Skip to content

Commit

Permalink
Rollup merge of #65652 - skinny121:const_infer_leak, r=eddyb
Browse files Browse the repository at this point in the history
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
  • Loading branch information
JohnTitor authored Oct 21, 2019
2 parents 865e46b + aa3d28f commit 1c94a44
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/librustc/infer/canonical/canonicalizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
)
}
Expand Down
14 changes: 14 additions & 0 deletions src/test/incremental/const-generics/issue-61338.rs
Original file line number Diff line number Diff line change
@@ -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();
}
16 changes: 16 additions & 0 deletions src/test/incremental/const-generics/issue-61516.rs
Original file line number Diff line number Diff line change
@@ -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);
}
12 changes: 12 additions & 0 deletions src/test/incremental/const-generics/issue-62536.rs
Original file line number Diff line number Diff line change
@@ -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
}
11 changes: 11 additions & 0 deletions src/test/incremental/const-generics/issue-64087.rs
Original file line number Diff line number Diff line change
@@ -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
}
14 changes: 14 additions & 0 deletions src/test/incremental/const-generics/issue-65623.rs
Original file line number Diff line number Diff line change
@@ -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();
}

0 comments on commit 1c94a44

Please sign in to comment.