-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Do not emit type errors on recovered blocks #46732
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
ce52a2d
to
d2d3f94
Compare
The case reported in #44579 is 100% reasonable recovery. (Also, the "unmatched visibility" wording was really weird and unhelpful (unmatched with what?), it's really nice that it's changed to "missing |
Output on nightly, the first error is much more visible now:
|
@petrochenkov the first error is more prominent now in this case, but any syntax error will cause the type error to happen. Consider the following case instead: pub struct Foo {
text: String
}
pub fn parse() -> Foo {
fn
Foo { text: "".to_string() }
}
The second error won't happen once the syntax error is fixed, but the compiler can't know that, and it is still the most vertically prominent error in the output. I feel that masking the type error when we know the block had a parse error (that we made an effort to continue after) is a better default. |
c6ceea9
to
d99aef8
Compare
☔ The latest upstream changes (presumably #46641) made this pull request unmergeable. Please resolve the merge conflicts. |
0d5a2f8
to
736e9b8
Compare
If some piece of code look so similar to a legal statement that we recover it as a legal statement (e.g. an item statement in case of pub fn parse() -> Foo { <not_poisoned>
let args: Vec<String> = env::args().collect();
let text = args[1].clone();
pub Foo { <poisoned> text </poisoned> }
</not_poisoned> } In the example with pub fn parse() -> Foo { <poisoned>
fn
Foo { text: "".to_string() }
</poisoned> } I need to make some experiments. |
d5c526f
to
0d5b144
Compare
})) | ||
} | ||
|
||
/// Parse a statement, including the trailing semicolon. | ||
pub fn parse_full_stmt(&mut self, macro_legacy_warnings: bool) -> PResult<'a, Option<Stmt>> { | ||
let mut stmt = match self.parse_stmt_(macro_legacy_warnings) { | ||
let mut stmt = match self.parse_stmt_without_recovery(macro_legacy_warnings)? { |
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.
This seems to be a change independent from adding the recovered
flag to blocks?
From what I see in the test diffs I'd keep this recovery in place.
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.
The recovery happens in the callee already, and using parse_stmt_
swallows errors that we do want to see in parse_block_tail
.
|
||
pub Foo { text } | ||
} | ||
//~^^ ERROR missing `struct` for struct definition |
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.
Could you add the example with fn
(#46732 (comment)) as a test too?
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.
added
r=me with comments addressed I still want to look at the statement recovery more carefully, but not right now (probably replace the |
9e392e2
to
351f06a
Compare
@bors r=petrochencov |
📌 Commit 351f06a has been approved by |
Do not emit type errors on recovered blocks When a parse error occurs on a block, the parser will recover and create a block with the statements collected until that point. Now a flag stating that a recovery has been performed in this block is propagated so that the type checker knows that the type of the block (which will be identified as `()`) shouldn't be checked against the expectation to reduce the amount of irrelevant diagnostic errors shown to the user. Fix #44579.
💔 Test failed - status-appveyor |
rustfmt and rls are marked as "Broken" in https://github.com/rust-lang/rust/blob/master/src/tools/toolstate.toml, a pull request to rustfmt can be sent asyncroniously. |
Already marked as broken, looks like the failure was due to sscache. @bors r=petrochenkov |
📌 Commit 351f06a has been approved by |
⌛ Testing commit 351f06a with merge a6c1141a37b6b16e467ca070daf55948e9068045... |
💔 Test failed - status-travis |
RLS and rustfmt are still broken. |
When a parse error occurs on a block, the parser will recover and create a block with the statements collected until that point. Now a flag stating that a recovery has been performed in this block is propagated so that the type checker knows that the type of the block (which will be identified as `()`) shouldn't be checked against the expectation to reduce the amount of irrelevant diagnostic errors shown to the user.
351f06a
to
d90d5d1
Compare
@bors try |
Do not emit type errors on recovered blocks When a parse error occurs on a block, the parser will recover and create a block with the statements collected until that point. Now a flag stating that a recovery has been performed in this block is propagated so that the type checker knows that the type of the block (which will be identified as `()`) shouldn't be checked against the expectation to reduce the amount of irrelevant diagnostic errors shown to the user. Fix #44579.
☀️ Test successful - status-travis |
@bors r=petrochenkov |
📌 Commit d90d5d1 has been approved by |
Do not emit type errors on recovered blocks When a parse error occurs on a block, the parser will recover and create a block with the statements collected until that point. Now a flag stating that a recovery has been performed in this block is propagated so that the type checker knows that the type of the block (which will be identified as `()`) shouldn't be checked against the expectation to reduce the amount of irrelevant diagnostic errors shown to the user. Fix #44579.
☀️ Test successful - status-appveyor, status-travis |
Awesome! Thanks a lot for this |
When a parse error occurs on a block, the parser will recover and create
a block with the statements collected until that point. Now a flag
stating that a recovery has been performed in this block is propagated
so that the type checker knows that the type of the block (which will be
identified as
()
) shouldn't be checked against the expectation toreduce the amount of irrelevant diagnostic errors shown to the user.
Fix #44579.