Skip to content

Commit

Permalink
Rollup merge of rust-lang#98499 - JulianKnodt:erase_lifetime, r=lcnr
Browse files Browse the repository at this point in the history
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``
  • Loading branch information
Dylan-DPC authored Jun 29, 2022
2 parents 32d74fb + 1e40200 commit 1445b53
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ impl<'tcx> AbstractConst<'tcx> {
) -> Result<Option<AbstractConst<'tcx>>, ErrorGuaranteed> {
let inner = tcx.thir_abstract_const_opt_const_arg(uv.def)?;
debug!("AbstractConst::new({:?}) = {:?}", uv, inner);
Ok(inner.map(|inner| AbstractConst { inner, substs: uv.substs }))
Ok(inner.map(|inner| AbstractConst { inner, substs: tcx.erase_regions(uv.substs) }))
}

pub fn from_const(
Expand Down Expand Up @@ -416,6 +416,7 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
// `AbstractConst`s should not contain any promoteds as they require references which
// are not allowed.
assert_eq!(ct.promoted, None);
assert_eq!(ct, self.tcx.erase_regions(ct));
}
}
}
Expand Down
33 changes: 33 additions & 0 deletions src/test/ui/const-generics/try_unify_ignore_lifetimes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// check-pass
#![feature(generic_const_exprs)]
#![allow(incomplete_features)]

struct Num<const N: usize>;

trait NumT {
const VALUE: usize;
}

impl<const N: usize> NumT for Num<N> {
const VALUE: usize = N;
}

struct Foo<'a, N: NumT>(&'a [u32; N::VALUE]) where [(); N::VALUE]:;

trait Bar {
type Size: NumT;

fn bar<'a>(foo: &Foo<'a, Self::Size>) where [(); Self::Size::VALUE]: {
todo!();
}
}

trait Baz<'a> {
type Size: NumT;

fn baz(foo: &Foo<'a, Self::Size>) where [(); Self::Size::VALUE]: {
todo!();
}
}

fn main() {}

0 comments on commit 1445b53

Please sign in to comment.