Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 5 pull requests #131539

Closed
wants to merge 10 commits into from
48 changes: 24 additions & 24 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5804,16 +5804,16 @@ checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484"

[[package]]
name = "wasm-component-ld"
version = "0.5.9"
version = "0.5.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fde17bc96539700198e12516230c76095cc215c84ef39ad206e1af3f84243e0f"
checksum = "4d4aa6bd7fbe7cffbed29fe3e236fda74419def1bdef6f80f989ec51137edf44"
dependencies = [
"anyhow",
"clap",
"lexopt",
"tempfile",
"wasi-preview1-component-adapter-provider",
"wasmparser 0.218.0",
"wasmparser 0.219.0",
"wat",
"wit-component",
"wit-parser",
Expand All @@ -5837,28 +5837,28 @@ dependencies = [

[[package]]
name = "wasm-encoder"
version = "0.218.0"
version = "0.219.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22b896fa8ceb71091ace9bcb81e853f54043183a1c9667cf93422c40252ffa0a"
checksum = "e2b1b95711b3ad655656a341e301cc64e33cbee94de9a99a1c5a2ab88efab79d"
dependencies = [
"leb128",
"wasmparser 0.218.0",
"wasmparser 0.219.0",
]

[[package]]
name = "wasm-metadata"
version = "0.218.0"
version = "0.219.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa5eeb071abe8a2132fdd5565dabffee70775ee8c24fc7e300ac43f51f4a8a91"
checksum = "96132fe00dd17d092d2be289eeed5a0a68ad3cf30b68e8875bc953b96f55f0be"
dependencies = [
"anyhow",
"indexmap",
"serde",
"serde_derive",
"serde_json",
"spdx",
"wasm-encoder 0.218.0",
"wasmparser 0.218.0",
"wasm-encoder 0.219.0",
"wasmparser 0.219.0",
]

[[package]]
Expand All @@ -5873,9 +5873,9 @@ dependencies = [

[[package]]
name = "wasmparser"
version = "0.218.0"
version = "0.219.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b09e46c7fceceaa72b2dd1a8a137ea7fd8f93dfaa69806010a709918e496c5dc"
checksum = "324b4e56d24439495b88cd81439dad5e97f3c7b1eedc3c7e10455ed1e045e9a2"
dependencies = [
"ahash",
"bitflags 2.6.0",
Expand All @@ -5887,22 +5887,22 @@ dependencies = [

[[package]]
name = "wast"
version = "218.0.0"
version = "219.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a53cd1f0fa505df97557e36a58bddb8296e2fcdcd089529545ebfdb18a1b9d7"
checksum = "06880ecb25662bc21db6a83f4fcc27c41f71fbcba4f1980b650c88ada92728e1"
dependencies = [
"bumpalo",
"leb128",
"memchr",
"unicode-width",
"wasm-encoder 0.218.0",
"wasm-encoder 0.219.0",
]

[[package]]
name = "wat"
version = "1.218.0"
version = "1.219.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4f87f8e14e776762e07927c27c2054d2cf678aab9aae2d431a79b3e31e4dd391"
checksum = "11e56dbf9fc89111b0d97c91e683d7895b1a6e5633a729f2ccad2303724005b6"
dependencies = [
"wast",
]
Expand Down Expand Up @@ -6179,9 +6179,9 @@ dependencies = [

[[package]]
name = "wit-component"
version = "0.218.0"
version = "0.219.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa53aa7e6bf2b3e8ccaffbcc963fbdb672a603dc0af393a481b6cec24c266406"
checksum = "99a76111c20444a814019de20499d30940ecd219b9512ee296f034a5edb18a2d"
dependencies = [
"anyhow",
"bitflags 2.6.0",
Expand All @@ -6190,17 +6190,17 @@ dependencies = [
"serde",
"serde_derive",
"serde_json",
"wasm-encoder 0.218.0",
"wasm-encoder 0.219.0",
"wasm-metadata",
"wasmparser 0.218.0",
"wasmparser 0.219.0",
"wit-parser",
]

[[package]]
name = "wit-parser"
version = "0.218.0"
version = "0.219.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d3d1066ab761b115f97fef2b191090faabcb0f37b555b758d3caf42d4ed9e55"
checksum = "23102e180c0c464f36e293d31a27b524e3ece930d7b5527d2f33f9d2c963de64"
dependencies = [
"anyhow",
"id-arena",
Expand All @@ -6211,7 +6211,7 @@ dependencies = [
"serde_derive",
"serde_json",
"unicode-xid",
"wasmparser 0.218.0",
"wasmparser 0.219.0",
]

[[package]]
Expand Down
90 changes: 59 additions & 31 deletions compiler/rustc_lint/src/non_local_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,6 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions {
// If that's the case this means that this impl block declaration
// is using local items and so we don't lint on it.

// We also ignore anon-const in item by including the anon-const
// parent as well.
let parent_parent = if parent_def_kind == DefKind::Const
&& parent_opt_item_name == Some(kw::Underscore)
{
Some(cx.tcx.parent(parent))
} else {
None
};

// 1. We collect all the `hir::Path` from the `Self` type and `Trait` ref
// of the `impl` definition
let mut collector = PathCollector { paths: Vec::new() };
Expand All @@ -148,13 +138,33 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions {
|p| matches!(p.res, Res::Def(def_kind, _) if def_kind != DefKind::TyParam),
);

// 2. We check if any of path reference a "local" parent and if that the case
// we bail out as asked by T-lang, even though this isn't correct from a
// type-system point of view, as inference exists and could still leak the impl.
// 1.9. We retrieve the parent def id of the impl item, ...
//
// ... modulo const-anons items, for enhanced compatibility with the ecosystem
// as that pattern is common with `serde`, `bevy`, ...
//
// For this example we want the `DefId` parent of the outermost const-anon items.
// ```
// const _: () = { // the parent of this const-anon
// const _: () = {
// impl Foo {}
// };
// };
// ```
let outermost_impl_parent = peel_parent_while(cx.tcx, parent, |tcx, did| {
tcx.def_kind(did) == DefKind::Const
&& tcx.opt_item_name(did) == Some(kw::Underscore)
});

// 2. We check if any of the paths reference a the `impl`-parent.
//
// If that the case we bail out, as was asked by T-lang, even though this isn't
// correct from a type-system point of view, as inference exists and one-impl-rule
// make its so that we could still leak the impl.
if collector
.paths
.iter()
.any(|path| path_has_local_parent(path, cx, parent, parent_parent))
.any(|path| path_has_local_parent(path, cx, parent, outermost_impl_parent))
{
return;
}
Expand Down Expand Up @@ -253,8 +263,8 @@ impl<'tcx> Visitor<'tcx> for PathCollector<'tcx> {
}
}

/// Given a path and a parent impl def id, this checks if the if parent resolution
/// def id correspond to the def id of the parent impl definition.
/// Given a path, this checks if the if the parent resolution def id corresponds to
/// the def id of the parent impl definition (the direct one and the outermost one).
///
/// Given this path, we will look at the path (and ignore any generic args):
///
Expand All @@ -267,32 +277,50 @@ fn path_has_local_parent(
path: &Path<'_>,
cx: &LateContext<'_>,
impl_parent: DefId,
impl_parent_parent: Option<DefId>,
outermost_impl_parent: Option<DefId>,
) -> bool {
path.res
.opt_def_id()
.is_some_and(|did| did_has_local_parent(did, cx.tcx, impl_parent, impl_parent_parent))
.is_some_and(|did| did_has_local_parent(did, cx.tcx, impl_parent, outermost_impl_parent))
}

/// Given a def id and a parent impl def id, this checks if the parent
/// def id (modulo modules) correspond to the def id of the parent impl definition.
/// Given a def id this checks if the parent def id (modulo modules) correspond to
/// the def id of the parent impl definition (the direct one and the outermost one).
#[inline]
fn did_has_local_parent(
did: DefId,
tcx: TyCtxt<'_>,
impl_parent: DefId,
impl_parent_parent: Option<DefId>,
outermost_impl_parent: Option<DefId>,
) -> bool {
did.is_local()
&& if let Some(did_parent) = tcx.opt_parent(did) {
did_parent == impl_parent
|| Some(did_parent) == impl_parent_parent
|| !did_parent.is_crate_root()
&& tcx.def_kind(did_parent) == DefKind::Mod
&& did_has_local_parent(did_parent, tcx, impl_parent, impl_parent_parent)
} else {
false
}
if !did.is_local() {
return false;
}

let Some(parent_did) = tcx.opt_parent(did) else {
return false;
};

peel_parent_while(tcx, parent_did, |tcx, did| tcx.def_kind(did) == DefKind::Mod)
.map(|parent_did| parent_did == impl_parent || Some(parent_did) == outermost_impl_parent)
.unwrap_or(false)
}

/// Given a `DefId` checks if it satisfies `f` if it does check with it's parent and continue
/// until it doesn't satisfies `f` and return the last `DefId` checked.
///
/// In other word this method return the first `DefId` that doesn't satisfies `f`.
#[inline]
fn peel_parent_while(
tcx: TyCtxt<'_>,
mut did: DefId,
mut f: impl FnMut(TyCtxt<'_>, DefId) -> bool,
) -> Option<DefId> {
while !did.is_crate_root() && f(tcx, did) {
did = tcx.opt_parent(did).filter(|parent_did| parent_did.is_local())?;
}

Some(did)
}

/// Return for a given `Path` the span until the last args
Expand Down
3 changes: 2 additions & 1 deletion library/core/src/alloc/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,8 @@ impl Layout {
)]
pub type LayoutErr = LayoutError;

/// The parameters given to `Layout::from_size_align`
/// The `LayoutError` is returned when the parameters given
/// to `Layout::from_size_align`
/// or some other `Layout` constructor
/// do not satisfy its documented constraints.
#[stable(feature = "alloc_layout_error", since = "1.50.0")]
Expand Down
12 changes: 0 additions & 12 deletions src/ci/docker/host-x86_64/mingw-check/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,6 @@ ENV RUN_CHECK_WITH_PARALLEL_QUERIES 1
# We disable optimized compiler built-ins because that requires a C toolchain for the target.
# We also skip the x86_64-unknown-linux-gnu target as it is well-tested by other jobs.
ENV SCRIPT \
# `core::builder::tests::ci_rustc_if_unchanged_logic` bootstrap test covers the `rust.download-rustc=if-unchanged` logic.
# Here we are adding a dummy commit on compiler and running that test to ensure when there is a change on the compiler,
# we never download ci rustc with `rust.download-rustc=if-unchanged` option.
echo \"\" >> ../compiler/rustc/src/main.rs && \
git config --global user.email \"[email protected]\" && \
git config --global user.name \"dummy\" && \
git add ../compiler/rustc/src/main.rs && \
git commit -m \"test commit for rust.download-rustc=if-unchanged logic\" && \
DISABLE_CI_RUSTC_IF_INCOMPATIBLE=0 python3 ../x.py test bootstrap -- core::builder::tests::ci_rustc_if_unchanged_logic && \
# Revert the dummy commit
git reset --hard HEAD~1 && \

python3 ../x.py check --stage 0 --set build.optimized-compiler-builtins=false core alloc std --target=aarch64-unknown-linux-gnu,i686-pc-windows-msvc,i686-unknown-linux-gnu,x86_64-apple-darwin,x86_64-pc-windows-gnu,x86_64-pc-windows-msvc && \
/scripts/check-default-config-profiles.sh && \
python3 ../x.py check --target=i686-pc-windows-gnu --host=i686-pc-windows-gnu && \
Expand Down
14 changes: 14 additions & 0 deletions src/ci/docker/scripts/x86_64-gnu-llvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

set -ex

# `core::builder::tests::ci_rustc_if_unchanged_logic` bootstrap test ensures that
# "download-rustc=if-unchanged" logic don't use CI rustc while there are changes on
# compiler and/or library. Here we are adding a dummy commit on compiler and running
# that test to make sure we never download CI rustc with a change on the compiler tree.
echo "" >> ../compiler/rustc/src/main.rs
git config --global user.email "[email protected]"
git config --global user.name "dummy"
git add ../compiler/rustc/src/main.rs
git commit -m "test commit for rust.download-rustc=if-unchanged logic"
DISABLE_CI_RUSTC_IF_INCOMPATIBLE=0 ../x.py test bootstrap \
-- core::builder::tests::ci_rustc_if_unchanged_logic
# Revert the dummy commit
git reset --hard HEAD~1

# Only run the stage 1 tests on merges, not on PR CI jobs.
if [[ -z "${PR_CI_JOB}" ]]; then
../x.py --stage 1 test --skip src/tools/tidy
Expand Down
8 changes: 3 additions & 5 deletions src/ci/github-actions/jobs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,15 @@ envs:
# it in each job definition.
pr:
- image: mingw-check
env:
# We are adding (temporarily) a dummy commit on the compiler
READ_ONLY_SRC: "0"
<<: *job-linux-4c
- image: mingw-check-tidy
continue_on_error: true
<<: *job-linux-4c
- image: x86_64-gnu-llvm-18
env:
ENABLE_GCC_CODEGEN: "1"
# We are adding (temporarily) a dummy commit on the compiler
READ_ONLY_SRC: "0"
<<: *job-linux-16c
- image: x86_64-gnu-tools
<<: *job-linux-16c
Expand Down Expand Up @@ -210,8 +209,6 @@ auto:
<<: *job-linux-8c

- image: mingw-check
env:
READ_ONLY_SRC: 0
<<: *job-linux-4c

- image: test-various
Expand Down Expand Up @@ -264,6 +261,7 @@ auto:
- image: x86_64-gnu-llvm-18
env:
RUST_BACKTRACE: 1
READ_ONLY_SRC: "0"
<<: *job-linux-8c

- image: x86_64-gnu-nopt
Expand Down
2 changes: 1 addition & 1 deletion src/rustdoc-json-types/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ pub struct FunctionHeader {
/// on unwinding for more info.
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum Abi {
// We only have a concrete listing here for stable ABI's because their are so many
// We only have a concrete listing here for stable ABI's because there are so many
// See rustc_ast_passes::feature_gate::PostExpansionVisitor::check_abi for the list
/// The default ABI, but that can also be written explicitly with `extern "Rust"`.
Rust,
Expand Down
2 changes: 1 addition & 1 deletion src/tools/wasm-component-ld/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ name = "wasm-component-ld"
path = "src/main.rs"

[dependencies]
wasm-component-ld = "0.5.9"
wasm-component-ld = "0.5.10"
7 changes: 7 additions & 0 deletions tests/ui/lint/non-local-defs/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ fn main() {

1
};

const _: () = {
const _: () = {
impl Test {}
//~^ WARN non-local `impl` definition
};
};
}

trait Uto9 {}
Expand Down
Loading
Loading