-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Always emit unclosed delimiter diagnostics #58903
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2ec7d0b
Do not panic on missing close paren
estebank cc535a2
Bail when encountering a second unexpected token in the same span
estebank ed2de5a
Emit unclosed delimiters during recovery
estebank e38e915
Reduce test case
estebank c70a516
Panic when unmatched delimiters aren't emitted
estebank 51d0e86
Emit missing unclosed delimiter errors
estebank ac6cc2d
Collect unclosed delimiters in parent parser
estebank f156d92
Always emit mismatched delim errors, never panic
estebank 3818f8b
Add regression test for #58886
estebank 6f0f2fc
Simplify code
estebank 551ea65
Rely on drop to emit unclosed delims
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
impl A { | ||
fn b(self> | ||
//~^ ERROR expected one of `)`, `,`, or `:`, found `>` | ||
} | ||
|
||
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,11 @@ | ||
error: expected one of `)`, `,`, or `:`, found `>` | ||
--> $DIR/issue-58856-1.rs:2:14 | ||
| | ||
LL | fn b(self> | ||
| - ^ | ||
| | | | ||
| | help: `)` may belong here | ||
| unclosed delimiter | ||
|
||
error: aborting due to previous error | ||
|
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,14 @@ | ||
struct Empty; | ||
|
||
trait Howness {} | ||
|
||
impl Howness for () { | ||
fn how_are_you(&self -> Empty { | ||
//~^ ERROR expected one of `)` or `,`, found `->` | ||
//~| ERROR method `how_are_you` is not a member of trait `Howness` | ||
Empty | ||
} | ||
} | ||
//~^ ERROR expected one of `async`, `const`, `crate`, `default`, `existential`, `extern`, `fn`, | ||
|
||
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,30 @@ | ||
error: expected one of `)` or `,`, found `->` | ||
--> $DIR/issue-58856-2.rs:6:26 | ||
| | ||
LL | fn how_are_you(&self -> Empty { | ||
| - -^^ | ||
| | | | ||
| | help: `)` may belong here | ||
| unclosed delimiter | ||
|
||
error: expected one of `async`, `const`, `crate`, `default`, `existential`, `extern`, `fn`, `pub`, `type`, `unsafe`, or `}`, found `)` | ||
--> $DIR/issue-58856-2.rs:11:1 | ||
| | ||
LL | } | ||
| - expected one of 11 possible tokens here | ||
LL | } | ||
| ^ unexpected token | ||
|
||
error[E0407]: method `how_are_you` is not a member of trait `Howness` | ||
--> $DIR/issue-58856-2.rs:6:5 | ||
| | ||
LL | / fn how_are_you(&self -> Empty { | ||
LL | | //~^ ERROR expected one of `)` or `,`, found `->` | ||
LL | | //~| ERROR method `how_are_you` is not a member of trait `Howness` | ||
LL | | Empty | ||
LL | | } | ||
| |_____^ not a member of trait `Howness` | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0407`. |
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,6 @@ | ||
mod unclosed_delim_mod; | ||
|
||
fn main() { | ||
let _: usize = unclosed_delim_mod::new(); | ||
//~^ ERROR mismatched types | ||
} |
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,23 @@ | ||
error: incorrect close delimiter: `}` | ||
--> $DIR/unclosed_delim_mod.rs:5:1 | ||
| | ||
LL | pub fn new() -> Result<Value, ()> { | ||
| - close delimiter possibly meant for this | ||
LL | Ok(Value { | ||
| - un-closed delimiter | ||
LL | } | ||
LL | } | ||
| ^ incorrect close delimiter | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/unclosed-delimiter-in-dep.rs:4:20 | ||
| | ||
LL | let _: usize = unclosed_delim_mod::new(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ expected usize, found enum `std::result::Result` | ||
| | ||
= note: expected type `usize` | ||
found type `std::result::Result<unclosed_delim_mod::Value, ()>` | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
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,6 @@ | ||
pub struct Value {} | ||
pub fn new() -> Result<Value, ()> { | ||
Ok(Value { | ||
} | ||
} | ||
//~^ ERROR incorrect close delimiter |
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.
Finally identified what is causing these: when reaching the end of the current
TokenTree
,self.bump()
will advance to a close token corresponding to the opening delimiter. There are two options: 1) attempt to rewrite theTokenTree
representation that theParser
has once we suggest a close delim (high potential for bad lurking bugs), or 2) catch this specific case inexpect_one_of
, but that might be too magical.