Skip to content

Commit c2aa7fd

Browse files
Rollup merge of rust-lang#98499 - JulianKnodt:erase_lifetime, r=lcnr
Erase regions in New Abstract Consts When an abstract const is constructed, we previously included lifetimes in the set of substitutes, so it was not able to unify two abstract consts if their lifetimes did not match but the values did, despite the values not depending on the lifetimes. This caused code that should have compiled to not compile. Fixes rust-lang#98452 r? `@lcnr`
2 parents b79e0a8 + 1e40200 commit c2aa7fd

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

compiler/rustc_trait_selection/src/traits/const_evaluatable.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ impl<'tcx> AbstractConst<'tcx> {
236236
) -> Result<Option<AbstractConst<'tcx>>, ErrorGuaranteed> {
237237
let inner = tcx.thir_abstract_const_opt_const_arg(uv.def)?;
238238
debug!("AbstractConst::new({:?}) = {:?}", uv, inner);
239-
Ok(inner.map(|inner| AbstractConst { inner, substs: uv.substs }))
239+
Ok(inner.map(|inner| AbstractConst { inner, substs: tcx.erase_regions(uv.substs) }))
240240
}
241241

242242
pub fn from_const(
@@ -416,6 +416,7 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
416416
// `AbstractConst`s should not contain any promoteds as they require references which
417417
// are not allowed.
418418
assert_eq!(ct.promoted, None);
419+
assert_eq!(ct, self.tcx.erase_regions(ct));
419420
}
420421
}
421422
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// check-pass
2+
#![feature(generic_const_exprs)]
3+
#![allow(incomplete_features)]
4+
5+
struct Num<const N: usize>;
6+
7+
trait NumT {
8+
const VALUE: usize;
9+
}
10+
11+
impl<const N: usize> NumT for Num<N> {
12+
const VALUE: usize = N;
13+
}
14+
15+
struct Foo<'a, N: NumT>(&'a [u32; N::VALUE]) where [(); N::VALUE]:;
16+
17+
trait Bar {
18+
type Size: NumT;
19+
20+
fn bar<'a>(foo: &Foo<'a, Self::Size>) where [(); Self::Size::VALUE]: {
21+
todo!();
22+
}
23+
}
24+
25+
trait Baz<'a> {
26+
type Size: NumT;
27+
28+
fn baz(foo: &Foo<'a, Self::Size>) where [(); Self::Size::VALUE]: {
29+
todo!();
30+
}
31+
}
32+
33+
fn main() {}

0 commit comments

Comments
 (0)