Skip to content

Commit a656a20

Browse files
authored
Rollup merge of #110984 - cjgillot:const-infer-lifetime, r=compiler-errors
Do not resolve anonymous lifetimes in consts to be static. Fixes #110931
2 parents 549b3a1 + 63028ac commit a656a20

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

compiler/rustc_resolve/src/late.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
656656
fn visit_anon_const(&mut self, constant: &'ast AnonConst) {
657657
// We deal with repeat expressions explicitly in `resolve_expr`.
658658
self.with_lifetime_rib(LifetimeRibKind::AnonConst, |this| {
659-
this.with_lifetime_rib(LifetimeRibKind::Elided(LifetimeRes::Static), |this| {
659+
this.with_lifetime_rib(LifetimeRibKind::Elided(LifetimeRes::Infer), |this| {
660660
this.resolve_anon_const(constant, IsRepeatExpr::No);
661661
})
662662
})
@@ -4126,7 +4126,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
41264126
ExprKind::Repeat(ref elem, ref ct) => {
41274127
self.visit_expr(elem);
41284128
self.with_lifetime_rib(LifetimeRibKind::AnonConst, |this| {
4129-
this.with_lifetime_rib(LifetimeRibKind::Elided(LifetimeRes::Static), |this| {
4129+
this.with_lifetime_rib(LifetimeRibKind::Elided(LifetimeRes::Infer), |this| {
41304130
this.resolve_anon_const(ct, IsRepeatExpr::Yes)
41314131
})
41324132
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Verify that elided lifetimes inside anonymous constants are not forced to be `'static`.
2+
// check-pass
3+
4+
fn foo() -> [(); {
5+
let a = 10_usize;
6+
let b: &'_ usize = &a;
7+
*b
8+
}] {
9+
[(); 10]
10+
}
11+
12+
fn bar() -> [(); 10] {
13+
[(); {
14+
let a = 10_usize;
15+
let b: &'_ usize = &a;
16+
*b
17+
}]
18+
}
19+
20+
fn main() {}

0 commit comments

Comments
 (0)