-
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
Make E0121's suggestion more robust (+ fix E0308's suggestion) #80847
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#![feature(generators)] | ||
|
||
// Functions with a type placeholder `_` as the return type should | ||
// not suggest returning the unnameable type of generators. | ||
// This is a regression test of #80844 | ||
|
||
struct Container<T>(T); | ||
|
||
fn returns_generator() -> _ { | ||
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures [E0121] | ||
//~| NOTE not allowed in type signatures | ||
//~| HELP consider using a `Generator` trait bound | ||
//~| NOTE for more information on generators | ||
|| yield 0i32 | ||
} | ||
|
||
fn returns_returns_generator() -> _ { | ||
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures [E0121] | ||
//~| NOTE not allowed in type signatures | ||
returns_generator | ||
} | ||
|
||
fn returns_option_closure() -> _ { | ||
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures [E0121] | ||
//~| NOTE not allowed in type signatures | ||
Some(|| 0i32) | ||
} | ||
|
||
fn returns_option_i32() -> _ { | ||
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures [E0121] | ||
//~| NOTE not allowed in type signatures | ||
//~| HELP replace with the correct return type | ||
//~| SUGGESTION Option<i32> | ||
Some(0i32) | ||
} | ||
|
||
fn returns_container_closure() -> _ { | ||
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures [E0121] | ||
//~| NOTE not allowed in type signatures | ||
Container(|| 0i32) | ||
} | ||
|
||
fn returns_container_i32() -> _ { | ||
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures [E0121] | ||
//~| NOTE not allowed in type signatures | ||
//~| HELP replace with the correct return type | ||
//~| SUGGESTION Container<i32> | ||
Container(0i32) | ||
} | ||
|
||
fn main() {} |
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,48 @@ | ||
error[E0121]: the type placeholder `_` is not allowed within types on item signatures | ||
--> $DIR/issue-80844-e0121.rs:9:27 | ||
| | ||
LL | fn returns_generator() -> _ { | ||
| ^ not allowed in type signatures | ||
| | ||
= help: consider using a `Generator` trait bound | ||
= note: for more information on generators, see https://doc.rust-lang.org/beta/unstable-book/language-features/generators.html | ||
|
||
error[E0121]: the type placeholder `_` is not allowed within types on item signatures | ||
--> $DIR/issue-80844-e0121.rs:17:35 | ||
| | ||
LL | fn returns_returns_generator() -> _ { | ||
| ^ not allowed in type signatures | ||
|
||
error[E0121]: the type placeholder `_` is not allowed within types on item signatures | ||
--> $DIR/issue-80844-e0121.rs:23:32 | ||
| | ||
LL | fn returns_option_closure() -> _ { | ||
| ^ not allowed in type signatures | ||
|
||
error[E0121]: the type placeholder `_` is not allowed within types on item signatures | ||
--> $DIR/issue-80844-e0121.rs:29:28 | ||
| | ||
LL | fn returns_option_i32() -> _ { | ||
| ^ | ||
| | | ||
| not allowed in type signatures | ||
| help: replace with the correct return type: `Option<i32>` | ||
|
||
error[E0121]: the type placeholder `_` is not allowed within types on item signatures | ||
--> $DIR/issue-80844-e0121.rs:37:35 | ||
| | ||
LL | fn returns_container_closure() -> _ { | ||
| ^ not allowed in type signatures | ||
|
||
error[E0121]: the type placeholder `_` is not allowed within types on item signatures | ||
--> $DIR/issue-80844-e0121.rs:43:31 | ||
| | ||
LL | fn returns_container_i32() -> _ { | ||
| ^ | ||
| | | ||
| not allowed in type signatures | ||
| help: replace with the correct return type: `Container<i32>` | ||
|
||
error: aborting due to 6 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0121`. |
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,61 @@ | ||
#![feature(generators)] | ||
|
||
// Functions with a type placeholder `_` as the return type should | ||
// not suggest returning the unnameable type of generators. | ||
// This is a regression test of #80844 | ||
|
||
struct Container<T>(T); | ||
|
||
fn expected_unit_got_generator() { | ||
//~^ NOTE possibly return type missing here? | ||
|| yield 0i32 | ||
//~^ ERROR mismatched types [E0308] | ||
//~| NOTE expected unit type `()` | ||
//~| NOTE expected `()`, found generator | ||
} | ||
|
||
fn expected_unit_got_closure() { | ||
//~^ NOTE possibly return type missing here? | ||
|| 0i32 | ||
//~^ ERROR mismatched types [E0308] | ||
//~| NOTE expected unit type `()` | ||
//~| NOTE expected `()`, found closure | ||
} | ||
|
||
fn expected_unit_got_option_closure() { | ||
//~^ NOTE possibly return type missing here? | ||
Some(|| 0i32) | ||
//~^ ERROR mismatched types [E0308] | ||
//~| NOTE expected unit type `()` | ||
//~| NOTE expected `()`, found enum `Option` | ||
//~| HELP try adding a semicolon | ||
} | ||
|
||
fn expected_unit_got_option_i32() { | ||
//~^ NOTE possibly return type missing here? | ||
Some(0i32) | ||
//~^ ERROR mismatched types [E0308] | ||
//~| NOTE expected unit type `()` | ||
//~| NOTE expected `()`, found enum `Option` | ||
//~| HELP try adding a semicolon | ||
} | ||
|
||
fn expected_unit_got_container_closure() { | ||
//~^ NOTE possibly return type missing here? | ||
Container(|| 0i32) | ||
//~^ ERROR mismatched types [E0308] | ||
//~| NOTE expected unit type `()` | ||
//~| NOTE expected `()`, found struct `Container` | ||
//~| HELP try adding a semicolon | ||
} | ||
|
||
fn expected_unit_got_container_i32() { | ||
//~^ NOTE possibly return type missing here? | ||
Container(0i32) | ||
//~^ ERROR mismatched types [E0308] | ||
//~| NOTE expected unit type `()` | ||
//~| NOTE expected `()`, found struct `Container` | ||
//~| HELP try adding a semicolon | ||
} | ||
|
||
fn main() {} |
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.
I think this check can now be removed thanks to
is_suggestable
accounting forError
.