Skip to content

Commit

Permalink
Add test with multiple type params failing inference
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Dec 7, 2021
1 parent 6a691b1 commit 7271d1f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -939,9 +939,7 @@ impl<'tcx> ResolvedTypeParamEraser<'tcx> {
/// 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> {
match c.val {
ty::ConstKind::Infer(..) => {
self.tcx().mk_const_param(index, name, c.ty)
}
ty::ConstKind::Infer(..) => self.tcx().mk_const_param(index, name, c.ty),
_ => c,
}
}
Expand Down
18 changes: 16 additions & 2 deletions src/test/ui/inference/erase-type-params-in-label.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
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> {
Expand All @@ -8,6 +11,17 @@ struct Bar<T, K, N: Default> {
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() }
}

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() }
}
39 changes: 29 additions & 10 deletions src/test/ui/inference/erase-type-params-in-label.stderr
Original file line number Diff line number Diff line change
@@ -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
|
LL | let foo = new(1, "");
| --- ^^^ cannot infer type for type parameter `Z` declared on the function `new`
LL | let foo = foo(1, "");
| --- ^^^ cannot infer type for type parameter `W` declared on the function `foo`
| |
| consider giving `foo` the explicit type `Foo<_, _, W, Z>`, where the type parameter `W` is specified
|
= note: cannot satisfy `_: Default`
note: required by a bound in `foo`
--> $DIR/erase-type-params-in-label.rs:25:17
|
LL | fn foo<T, K, W: Default, Z: Default>(t: T, k: K) -> Foo<T, K, W, Z> {
| ^^^^^^^ required by this bound in `foo`
help: consider specifying the type arguments in the function call
|
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 `foo` the explicit type `Bar<_, _, Z>`, where the type parameter `Z` is specified
| 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 `new`
--> $DIR/erase-type-params-in-label.rs:11:17
note: required by a bound in `bar`
--> $DIR/erase-type-params-in-label.rs:14:17
|
LL | fn new<T, K, Z: Default>(t: T, k: K) -> Bar<T, K, Z> {
| ^^^^^^^ required by this bound in `new`
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 foo = new::<T, K, Z>(1, "");
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`.

0 comments on commit 7271d1f

Please sign in to comment.