Suggest replacing _ in type signature of impl for Trait

This commit is contained in:
Michael Goulet 2022-03-27 19:43:05 -07:00
parent 18f314e702
commit 42dbbabcb0
6 changed files with 147 additions and 15 deletions

View file

@ -0,0 +1,13 @@
// run-rustfix
#![allow(unused)]
trait Foo<T>: Sized {
fn bar(i: i32, t: T, s: &Self) {}
}
impl Foo<usize> for () {
fn bar(i: i32, t: usize, s: &()) {}
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions
}
fn main() {}

View file

@ -0,0 +1,13 @@
// run-rustfix
#![allow(unused)]
trait Foo<T>: Sized {
fn bar(i: i32, t: T, s: &Self) {}
}
impl Foo<usize> for () {
fn bar(i: _, t: _, s: _) {}
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions
}
fn main() {}

View file

@ -0,0 +1,17 @@
error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions
--> $DIR/replace-impl-infer-ty-from-trait.rs:9:15
|
LL | fn bar(i: _, t: _, s: _) {}
| ^ ^ ^ not allowed in type signatures
| | |
| | not allowed in type signatures
| not allowed in type signatures
|
help: try replacing `_` with the types in the corresponding trait method signature
|
LL | fn bar(i: i32, t: usize, s: &()) {}
| ~~~ ~~~~~ ~~~
error: aborting due to previous error
For more information about this error, try `rustc --explain E0121`.

View file

@ -560,10 +560,10 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
LL | fn clone_from(&mut self, other: _) { *self = Test9; }
| ^ not allowed in type signatures
|
help: use type parameters instead
help: try replacing `_` with the type in the corresponding trait method signature
|
LL | fn clone_from<T>(&mut self, other: T) { *self = Test9; }
| +++ ~
LL | fn clone_from(&mut self, other: &Test9) { *self = Test9; }
| ~~~~~~
error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types
--> $DIR/typeck_type_placeholder_item.rs:107:31
@ -600,10 +600,10 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
LL | fn clone_from(&mut self, other: _) { *self = FnTest9; }
| ^ not allowed in type signatures
|
help: use type parameters instead
help: try replacing `_` with the type in the corresponding trait method signature
|
LL | fn clone_from<T>(&mut self, other: T) { *self = FnTest9; }
| +++ ~
LL | fn clone_from(&mut self, other: &FnTest9) { *self = FnTest9; }
| ~~~~~~~~
error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated types
--> $DIR/typeck_type_placeholder_item.rs:201:14