Skip to content

Commit dabee5d

Browse files
committed
Do not treat lifetimes from parent items as influencing child items
1 parent 2a06022 commit dabee5d

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

compiler/rustc_resolve/src/late.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1833,14 +1833,17 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
18331833
}
18341834
LifetimeRibKind::StaticIfNoLifetimeInScope { lint_id: node_id, emit_lint } => {
18351835
let mut lifetimes_in_scope = vec![];
1836-
for rib in &self.lifetime_ribs[..i] {
1836+
for rib in self.lifetime_ribs[..i].iter().rev() {
18371837
lifetimes_in_scope.extend(rib.bindings.iter().map(|(ident, _)| ident.span));
18381838
// Consider any anonymous lifetimes, too
18391839
if let LifetimeRibKind::AnonymousCreateParameter { binder, .. } = rib.kind
18401840
&& let Some(extra) = self.r.extra_lifetime_params_map.get(&binder)
18411841
{
18421842
lifetimes_in_scope.extend(extra.iter().map(|(ident, _, _)| ident.span));
18431843
}
1844+
if let LifetimeRibKind::Item = rib.kind {
1845+
break;
1846+
}
18441847
}
18451848
if lifetimes_in_scope.is_empty() {
18461849
self.record_lifetime_res(

tests/ui/consts/static-default-lifetime/static-trait-impl.rs

+13
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,17 @@ impl Bar<'static> for B {
1717
const STATIC: &str = "";
1818
}
1919

20+
struct C;
21+
impl Bar<'_> for C {
22+
// make ^^ not cause
23+
const STATIC: &'static str = {
24+
struct B;
25+
impl Bar<'static> for B {
26+
const STATIC: &str = "";
27+
// ^ to emit a future incompat warning
28+
}
29+
""
30+
};
31+
}
32+
2033
fn main() {}

0 commit comments

Comments
 (0)