1
Fork 0

Rollup merge of #65652 - skinny121:const_infer_leak, r=eddyb

Fix `canonicalize_const_var` leaking inference variables

Fixes #61338
Fixes #61516
Fixes #62536
Fixes #64087
Fixes #64863
Fixes #65623

I added regression tests for all these issues apart from #64863, which is very similar to #61338.

r? @varkor
This commit is contained in:
Yuki Okushi 2019-10-21 19:53:06 +09:00 committed by GitHub
commit 1c94a4475b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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( self.tcx().mk_const(
ty::Const { ty::Const {
val: ConstValue::Infer(InferConst::Canonical(self.binder_index, var.into())), 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();
}