-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Expand suggestions for type ascription parse errors #59150
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8ba1a97
Expand suggestions for type ascription parse errors
estebank b1a6c32
Tweak labels
estebank 72a3089
Only suggest let assignment for type ascription if we find an equals …
estebank 81b876b
Hide "type ascription is experimental error" unless it's the only one
estebank 44a086e
Review comment
estebank d72ef21
Reword type ascription note to reduce verbosity
estebank 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,10 @@ | ||
enum Test { | ||
Drill { | ||
field: i32, | ||
} | ||
} | ||
|
||
fn main() { | ||
Test::Drill(field: 42); | ||
//~^ ERROR expected type, found | ||
} |
This file contains hidden or 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,16 @@ | ||
error: expected type, found `42` | ||
--> $DIR/issue-34255-1.rs:8:24 | ||
| | ||
LL | Test::Drill(field: 42); | ||
| ^^ expecting a type here because of type ascription | ||
| | ||
= note: type ascription is a nightly-only feature that lets you annotate an expression with a type: `<expr>: <type>` | ||
note: this expression expects an ascribed type after the colon | ||
--> $DIR/issue-34255-1.rs:8:17 | ||
| | ||
LL | Test::Drill(field: 42); | ||
| ^^^^^ | ||
= help: this might be indicative of a syntax error elsewhere | ||
|
||
error: aborting due to previous error | ||
|
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,10 @@ | ||
fn fun(x: i32) -> i32 { x } | ||
|
||
fn main() { | ||
let closure_annotated = |value: i32| -> i32 { | ||
temp: i32 = fun(5i32); | ||
//~^ ERROR cannot find value `temp` in this scope | ||
temp + value + 1 | ||
//~^ ERROR cannot find value `temp` in this scope | ||
}; | ||
} |
18 changes: 18 additions & 0 deletions
18
src/test/ui/suggestions/type-ascription-instead-of-let.stderr
This file contains hidden or 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,18 @@ | ||
error[E0425]: cannot find value `temp` in this scope | ||
--> $DIR/type-ascription-instead-of-let.rs:5:9 | ||
| | ||
LL | temp: i32 = fun(5i32); | ||
| ^^^^ | ||
| | | ||
| not found in this scope | ||
| help: maybe you meant to write an assignment here: `let temp` | ||
|
||
error[E0425]: cannot find value `temp` in this scope | ||
--> $DIR/type-ascription-instead-of-let.rs:7:9 | ||
| | ||
LL | temp + value + 1 | ||
| ^^^^ not found in this scope | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0425`. |
This file contains hidden or 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,4 @@ | ||
fn main() { | ||
Box:new("foo".to_string()) | ||
//~^ ERROR expected type, found | ||
} |
10 changes: 10 additions & 0 deletions
10
src/test/ui/suggestions/type-ascription-instead-of-method.stderr
This file contains hidden or 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,10 @@ | ||
error: expected type, found `"foo"` | ||
--> $DIR/type-ascription-instead-of-method.rs:2:13 | ||
| | ||
LL | Box:new("foo".to_string()) | ||
| - ^^^^^ expecting a type here because of type ascription | ||
| | | ||
| help: maybe you meant to write a path separator here: `::` | ||
|
||
error: aborting due to previous error | ||
|
This file contains hidden or 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,5 @@ | ||
fn main() { | ||
std:io::stdin(); | ||
//~^ ERROR failed to resolve: use of undeclared type or module `io` | ||
//~| ERROR expected value, found module | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.