forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
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 rust-lang#95758 - compiler-errors:issue-54771, r=este…
…bank Only suggest removing semicolon when expression is compatible with `impl Trait` rust-lang#54771 (comment) > It still needs checking that the last statement's expr can actually conform to the trait, but the naïve behavior is there. Only suggest removing a semicolon when the type behind the semicolon actually implements the trait in an RPIT `-> impl Trait`. Also upgrade the label that suggests removing the semicolon to a suggestion (should it be verbose?). cc rust-lang#54771
- Loading branch information
Showing
15 changed files
with
97 additions
and
32 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
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