diff options
| author | Oli Scherer <github333195615777966@oli-obk.de> | 2025-03-28 17:01:23 +0000 |
|---|---|---|
| committer | Oli Scherer <github333195615777966@oli-obk.de> | 2025-03-28 17:06:00 +0000 |
| commit | dabee5d5635fd9f5093031df19cacf805292528c (patch) | |
| tree | 468bce31b54fc4bf089799f02c08442d54618da3 | |
| parent | 2a06022951893fe5b5384f8dbd75b4e6e3b5cee0 (diff) | |
| download | rust-dabee5d5635fd9f5093031df19cacf805292528c.tar.gz rust-dabee5d5635fd9f5093031df19cacf805292528c.zip | |
Do not treat lifetimes from parent items as influencing child items
| -rw-r--r-- | compiler/rustc_resolve/src/late.rs | 5 | ||||
| -rw-r--r-- | tests/ui/consts/static-default-lifetime/static-trait-impl.rs | 13 |
2 files changed, 17 insertions, 1 deletions
diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 533e216ddb2..0d23ae501f0 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -1833,7 +1833,7 @@ 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 @@ -1841,6 +1841,9 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { { 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( diff --git a/tests/ui/consts/static-default-lifetime/static-trait-impl.rs b/tests/ui/consts/static-default-lifetime/static-trait-impl.rs index b50bf01453d..1e12259e483 100644 --- a/tests/ui/consts/static-default-lifetime/static-trait-impl.rs +++ b/tests/ui/consts/static-default-lifetime/static-trait-impl.rs @@ -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() {} |
