-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Add ErrorGuaranteed
to ast::ExprKind::Err
#120586
Conversation
Some changes occurred in src/tools/clippy cc @rust-lang/clippy |
ExprKind::Err(guar) => hir::ExprKind::Err(*guar), | ||
|
||
ExprKind::Dummy => { | ||
span_bug!(e.span, "lowered ExprKind::Dummy") |
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 comment has been minimized.
This comment has been minimized.
Some changes occurred in src/tools/rustfmt cc @rust-lang/rustfmt |
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.
Very nice, thanks for working on this!
I have a couple of minor suggestions but there are still some parser changes I need to review. Note that I probably won't approve this until CI works again (oh, it runs again!). The tree is closed anyway.
You also need to to update (ah, you just pushed them haha). I see that you've already updated Clippy, amazing!src/tools/rustfmt
return false; | ||
} | ||
} | ||
TokenTree::Delimited(.., del) => check_lhs_no_empty_seq(sess, &del.tts)?, |
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.
🎉
Refactored some code, also took the liberty to remove the @rustbot review |
@@ -143,7 +143,7 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool { | |||
match (&l.kind, &r.kind) { | |||
(Paren(l), _) => eq_expr(l, r), | |||
(_, Paren(r)) => eq_expr(l, r), | |||
(Err, Err) => true, | |||
(Err(_), Err(_)) => true, |
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.
(Dummy, Dummy)
is missing from this match statement.
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.
To mimic the old behavior (Err(_), Dummy)
and (Dummy, Err(_))
may also be needed, and I wonder if (Dummy, _) | (_, Dummy) => true
makes sense.
But the only two occurences of ExprKind::Dummy
are in
<Expr as DummyAstNode>::dummy()
which isn't actually called (I can replace its body withpanic!()
and both./x test --stage 1 tests/ui/
and./x check --stage 2
passes successfully)
rust/compiler/rustc_ast/src/mut_visit.rs
Lines 1635 to 1645 in 8c0b4f6
impl DummyAstNode for Expr { fn dummy() -> Self { Expr { id: DUMMY_NODE_ID, kind: ExprKind::Err, span: Default::default(), attrs: Default::default(), tokens: Default::default(), } } } Parser::maybe_recover_trailing_expr()
for avoiding creating aP<Expr>
rust/compiler/rustc_parse/src/parser/pat.rs
Lines 388 to 394 in 8c0b4f6
// Parse `?`, `.f`, `(arg0, arg1, ...)` or `[expr]` until they've all been eaten. if let Ok(expr) = snapshot .parse_expr_dot_or_call_with( self.mk_expr_err(pat_span), // equivalent to transforming the parsed pattern into an `Expr` pat_span, AttrVec::new(), )
So ast_utils.rs
's eq_expr
cannot actually have an ExprKind::Dummy
, so this case can't be tested in the testsuite. I was tempted to put a panic!()
to hold the choice until later if someone uses Dummy
and it reaches Clippy, but if it's not tested I'd rather have a wrong diagnostic than a panic in prod.
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.
If this can really not occur here, then I suggest to add a debug_assertion
or an unreachable!
in this function. I'd like this to be an exhaustive match.
Just to give an update: I'm at 35 / 39 files viewed with pending review comments. Finishing my review later. |
Oh dear, I started working on this today, not realizing that someone else was working on it. I also did I didn't get all the way to fixing |
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.
Just posting my pending review comments. I still need to look at some of these files.
@@ -1065,7 +1071,7 @@ pub struct ExtCtxt<'a> { | |||
pub sess: &'a Session, | |||
pub ecfg: expand::ExpansionConfig<'a>, | |||
pub num_standard_library_imports: usize, | |||
pub reduced_recursion_limit: Option<Limit>, | |||
pub reduced_recursion_limit: Option<(Limit, ErrorGuaranteed)>, |
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.
Wondering if this change is strictly required or if this can stay an Option<Limit>
unless it forces us to introduce delayed_bug
somewhere?
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.
rust/compiler/rustc_expand/src/expand.rs
Lines 639 to 648 in 8c0b1fc
if !recursion_limit.value_within_limit(self.cx.current_expansion.depth) { | |
if self.cx.reduced_recursion_limit.is_none() { | |
self.error_recursion_limit_reached(); | |
} | |
// Reduce the recursion limit by half each time it triggers. | |
self.cx.reduced_recursion_limit = Some(recursion_limit / 2); | |
return ExpandResult::Ready(invoc.fragment_kind.dummy(invoc.span())); | |
} |
The error is only emitted once (MacroExpander::error_recursion_limit_reached
) and AstFragmentKind::dummy
requires a guar
.
It's possible to use DiagCtxt::has_errors().unwrap()
, but we lose the guarantee that if the recursion limit was reduced, then an error was emitted.
@@ -388,7 +388,7 @@ impl<'a> Parser<'a> { | |||
// Parse `?`, `.f`, `(arg0, arg1, ...)` or `[expr]` until they've all been eaten. | |||
if let Ok(expr) = snapshot | |||
.parse_expr_dot_or_call_with( | |||
self.mk_expr_err(pat_span), // equivalent to transforming the parsed pattern into an `Expr` | |||
self.mk_expr_dummy(pat_span), // equivalent to transforming the parsed pattern into an `Expr` |
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.
Oh, it's unfortunate that we have to use ExprKind::Dummy
here, I wish we wouldn't introduce more uses of it but I don't see a better option here either.
@nnethercote How would you go about updating trait |
☔ The latest upstream changes (presumably #121078) made this pull request unmergeable. Please resolve the merge conflicts. |
Use Because I didn't fully convert |
…ease Add `ErrorGuaranteed` to `ast::LitKind::Err`, `token::LitKind::Err`. Similar to recent work doing the same for `ExprKind::Err` (rust-lang#120586) and `TyKind::Err` (rust-lang#121109). r? `@oli-obk`
💔 Test failed - checks-actions |
@bors retry (spurious?) |
Add `ErrorGuaranteed` to `ast::ExprKind::Err` See rust-lang#119967 for context ``` \ \ _~^~^~_ \) / o o \ (/ '_ - _' / '-----' \ ``` r? fmease
💔 Test failed - checks-actions |
A job failed! Check out the build log: (web) (plain) Click to see the possible cause of the failure (guessed by this bot)
|
@bors retry |
☀️ Test successful - checks-actions |
…ease Add `ErrorGuaranteed` to `ast::LitKind::Err`, `token::LitKind::Err`. Similar to recent work doing the same for `ExprKind::Err` (rust-lang#120586) and `TyKind::Err` (rust-lang#121109). r? `@oli-obk`
Finished benchmarking commit (b79db43): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 649.794s -> 649.972s (0.03%) |
Properly emit `expected ;` on `#[attr] expr` Fixes rust-lang#121647 See rust-lang#118182, rust-lang#120586 --- r? estebank
Rollup merge of rust-lang#121651 - ShE3py:issue-121647, r=estebank Properly emit `expected ;` on `#[attr] expr` Fixes rust-lang#121647 See rust-lang#118182, rust-lang#120586 --- r? estebank
Add `ErrorGuaranteed` to `ast::ExprKind::Err` See rust-lang#119967 for context ``` \ \ _~^~^~_ \) / o o \ (/ '_ - _' / '-----' \ ``` r? fmease
Add `ErrorGuaranteed` to `ast::ExprKind::Err` See rust-lang#119967 for context ``` \ \ _~^~^~_ \) / o o \ (/ '_ - _' / '-----' \ ``` r? fmease
See #119967 for context
r? fmease