-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #100838 - hkmatsumoto:move-gen-args-to-trait-when-app…
…ropriate, r=davidtwco Suggest moving redundant generic args of an assoc fn to its trait Closes #89064
- Loading branch information
Showing
4 changed files
with
245 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use std::convert::TryInto; | ||
|
||
trait A<T> { | ||
fn foo() {} | ||
} | ||
|
||
trait B<T, U> { | ||
fn bar() {} | ||
} | ||
|
||
struct S; | ||
|
||
impl<T> A<T> for S {} | ||
impl<T, U> B<T, U> for S {} | ||
|
||
fn main() { | ||
let _ = A::foo::<S>(); | ||
//~^ ERROR | ||
//~| HELP remove these generics | ||
//~| HELP consider moving this generic argument | ||
|
||
let _ = B::bar::<S, S>(); | ||
//~^ ERROR | ||
//~| HELP remove these generics | ||
//~| HELP consider moving these generic arguments | ||
|
||
let _ = A::<S>::foo::<S>(); | ||
//~^ ERROR | ||
//~| HELP remove these generics | ||
|
||
let _ = 42.into::<Option<_>>(); | ||
//~^ ERROR | ||
//~| HELP remove these generics | ||
//~| HELP consider moving this generic argument | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
error[E0107]: this associated function takes 0 generic arguments but 1 generic argument was supplied | ||
--> $DIR/issue-89064.rs:17:16 | ||
| | ||
LL | let _ = A::foo::<S>(); | ||
| ^^^ expected 0 generic arguments | ||
| | ||
note: associated function defined here, with 0 generic parameters | ||
--> $DIR/issue-89064.rs:4:8 | ||
| | ||
LL | fn foo() {} | ||
| ^^^ | ||
help: consider moving this generic argument to the `A` trait, which takes up to 1 argument | ||
| | ||
LL - let _ = A::foo::<S>(); | ||
LL + let _ = A::<S>::foo(); | ||
| | ||
help: remove these generics | ||
| | ||
LL - let _ = A::foo::<S>(); | ||
LL + let _ = A::foo(); | ||
| | ||
|
||
error[E0107]: this associated function takes 0 generic arguments but 2 generic arguments were supplied | ||
--> $DIR/issue-89064.rs:22:16 | ||
| | ||
LL | let _ = B::bar::<S, S>(); | ||
| ^^^ expected 0 generic arguments | ||
| | ||
note: associated function defined here, with 0 generic parameters | ||
--> $DIR/issue-89064.rs:8:8 | ||
| | ||
LL | fn bar() {} | ||
| ^^^ | ||
help: consider moving these generic arguments to the `B` trait, which takes up to 2 arguments | ||
| | ||
LL - let _ = B::bar::<S, S>(); | ||
LL + let _ = B::<S, S>::bar(); | ||
| | ||
help: remove these generics | ||
| | ||
LL - let _ = B::bar::<S, S>(); | ||
LL + let _ = B::bar(); | ||
| | ||
|
||
error[E0107]: this associated function takes 0 generic arguments but 1 generic argument was supplied | ||
--> $DIR/issue-89064.rs:27:21 | ||
| | ||
LL | let _ = A::<S>::foo::<S>(); | ||
| ^^^----- help: remove these generics | ||
| | | ||
| expected 0 generic arguments | ||
| | ||
note: associated function defined here, with 0 generic parameters | ||
--> $DIR/issue-89064.rs:4:8 | ||
| | ||
LL | fn foo() {} | ||
| ^^^ | ||
|
||
error[E0107]: this associated function takes 0 generic arguments but 1 generic argument was supplied | ||
--> $DIR/issue-89064.rs:31:16 | ||
| | ||
LL | let _ = 42.into::<Option<_>>(); | ||
| ^^^^ expected 0 generic arguments | ||
| | ||
note: associated function defined here, with 0 generic parameters | ||
--> $SRC_DIR/core/src/convert/mod.rs:LL:COL | ||
| | ||
LL | fn into(self) -> T; | ||
| ^^^^ | ||
help: consider moving this generic argument to the `Into` trait, which takes up to 1 argument | ||
| | ||
LL | let _ = Into::<Option<_>>::into(42); | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
help: remove these generics | ||
| | ||
LL - let _ = 42.into::<Option<_>>(); | ||
LL + let _ = 42.into(); | ||
| | ||
|
||
error: aborting due to 4 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0107`. |