diff options
| author | Yuki Okushi <huyuumi.dev@gmail.com> | 2019-10-21 19:53:06 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-10-21 19:53:06 +0900 |
| commit | 1c94a4475bb3ef7e13eb59dc6fd0920051544b45 (patch) | |
| tree | 53f09c5f0253e3fde779a9bdd5e81c16e3028d13 /src | |
| parent | 865e46b4ba4669dcfe184e6fce0395a481b7f0ad (diff) | |
| parent | aa3d28f9a8e0fa2915e5321648d57af6c922799f (diff) | |
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
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc/infer/canonical/canonicalizer.rs | 2 | ||||
| -rw-r--r-- | src/test/incremental/const-generics/issue-61338.rs | 14 | ||||
| -rw-r--r-- | src/test/incremental/const-generics/issue-61516.rs | 16 | ||||
| -rw-r--r-- | src/test/incremental/const-generics/issue-62536.rs | 12 | ||||
| -rw-r--r-- | src/test/incremental/const-generics/issue-64087.rs | 11 | ||||
| -rw-r--r-- | src/test/incremental/const-generics/issue-65623.rs | 14 |
6 files changed, 68 insertions, 1 deletions
diff --git a/src/librustc/infer/canonical/canonicalizer.rs b/src/librustc/infer/canonical/canonicalizer.rs index b9474f869ee..e69719806a8 100644 --- a/src/librustc/infer/canonical/canonicalizer.rs +++ b/src/librustc/infer/canonical/canonicalizer.rs @@ -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), } ) } diff --git a/src/test/incremental/const-generics/issue-61338.rs b/src/test/incremental/const-generics/issue-61338.rs new file mode 100644 index 00000000000..00b3b29698b --- /dev/null +++ b/src/test/incremental/const-generics/issue-61338.rs @@ -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(); +} diff --git a/src/test/incremental/const-generics/issue-61516.rs b/src/test/incremental/const-generics/issue-61516.rs new file mode 100644 index 00000000000..a7465b77267 --- /dev/null +++ b/src/test/incremental/const-generics/issue-61516.rs @@ -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); +} diff --git a/src/test/incremental/const-generics/issue-62536.rs b/src/test/incremental/const-generics/issue-62536.rs new file mode 100644 index 00000000000..90e279bfc74 --- /dev/null +++ b/src/test/incremental/const-generics/issue-62536.rs @@ -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 +} diff --git a/src/test/incremental/const-generics/issue-64087.rs b/src/test/incremental/const-generics/issue-64087.rs new file mode 100644 index 00000000000..b3c12fbb6e8 --- /dev/null +++ b/src/test/incremental/const-generics/issue-64087.rs @@ -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 +} diff --git a/src/test/incremental/const-generics/issue-65623.rs b/src/test/incremental/const-generics/issue-65623.rs new file mode 100644 index 00000000000..353e323e67b --- /dev/null +++ b/src/test/incremental/const-generics/issue-65623.rs @@ -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(); +} |
