-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suggest creating unary tuples when types don't match a trait #132583
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,19 @@ | ||
pub trait Argument {} | ||
impl Argument for u8 {} | ||
impl Argument for i8 {} | ||
impl Argument for String {} | ||
impl Argument for &str {} | ||
|
||
pub trait TupleArgs {} | ||
impl<A: Argument> TupleArgs for (A,) {} | ||
impl<A: Argument, B: Argument> TupleArgs for (A, B) {} | ||
impl<A: Argument, B: Argument, C: Argument> TupleArgs for (A, B, C) {} | ||
|
||
fn convert_into_tuple(_x: impl TupleArgs) {} | ||
|
||
fn main() { | ||
convert_into_tuple(42_u8); | ||
//~^ ERROR E0277 | ||
//~| HELP the following other types implement trait `TupleArgs` | ||
//~| HELP use a unary tuple instead | ||
} |
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,25 @@ | ||
error[E0277]: the trait bound `u8: TupleArgs` is not satisfied | ||
--> $DIR/suggest_tuple_wrap.rs:15:24 | ||
| | ||
LL | convert_into_tuple(42_u8); | ||
| ------------------ ^^^^^ the trait `TupleArgs` is not implemented for `u8` | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
= help: the following other types implement trait `TupleArgs`: | ||
(A, B) | ||
(A, B, C) | ||
(A,) | ||
note: required by a bound in `convert_into_tuple` | ||
--> $DIR/suggest_tuple_wrap.rs:12:32 | ||
| | ||
LL | fn convert_into_tuple(_x: impl TupleArgs) {} | ||
| ^^^^^^^^^ required by this bound in `convert_into_tuple` | ||
help: use a unary tuple instead | ||
| | ||
LL | convert_into_tuple((42_u8,)); | ||
| + ++ | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
26 changes: 26 additions & 0 deletions
26
tests/ui/on-unimplemented/suggest_tuple_wrap_root_obligation.rs
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,26 @@ | ||
struct Tuple; | ||
|
||
impl From<(u8,)> for Tuple { | ||
fn from(_: (u8,)) -> Self { | ||
todo!() | ||
} | ||
} | ||
impl From<(u8, u8)> for Tuple { | ||
fn from(_: (u8, u8)) -> Self { | ||
todo!() | ||
} | ||
} | ||
impl From<(u8, u8, u8)> for Tuple { | ||
fn from(_: (u8, u8, u8)) -> Self { | ||
todo!() | ||
} | ||
} | ||
|
||
fn convert_into_tuple(_x: impl Into<Tuple>) {} | ||
|
||
fn main() { | ||
convert_into_tuple(42_u8); | ||
//~^ ERROR E0277 | ||
//~| HELP use a unary tuple instead | ||
//~| HELP the following other types implement trait `From<T>` | ||
} |
26 changes: 26 additions & 0 deletions
26
tests/ui/on-unimplemented/suggest_tuple_wrap_root_obligation.stderr
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,26 @@ | ||
error[E0277]: the trait bound `Tuple: From<u8>` is not satisfied | ||
--> $DIR/suggest_tuple_wrap_root_obligation.rs:22:24 | ||
| | ||
LL | convert_into_tuple(42_u8); | ||
| ------------------ ^^^^^ the trait `From<u8>` is not implemented for `Tuple` | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
= help: the following other types implement trait `From<T>`: | ||
`Tuple` implements `From<(u8, u8)>` | ||
`Tuple` implements `From<(u8, u8, u8)>` | ||
`Tuple` implements `From<(u8,)>` | ||
= note: required for `u8` to implement `Into<Tuple>` | ||
note: required by a bound in `convert_into_tuple` | ||
--> $DIR/suggest_tuple_wrap_root_obligation.rs:19:32 | ||
| | ||
LL | fn convert_into_tuple(_x: impl Into<Tuple>) {} | ||
| ^^^^^^^^^^^ required by this bound in `convert_into_tuple` | ||
help: use a unary tuple instead | ||
| | ||
LL | convert_into_tuple((42_u8,)); | ||
| + ++ | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this suggestion okay? I'm not quite sure what
#[do_not_recommend]
is supposed to (not) show. Its rfc only talks about not mentioning confusing traits.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's fine.