Skip to content

Commit 1c94a44

Browse files
authored
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
2 parents 865e46b + aa3d28f commit 1c94a44

File tree

6 files changed

+68
-1
lines changed

6 files changed

+68
-1
lines changed

src/librustc/infer/canonical/canonicalizer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
701701
self.tcx().mk_const(
702702
ty::Const {
703703
val: ConstValue::Infer(InferConst::Canonical(self.binder_index, var.into())),
704-
ty: const_var.ty,
704+
ty: self.fold_ty(const_var.ty),
705705
}
706706
)
707707
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// revisions:rpass1
2+
3+
#![feature(const_generics)]
4+
5+
struct Struct<T>(T);
6+
7+
impl<T, const N: usize> Struct<[T; N]> {
8+
fn f() {}
9+
fn g() { Self::f(); }
10+
}
11+
12+
fn main() {
13+
Struct::<[u32; 3]>::g();
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// revisions:rpass1
2+
3+
#![feature(const_generics)]
4+
5+
struct FakeArray<T, const N: usize>(T);
6+
7+
impl<T, const N: usize> FakeArray<T, { N }> {
8+
fn len(&self) -> usize {
9+
N
10+
}
11+
}
12+
13+
fn main() {
14+
let fa = FakeArray::<u32, { 32 }>(1);
15+
assert_eq!(fa.len(), 32);
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// revisions:cfail1
2+
#![feature(const_generics)]
3+
//[cfail1]~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
4+
5+
struct S<T, const N: usize>([T; N]);
6+
7+
fn f<T, const N: usize>(x: T) -> S<T, {N}> { panic!() }
8+
9+
fn main() {
10+
f(0u8);
11+
//[cfail1]~^ ERROR type annotations needed
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// revisions:cfail1
2+
#![feature(const_generics)]
3+
//[cfail1]~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
4+
5+
fn combinator<T, const S: usize>() -> [T; S] {}
6+
//[cfail1]~^ ERROR mismatched types
7+
8+
fn main() {
9+
combinator().into_iter();
10+
//[cfail1]~^ ERROR type annotations needed
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// revisions:rpass1
2+
#![feature(const_generics)]
3+
4+
pub struct Foo<T, const N: usize>([T; 0]);
5+
6+
impl<T, const N: usize> Foo<T, {N}> {
7+
pub fn new() -> Self {
8+
Foo([])
9+
}
10+
}
11+
12+
fn main() {
13+
let _: Foo<u32, 0> = Foo::new();
14+
}

0 commit comments

Comments
 (0)