Skip to content

Commit 63028ac

Browse files
committed
Do not force anonymous lifetimes in consts to be static.
1 parent 6ce2273 commit 63028ac

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
})
@@ -4130,7 +4130,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
41304130
ExprKind::Repeat(ref elem, ref ct) => {
41314131
self.visit_expr(elem);
41324132
self.with_lifetime_rib(LifetimeRibKind::AnonConst, |this| {
4133-
this.with_lifetime_rib(LifetimeRibKind::Elided(LifetimeRes::Static), |this| {
4133+
this.with_lifetime_rib(LifetimeRibKind::Elided(LifetimeRes::Infer), |this| {
41344134
this.resolve_anon_const(ct, IsRepeatExpr::Yes)
41354135
})
41364136
});
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)