Skip to content

Commit 37db365

Browse files
committed
Also treat impl definition parent as transparent regarding modules
1 parent a0d98ff commit 37db365

File tree

2 files changed

+72
-2
lines changed

2 files changed

+72
-2
lines changed

compiler/rustc_lint/src/non_local_def.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,15 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions {
151151
// };
152152
// };
153153
// ```
154+
//
155+
// It isn't possible to mix a impl in a module with const-anon, but an item can
156+
// be put inside a module and referenced by a impl so we also have to treat the
157+
// item parent as transparent to module and for consistency we have to do the same
158+
// for impl, otherwise the item-def and impl-def won't have the same parent.
154159
let outermost_impl_parent = peel_parent_while(cx.tcx, parent, |tcx, did| {
155-
tcx.def_kind(did) == DefKind::Const
156-
&& tcx.opt_item_name(did) == Some(kw::Underscore)
160+
tcx.def_kind(did) == DefKind::Mod
161+
|| (tcx.def_kind(did) == DefKind::Const
162+
&& tcx.opt_item_name(did) == Some(kw::Underscore))
157163
});
158164

159165
// 2. We check if any of the paths reference a the `impl`-parent.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Regression tests for https://github.com/rust-lang/rust/issues/132427
2+
3+
//@ check-pass
4+
5+
// original
6+
mod auth {
7+
const _: () = {
8+
pub enum ArbitraryContext {}
9+
10+
const _: () = {
11+
impl ArbitraryContext {}
12+
};
13+
};
14+
}
15+
16+
mod z {
17+
pub enum ArbitraryContext {}
18+
19+
const _: () = {
20+
const _: () = {
21+
impl ArbitraryContext {}
22+
};
23+
};
24+
}
25+
26+
const _: () = {
27+
mod auth {
28+
const _: () = {
29+
pub enum ArbitraryContext {}
30+
31+
const _: () = {
32+
impl ArbitraryContext {}
33+
};
34+
};
35+
}
36+
};
37+
38+
mod a {
39+
mod b {
40+
const _: () = {
41+
pub enum ArbitraryContext {}
42+
43+
const _: () = {
44+
impl ArbitraryContext {}
45+
};
46+
};
47+
}
48+
}
49+
50+
mod foo {
51+
const _: () = {
52+
mod auth {
53+
const _: () = {
54+
pub enum ArbitraryContext {}
55+
56+
const _: () = {
57+
impl ArbitraryContext {}
58+
};
59+
};
60+
}
61+
};
62+
}
63+
64+
fn main() {}

0 commit comments

Comments
 (0)