-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Only suggest removing semicolon when expression is compatible with impl Trait
#95758
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
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
21 changes: 19 additions & 2 deletions
21
src/test/ui/suggestions/impl-trait-return-trailing-semicolon.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 |
---|---|---|
@@ -1,8 +1,25 @@ | ||
trait Bar {} | ||
impl Bar for u8 {} | ||
|
||
impl Bar for i32 {} | ||
|
||
struct Qux; | ||
|
||
impl Bar for Qux {} | ||
|
||
fn foo() -> impl Bar { | ||
5; //~^ ERROR the trait bound `(): Bar` is not satisfied | ||
//~^ ERROR the trait bound `(): Bar` is not satisfied | ||
//~| ERROR the trait bound `(): Bar` is not satisfied | ||
//~| HELP the following other types implement trait `Bar`: | ||
5; | ||
//~^ HELP remove this semicolon | ||
} | ||
|
||
fn bar() -> impl Bar { | ||
//~^ ERROR the trait bound `(): Bar` is not satisfied | ||
//~| ERROR the trait bound `(): Bar` is not satisfied | ||
//~| HELP the following other types implement trait `Bar`: | ||
//~| HELP the following other types implement trait `Bar`: | ||
""; | ||
} | ||
|
||
fn main() {} |
45 changes: 40 additions & 5 deletions
45
src/test/ui/suggestions/impl-trait-return-trailing-semicolon.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 |
---|---|---|
@@ -1,23 +1,58 @@ | ||
error[E0277]: the trait bound `(): Bar` is not satisfied | ||
--> $DIR/impl-trait-return-trailing-semicolon.rs:3:13 | ||
--> $DIR/impl-trait-return-trailing-semicolon.rs:9:13 | ||
| | ||
LL | fn foo() -> impl Bar { | ||
| ^^^^^^^^ the trait `Bar` is not implemented for `()` | ||
... | ||
LL | 5; | ||
| - consider removing this semicolon | ||
| -- help: remove this semicolon | ||
| | | ||
| this expression has type `{integer}`, which implements `Bar` | ||
|
||
error[E0277]: the trait bound `(): Bar` is not satisfied | ||
--> $DIR/impl-trait-return-trailing-semicolon.rs:3:22 | ||
--> $DIR/impl-trait-return-trailing-semicolon.rs:9:22 | ||
| | ||
LL | fn foo() -> impl Bar { | ||
| ______________________^ | ||
LL | | | ||
LL | | | ||
LL | | | ||
LL | | 5; | ||
LL | | | ||
LL | | } | ||
| |_^ the trait `Bar` is not implemented for `()` | ||
| | ||
= help: the trait `Bar` is implemented for `u8` | ||
= help: the following other types implement trait `Bar`: | ||
Qux | ||
i32 | ||
|
||
error[E0277]: the trait bound `(): Bar` is not satisfied | ||
--> $DIR/impl-trait-return-trailing-semicolon.rs:17:13 | ||
| | ||
LL | fn bar() -> impl Bar { | ||
| ^^^^^^^^ the trait `Bar` is not implemented for `()` | ||
| | ||
= help: the following other types implement trait `Bar`: | ||
Qux | ||
i32 | ||
|
||
error[E0277]: the trait bound `(): Bar` is not satisfied | ||
--> $DIR/impl-trait-return-trailing-semicolon.rs:17:22 | ||
| | ||
LL | fn bar() -> impl Bar { | ||
| ______________________^ | ||
LL | | | ||
LL | | | ||
LL | | | ||
LL | | | ||
LL | | ""; | ||
LL | | } | ||
| |_^ the trait `Bar` is not implemented for `()` | ||
| | ||
= help: the following other types implement trait `Bar`: | ||
Qux | ||
i32 | ||
|
||
error: aborting due to 2 previous errors | ||
error: aborting due to 4 previous errors | ||
|
||
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
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
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.
Should we add a span label pointing at the last statement saying "this is a statement, which are always of type
()
" and maybe mention the type of the expression in that statement if it were a tail expression, explaining that it doesn't match the trait?