Skip to content

Do not treat lifetimes from parent items as influencing child items #139075

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

Merged
merged 1 commit into from
Mar 29, 2025
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
5 changes: 4 additions & 1 deletion compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1833,14 +1833,17 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
}
LifetimeRibKind::StaticIfNoLifetimeInScope { lint_id: node_id, emit_lint } => {
let mut lifetimes_in_scope = vec![];
for rib in &self.lifetime_ribs[..i] {
for rib in self.lifetime_ribs[..i].iter().rev() {
lifetimes_in_scope.extend(rib.bindings.iter().map(|(ident, _)| ident.span));
// Consider any anonymous lifetimes, too
if let LifetimeRibKind::AnonymousCreateParameter { binder, .. } = rib.kind
&& let Some(extra) = self.r.extra_lifetime_params_map.get(&binder)
{
lifetimes_in_scope.extend(extra.iter().map(|(ident, _, _)| ident.span));
}
if let LifetimeRibKind::Item = rib.kind {
break;
}
}
if lifetimes_in_scope.is_empty() {
self.record_lifetime_res(
Expand Down
13 changes: 13 additions & 0 deletions tests/ui/consts/static-default-lifetime/static-trait-impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,17 @@ impl Bar<'static> for B {
const STATIC: &str = "";
}

struct C;
impl Bar<'_> for C {
// make ^^ not cause
const STATIC: &'static str = {
struct B;
impl Bar<'static> for B {
const STATIC: &str = "";
// ^ to emit a future incompat warning
}
""
};
}

fn main() {}
Loading