mirror of
https://github.com/rust-lang/rust
synced 2024-10-01 06:14:33 +00:00
Rollup merge of #110984 - cjgillot:const-infer-lifetime, r=compiler-errors
Do not resolve anonymous lifetimes in consts to be static. Fixes https://github.com/rust-lang/rust/issues/110931
This commit is contained in:
commit
a656a2019a
|
@ -656,7 +656,7 @@ fn visit_block(&mut self, block: &'ast Block) {
|
|||
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);
|
||||
})
|
||||
})
|
||||
|
@ -4126,7 +4126,7 @@ fn resolve_expr(&mut self, expr: &'ast Expr, parent: Option<&'ast Expr>) {
|
|||
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)
|
||||
})
|
||||
});
|
||||
|
|
20
tests/ui/lifetimes/elided-lifetime-in-anon-const.rs
Normal file
20
tests/ui/lifetimes/elided-lifetime-in-anon-const.rs
Normal file
|
@ -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() {}
|
Loading…
Reference in a new issue