about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorUrgau <urgau@numericable.fr>2024-11-01 12:44:55 +0100
committerUrgau <urgau@numericable.fr>2024-11-01 16:07:02 +0100
commit37db36594838d85f72e2282e73707071e80e31c0 (patch)
treee3ad60954e942fadf22438485ffe8d83f038921c /compiler
parenta0d98ff0e5b6e1f2c63fd26f68484792621b235c (diff)
downloadrust-37db36594838d85f72e2282e73707071e80e31c0.tar.gz
rust-37db36594838d85f72e2282e73707071e80e31c0.zip
Also treat `impl` definition parent as transparent regarding modules
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_lint/src/non_local_def.rs10
1 files changed, 8 insertions, 2 deletions
diff --git a/compiler/rustc_lint/src/non_local_def.rs b/compiler/rustc_lint/src/non_local_def.rs
index 3c31b879bd6..3c33b2dd478 100644
--- a/compiler/rustc_lint/src/non_local_def.rs
+++ b/compiler/rustc_lint/src/non_local_def.rs
@@ -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.