-
Notifications
You must be signed in to change notification settings - Fork 13.4k
rustc_typeck: improve diagnostics for -> _ fn return type #62694
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,10 @@ error[E0121]: the type placeholder `_` is not allowed within types on item signa | |
--> $DIR/E0121.rs:1:13 | ||
| | ||
LL | fn foo() -> _ { 5 } | ||
| ^ not allowed in type signatures | ||
| ^ | ||
| | | ||
| not allowed in type signatures | ||
| help: replace `_` with the correct return type: `i32` | ||
|
||
error[E0121]: the type placeholder `_` is not allowed within types on item signatures | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Heh, you could also implement it for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could also add parser recovery for when no type is provided syntactically, for example: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Help for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, basically delegate to the AST representation of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Centril But would we have the correct type to suggest in the parser? (I assume you implied the type of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The correct type in the parser would be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But then the suggestion for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can skip this for now, tbh. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, let's follow up later. @lundibundi We should take care not to suggest replacing |
||
--> $DIR/E0121.rs:3:13 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// This test checks that it proper item type will be suggested when | ||
// using the `_` type placeholder. | ||
|
||
fn test1() -> _ { Some(42) } | ||
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures | ||
|
||
pub fn main() { | ||
let _: Option<usize> = test1(); | ||
let _: f64 = test1(); | ||
let _: Option<i32> = test1(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
error[E0121]: the type placeholder `_` is not allowed within types on item signatures | ||
--> $DIR/typeck_type_placeholder_item_help.rs:4:15 | ||
| | ||
LL | fn test1() -> _ { Some(42) } | ||
| ^ | ||
| | | ||
| not allowed in type signatures | ||
| help: replace `_` with the correct return type: `std::option::Option<i32>` | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0121`. |
Uh oh!
There was an error while loading. Please reload this page.