Skip to content
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: 7 additions & 3 deletions compiler/rustc_lint/src/non_local_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions tests/ui/lint/non-local-defs/convoluted-locals-131474-with-mods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
9 changes: 9 additions & 0 deletions tests/ui/lint/non-local-defs/convoluted-locals-131474.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,13 @@ const _: () = {
};
};

// https://github.com/rust-lang/rust/issues/131643
const _: () = {
const _: () = {
impl InnerTest {}
};

struct InnerTest;
};

fn main() {}
Loading