Skip to content

Commit

Permalink
Rollup merge of #110984 - cjgillot:const-infer-lifetime, r=compiler-e…
Browse files Browse the repository at this point in the history
…rrors

Do not resolve anonymous lifetimes in consts to be static.

Fixes #110931
  • Loading branch information
matthiaskrgr authored Apr 29, 2023
2 parents 549b3a1 + 63028ac commit a656a20
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
fn visit_anon_const(&mut self, constant: &'ast AnonConst) {
// We deal with repeat expressions explicitly in `resolve_expr`.
self.with_lifetime_rib(LifetimeRibKind::AnonConst, |this| {
this.with_lifetime_rib(LifetimeRibKind::Elided(LifetimeRes::Static), |this| {
this.with_lifetime_rib(LifetimeRibKind::Elided(LifetimeRes::Infer), |this| {
this.resolve_anon_const(constant, IsRepeatExpr::No);
})
})
Expand Down Expand Up @@ -4126,7 +4126,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
ExprKind::Repeat(ref elem, ref ct) => {
self.visit_expr(elem);
self.with_lifetime_rib(LifetimeRibKind::AnonConst, |this| {
this.with_lifetime_rib(LifetimeRibKind::Elided(LifetimeRes::Static), |this| {
this.with_lifetime_rib(LifetimeRibKind::Elided(LifetimeRes::Infer), |this| {
this.resolve_anon_const(ct, IsRepeatExpr::Yes)
})
});
Expand Down
20 changes: 20 additions & 0 deletions tests/ui/lifetimes/elided-lifetime-in-anon-const.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Verify that elided lifetimes inside anonymous constants are not forced to be `'static`.
// check-pass

fn foo() -> [(); {
let a = 10_usize;
let b: &'_ usize = &a;
*b
}] {
[(); 10]
}

fn bar() -> [(); 10] {
[(); {
let a = 10_usize;
let b: &'_ usize = &a;
*b
}]
}

fn main() {}

0 comments on commit a656a20

Please sign in to comment.