diff options
| author | Urgau <urgau@numericable.fr> | 2024-10-13 18:13:30 +0200 |
|---|---|---|
| committer | Josh Stone <jistone@redhat.com> | 2024-10-17 10:30:16 -0700 |
| commit | d04ae764ccdd8a2883991f2c60df4cbe75bc1e3f (patch) | |
| tree | f167a82a06f3958db542ea50de8c72b0309086fd | |
| parent | 601863bf305f4db04c0a6b9ae7434a84d2fd8903 (diff) | |
| download | rust-d04ae764ccdd8a2883991f2c60df4cbe75bc1e3f.tar.gz rust-d04ae764ccdd8a2883991f2c60df4cbe75bc1e3f.zip | |
Also use outermost const-anon for impl items in `non_local_defs` lint
(cherry picked from commit b5e91a00c89a065f618693873ad7074a13ad6b90)
| -rw-r--r-- | compiler/rustc_lint/src/non_local_def.rs | 10 | ||||
| -rw-r--r-- | tests/ui/lint/non-local-defs/convoluted-locals-131474-with-mods.rs | 11 | ||||
| -rw-r--r-- | tests/ui/lint/non-local-defs/convoluted-locals-131474.rs | 9 |
3 files changed, 27 insertions, 3 deletions
diff --git a/compiler/rustc_lint/src/non_local_def.rs b/compiler/rustc_lint/src/non_local_def.rs index 6fecddb3319..3c31b879bd6 100644 --- a/compiler/rustc_lint/src/non_local_def.rs +++ b/compiler/rustc_lint/src/non_local_def.rs @@ -301,9 +301,13 @@ fn did_has_local_parent( 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) + peel_parent_while(tcx, parent_did, |tcx, did| { + tcx.def_kind(did) == DefKind::Mod + || (tcx.def_kind(did) == DefKind::Const + && tcx.opt_item_name(did) == Some(kw::Underscore)) + }) + .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 diff --git a/tests/ui/lint/non-local-defs/convoluted-locals-131474-with-mods.rs b/tests/ui/lint/non-local-defs/convoluted-locals-131474-with-mods.rs index cef0f0205e8..72fd056d461 100644 --- a/tests/ui/lint/non-local-defs/convoluted-locals-131474-with-mods.rs +++ b/tests/ui/lint/non-local-defs/convoluted-locals-131474-with-mods.rs @@ -31,4 +31,15 @@ const _: () = { }; }; +// https://github.com/rust-lang/rust/issues/131643 +const _: () = { + const _: () = { + impl tmp::InnerTest {} + }; + + mod tmp { + pub(super) struct InnerTest; + } +}; + fn main() {} diff --git a/tests/ui/lint/non-local-defs/convoluted-locals-131474.rs b/tests/ui/lint/non-local-defs/convoluted-locals-131474.rs index 4881723f13b..8e738544a71 100644 --- a/tests/ui/lint/non-local-defs/convoluted-locals-131474.rs +++ b/tests/ui/lint/non-local-defs/convoluted-locals-131474.rs @@ -21,4 +21,13 @@ const _: () = { }; }; +// https://github.com/rust-lang/rust/issues/131643 +const _: () = { + const _: () = { + impl InnerTest {} + }; + + struct InnerTest; +}; + fn main() {} |
