1
Fork 0

Add test with multiple type params failing inference

This commit is contained in:
Esteban Kuber 2021-11-19 06:10:43 +00:00
parent 6a691b1d92
commit 7271d1f803
3 changed files with 46 additions and 15 deletions

View file

@ -939,9 +939,7 @@ impl<'tcx> ResolvedTypeParamEraser<'tcx> {
/// Replace not yet inferred const params with their def name. /// Replace not yet inferred const params with their def name.
fn replace_infers(&self, c: &'tcx Const<'tcx>, index: u32, name: Symbol) -> &'tcx Const<'tcx> { fn replace_infers(&self, c: &'tcx Const<'tcx>, index: u32, name: Symbol) -> &'tcx Const<'tcx> {
match c.val { match c.val {
ty::ConstKind::Infer(..) => { ty::ConstKind::Infer(..) => self.tcx().mk_const_param(index, name, c.ty),
self.tcx().mk_const_param(index, name, c.ty)
}
_ => c, _ => c,
} }
} }

View file

@ -1,5 +1,8 @@
fn main() { fn main() {
let foo = new(1, ""); //~ ERROR E0283 let foo = foo(1, ""); //~ ERROR E0283
}
fn baz() {
let bar = bar(1, ""); //~ ERROR E0283
} }
struct Bar<T, K, N: Default> { struct Bar<T, K, N: Default> {
@ -8,6 +11,17 @@ struct Bar<T, K, N: Default> {
n: N, n: N,
} }
fn new<T, K, Z: Default>(t: T, k: K) -> Bar<T, K, Z> { fn bar<T, K, Z: Default>(t: T, k: K) -> Bar<T, K, Z> {
Bar { t, k, n: Default::default() } Bar { t, k, n: Default::default() }
} }
struct Foo<T, K, N: Default, M: Default> {
t: T,
k: K,
n: N,
m: M,
}
fn foo<T, K, W: Default, Z: Default>(t: T, k: K) -> Foo<T, K, W, Z> {
Foo { t, k, n: Default::default(), m: Default::default() }
}

View file

@ -1,22 +1,41 @@
error[E0283]: type annotations needed for `Bar<i32, &str, Z>` error[E0283]: type annotations needed for `Foo<i32, &str, W, Z>`
--> $DIR/erase-type-params-in-label.rs:2:15 --> $DIR/erase-type-params-in-label.rs:2:15
| |
LL | let foo = new(1, ""); LL | let foo = foo(1, "");
| --- ^^^ cannot infer type for type parameter `Z` declared on the function `new` | --- ^^^ cannot infer type for type parameter `W` declared on the function `foo`
| | | |
| consider giving `foo` the explicit type `Bar<_, _, Z>`, where the type parameter `Z` is specified | consider giving `foo` the explicit type `Foo<_, _, W, Z>`, where the type parameter `W` is specified
| |
= note: cannot satisfy `_: Default` = note: cannot satisfy `_: Default`
note: required by a bound in `new` note: required by a bound in `foo`
--> $DIR/erase-type-params-in-label.rs:11:17 --> $DIR/erase-type-params-in-label.rs:25:17
| |
LL | fn new<T, K, Z: Default>(t: T, k: K) -> Bar<T, K, Z> { LL | fn foo<T, K, W: Default, Z: Default>(t: T, k: K) -> Foo<T, K, W, Z> {
| ^^^^^^^ required by this bound in `new` | ^^^^^^^ required by this bound in `foo`
help: consider specifying the type arguments in the function call help: consider specifying the type arguments in the function call
| |
LL | let foo = new::<T, K, Z>(1, ""); LL | let foo = foo::<T, K, W, Z>(1, "");
| ++++++++++++++
error[E0283]: type annotations needed for `Bar<i32, &str, Z>`
--> $DIR/erase-type-params-in-label.rs:5:15
|
LL | let bar = bar(1, "");
| --- ^^^ cannot infer type for type parameter `Z` declared on the function `bar`
| |
| consider giving `bar` the explicit type `Bar<_, _, Z>`, where the type parameter `Z` is specified
|
= note: cannot satisfy `_: Default`
note: required by a bound in `bar`
--> $DIR/erase-type-params-in-label.rs:14:17
|
LL | fn bar<T, K, Z: Default>(t: T, k: K) -> Bar<T, K, Z> {
| ^^^^^^^ required by this bound in `bar`
help: consider specifying the type arguments in the function call
|
LL | let bar = bar::<T, K, Z>(1, "");
| +++++++++++ | +++++++++++
error: aborting due to previous error error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0283`. For more information about this error, try `rustc --explain E0283`.