Fix canonicalize_const_var from leaking inference variables through

it's type.
This commit is contained in:
ben 2019-10-21 14:42:54 +13:00
parent 7979016aff
commit aa3d28f9a8
6 changed files with 68 additions and 1 deletions

View file

@ -701,7 +701,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
self.tcx().mk_const(
ty::Const {
val: ConstValue::Infer(InferConst::Canonical(self.binder_index, var.into())),
ty: const_var.ty,
ty: self.fold_ty(const_var.ty),
}
)
}

View file

@ -0,0 +1,14 @@
// revisions:rpass1
#![feature(const_generics)]
struct Struct<T>(T);
impl<T, const N: usize> Struct<[T; N]> {
fn f() {}
fn g() { Self::f(); }
}
fn main() {
Struct::<[u32; 3]>::g();
}

View file

@ -0,0 +1,16 @@
// revisions:rpass1
#![feature(const_generics)]
struct FakeArray<T, const N: usize>(T);
impl<T, const N: usize> FakeArray<T, { N }> {
fn len(&self) -> usize {
N
}
}
fn main() {
let fa = FakeArray::<u32, { 32 }>(1);
assert_eq!(fa.len(), 32);
}

View file

@ -0,0 +1,12 @@
// revisions:cfail1
#![feature(const_generics)]
//[cfail1]~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
struct S<T, const N: usize>([T; N]);
fn f<T, const N: usize>(x: T) -> S<T, {N}> { panic!() }
fn main() {
f(0u8);
//[cfail1]~^ ERROR type annotations needed
}

View file

@ -0,0 +1,11 @@
// revisions:cfail1
#![feature(const_generics)]
//[cfail1]~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
fn combinator<T, const S: usize>() -> [T; S] {}
//[cfail1]~^ ERROR mismatched types
fn main() {
combinator().into_iter();
//[cfail1]~^ ERROR type annotations needed
}

View file

@ -0,0 +1,14 @@
// revisions:rpass1
#![feature(const_generics)]
pub struct Foo<T, const N: usize>([T; 0]);
impl<T, const N: usize> Foo<T, {N}> {
pub fn new() -> Self {
Foo([])
}
}
fn main() {
let _: Foo<u32, 0> = Foo::new();
}