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

Also treat impl definition parent as transparent regarding modules #132453

Merged
merged 1 commit into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions compiler/rustc_lint/src/non_local_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,15 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions {
// };
// };
// ```
//
// It isn't possible to mix a impl in a module with const-anon, but an item can
// be put inside a module and referenced by a impl so we also have to treat the
// item parent as transparent to module and for consistency we have to do the same
// for impl, otherwise the item-def and impl-def won't have the same parent.
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)
tcx.def_kind(did) == DefKind::Mod
|| (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.
Expand Down
64 changes: 64 additions & 0 deletions tests/ui/lint/non-local-defs/convoluted-locals-132427.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Regression tests for https://github.com/rust-lang/rust/issues/132427

//@ check-pass

// original
mod auth {
const _: () = {
pub enum ArbitraryContext {}

const _: () = {
impl ArbitraryContext {}
};
};
}

mod z {
pub enum ArbitraryContext {}

const _: () = {
const _: () = {
impl ArbitraryContext {}
};
};
}

const _: () = {
mod auth {
const _: () = {
pub enum ArbitraryContext {}

const _: () = {
impl ArbitraryContext {}
};
};
}
};

mod a {
mod b {
const _: () = {
pub enum ArbitraryContext {}

const _: () = {
impl ArbitraryContext {}
};
};
}
}

mod foo {
const _: () = {
mod auth {
const _: () = {
pub enum ArbitraryContext {}

const _: () = {
impl ArbitraryContext {}
};
};
}
};
}

fn main() {}
Loading