Skip to content

Commit 00f15c5

Browse files
committed
Add test with multiple type params failing inference
1 parent b97e078 commit 00f15c5

File tree

3 files changed

+46
-15
lines changed

3 files changed

+46
-15
lines changed

compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -900,9 +900,7 @@ impl<'tcx> ResolvedTypeParamEraser<'tcx> {
900900
/// Replace not yet inferred const params with their def name.
901901
fn replace_infers(&self, c: &'tcx Const<'tcx>, index: u32, name: Symbol) -> &'tcx Const<'tcx> {
902902
match c.val {
903-
ty::ConstKind::Infer(..) => {
904-
self.tcx().mk_const_param(index, name, c.ty)
905-
}
903+
ty::ConstKind::Infer(..) => self.tcx().mk_const_param(index, name, c.ty),
906904
_ => c,
907905
}
908906
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
fn main() {
2-
let foo = new(1, ""); //~ ERROR E0283
2+
let foo = foo(1, ""); //~ ERROR E0283
3+
}
4+
fn baz() {
5+
let bar = bar(1, ""); //~ ERROR E0283
36
}
47

58
struct Bar<T, K, N: Default> {
@@ -8,6 +11,17 @@ struct Bar<T, K, N: Default> {
811
n: N,
912
}
1013

11-
fn new<T, K, Z: Default>(t: T, k: K) -> Bar<T, K, Z> {
14+
fn bar<T, K, Z: Default>(t: T, k: K) -> Bar<T, K, Z> {
1215
Bar { t, k, n: Default::default() }
1316
}
17+
18+
struct Foo<T, K, N: Default, M: Default> {
19+
t: T,
20+
k: K,
21+
n: N,
22+
m: M,
23+
}
24+
25+
fn foo<T, K, W: Default, Z: Default>(t: T, k: K) -> Foo<T, K, W, Z> {
26+
Foo { t, k, n: Default::default(), m: Default::default() }
27+
}
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,41 @@
1-
error[E0283]: type annotations needed for `Bar<i32, &str, Z>`
1+
error[E0283]: type annotations needed for `Foo<i32, &str, W, Z>`
22
--> $DIR/erase-type-params-in-label.rs:2:15
33
|
4-
LL | let foo = new(1, "");
5-
| --- ^^^ cannot infer type for type parameter `Z` declared on the function `new`
4+
LL | let foo = foo(1, "");
5+
| --- ^^^ cannot infer type for type parameter `W` declared on the function `foo`
6+
| |
7+
| consider giving `foo` the explicit type `Foo<_, _, W, Z>`, where the type parameter `W` is specified
8+
|
9+
= note: cannot satisfy `_: Default`
10+
note: required by a bound in `foo`
11+
--> $DIR/erase-type-params-in-label.rs:25:17
12+
|
13+
LL | fn foo<T, K, W: Default, Z: Default>(t: T, k: K) -> Foo<T, K, W, Z> {
14+
| ^^^^^^^ required by this bound in `foo`
15+
help: consider specifying the type arguments in the function call
16+
|
17+
LL | let foo = foo::<T, K, W, Z>(1, "");
18+
| ++++++++++++++
19+
20+
error[E0283]: type annotations needed for `Bar<i32, &str, Z>`
21+
--> $DIR/erase-type-params-in-label.rs:5:15
22+
|
23+
LL | let bar = bar(1, "");
24+
| --- ^^^ cannot infer type for type parameter `Z` declared on the function `bar`
625
| |
7-
| consider giving `foo` the explicit type `Bar<_, _, Z>`, where the type parameter `Z` is specified
26+
| consider giving `bar` the explicit type `Bar<_, _, Z>`, where the type parameter `Z` is specified
827
|
928
= note: cannot satisfy `_: Default`
10-
note: required by a bound in `new`
11-
--> $DIR/erase-type-params-in-label.rs:11:17
29+
note: required by a bound in `bar`
30+
--> $DIR/erase-type-params-in-label.rs:14:17
1231
|
13-
LL | fn new<T, K, Z: Default>(t: T, k: K) -> Bar<T, K, Z> {
14-
| ^^^^^^^ required by this bound in `new`
32+
LL | fn bar<T, K, Z: Default>(t: T, k: K) -> Bar<T, K, Z> {
33+
| ^^^^^^^ required by this bound in `bar`
1534
help: consider specifying the type arguments in the function call
1635
|
17-
LL | let foo = new::<T, K, Z>(1, "");
36+
LL | let bar = bar::<T, K, Z>(1, "");
1837
| +++++++++++
1938

20-
error: aborting due to previous error
39+
error: aborting due to 2 previous errors
2140

2241
For more information about this error, try `rustc --explain E0283`.

0 commit comments

Comments
 (0)