rustc_parse: Stop returning Option from statement parsing#159849
rustc_parse: Stop returning Option from statement parsing#159849petrochenkov wants to merge 1 commit into
Option from statement parsing#159849Conversation
|
The parser was modified, potentially altering the grammar of (stable) Rust cc @fmease Some changes occurred in compiler/rustc_attr_parsing |
|
rustbot has assigned @hanna-kruppe. Use Why was this reviewer chosen?The reviewer was selected based on:
|
| } else if self.eat(exp!(Semi)) { | ||
| // Do not attempt to parse an expression if we're done here. | ||
| self.error_outer_attrs(attrs); | ||
| self.error_outer_attrs(attrs)?; |
There was a problem hiding this comment.
Note: what we did here previously was recovery, which is a bit sus in a function ending with _without_recovery and without checking for may_recover. So we no longer recover now.
| } else if self.token != token::CloseBrace { | ||
| } else if self.token == token::CloseBrace { | ||
| self.error_outer_attrs(attrs)?; | ||
| self.dcx().span_bug(self.token.span, "don't parse a statement if you see `}`"); |
There was a problem hiding this comment.
Technically this branch is unnecessary, we can just fall through into the last else clause, we'll just get worse error messages like "expected an expression, found }".
There was a problem hiding this comment.
@bors r+ rollup
This is quite a lot nicer, thanks!
rustc_parse: Stop returning `Option` from statement parsing `parse_stmt_without_recovery` had one corner case in which it returned `Ok(None)` - when parsing immediately encountered a closing brace `}`, possibly after parsing outer attributes. It is simpler to never call `parse_stmt_without_recovery` in such contexts than deal with a possibility of no statement being returned without an error. So this PR changes the function's return type from `PResult<'a, Option<Stmt>>` to `PResult<'a, Stmt>` and adjusts one call site to check for a closing brace.
rustc_parse: Stop returning `Option` from statement parsing `parse_stmt_without_recovery` had one corner case in which it returned `Ok(None)` - when parsing immediately encountered a closing brace `}`, possibly after parsing outer attributes. It is simpler to never call `parse_stmt_without_recovery` in such contexts than deal with a possibility of no statement being returned without an error. So this PR changes the function's return type from `PResult<'a, Option<Stmt>>` to `PResult<'a, Stmt>` and adjusts one call site to check for a closing brace.
rustc_parse: Stop returning `Option` from statement parsing `parse_stmt_without_recovery` had one corner case in which it returned `Ok(None)` - when parsing immediately encountered a closing brace `}`, possibly after parsing outer attributes. It is simpler to never call `parse_stmt_without_recovery` in such contexts than deal with a possibility of no statement being returned without an error. So this PR changes the function's return type from `PResult<'a, Option<Stmt>>` to `PResult<'a, Stmt>` and adjusts one call site to check for a closing brace.
rustc_parse: Stop returning `Option` from statement parsing `parse_stmt_without_recovery` had one corner case in which it returned `Ok(None)` - when parsing immediately encountered a closing brace `}`, possibly after parsing outer attributes. It is simpler to never call `parse_stmt_without_recovery` in such contexts than deal with a possibility of no statement being returned without an error. So this PR changes the function's return type from `PResult<'a, Option<Stmt>>` to `PResult<'a, Stmt>` and adjusts one call site to check for a closing brace.
…uwer Rollup of 24 pull requests Successful merges: - #159638 (bootstrap: Split the `Step` trait into multiple traits) - #159774 (rustc_trait_selection: fix trait solver hang caused by degenerate obligations) - #159837 (line-tables-only test: check that the line number matches the function name) - #159946 (Update Enzyme submodule to imporve llvm-cov) - #159617 (Fix up `#[linkage]` target checking) - #159733 (std: Switch implementations of `thread_local!` for WASI) - #159783 (Check unsafe impls on safe EIIs) - #159810 (Add tuple never coercion collection regression test) - #159821 (Update expect message using the recommended style in binary_heap module) - #159826 (Remove redundant `#[rustc_paren_sugar]` feature gate) - #159846 (Implement `str::copy_from_str`) - #159849 (rustc_parse: Stop returning `Option` from statement parsing) - #159853 (Updated expect messages for `CString` struct and method documentation) - #159875 (More cleanup in `rustc_attr_parsing`) - #159882 (Update expect messages in library/alloc/boxed.rs and library/alloc/string.rs to follow the style guide) - #159891 (Split multiline derives into std/rustc macros) - #159893 (Fix `find_attr` hygiene and `rustc_hir` cleanups) - #159895 (rustc-dev-guide subtree update) - #159902 (Clarify that the expected runtime symbols signature is for the current target only) - #159914 (Fix error in diagnostic on_unmatched_args) - #159917 (spare capacity mut constification) - #159918 (rename abort_unwind → abort_on_unwind) - #159936 (Minor `rustc_ast::ast` doc cleanups) - #159945 (Update expect messages in library/core/src/ptr/non_null.rs)
…uwer Rollup of 24 pull requests Successful merges: - #159638 (bootstrap: Split the `Step` trait into multiple traits) - #159774 (rustc_trait_selection: fix trait solver hang caused by degenerate obligations) - #159837 (line-tables-only test: check that the line number matches the function name) - #159946 (Update Enzyme submodule to imporve llvm-cov) - #159617 (Fix up `#[linkage]` target checking) - #159733 (std: Switch implementations of `thread_local!` for WASI) - #159783 (Check unsafe impls on safe EIIs) - #159810 (Add tuple never coercion collection regression test) - #159821 (Update expect message using the recommended style in binary_heap module) - #159826 (Remove redundant `#[rustc_paren_sugar]` feature gate) - #159846 (Implement `str::copy_from_str`) - #159849 (rustc_parse: Stop returning `Option` from statement parsing) - #159853 (Updated expect messages for `CString` struct and method documentation) - #159875 (More cleanup in `rustc_attr_parsing`) - #159882 (Update expect messages in library/alloc/boxed.rs and library/alloc/string.rs to follow the style guide) - #159891 (Split multiline derives into std/rustc macros) - #159893 (Fix `find_attr` hygiene and `rustc_hir` cleanups) - #159895 (rustc-dev-guide subtree update) - #159902 (Clarify that the expected runtime symbols signature is for the current target only) - #159914 (Fix error in diagnostic on_unmatched_args) - #159917 (spare capacity mut constification) - #159918 (rename abort_unwind → abort_on_unwind) - #159936 (Minor `rustc_ast::ast` doc cleanups) - #159945 (Update expect messages in library/core/src/ptr/non_null.rs)
rustc_parse: Stop returning `Option` from statement parsing `parse_stmt_without_recovery` had one corner case in which it returned `Ok(None)` - when parsing immediately encountered a closing brace `}`, possibly after parsing outer attributes. It is simpler to never call `parse_stmt_without_recovery` in such contexts than deal with a possibility of no statement being returned without an error. So this PR changes the function's return type from `PResult<'a, Option<Stmt>>` to `PResult<'a, Stmt>` and adjusts one call site to check for a closing brace.
…uwer Rollup of 28 pull requests Successful merges: - #159638 (bootstrap: Split the `Step` trait into multiple traits) - #159774 (rustc_trait_selection: fix trait solver hang caused by degenerate obligations) - #159837 (line-tables-only test: check that the line number matches the function name) - #159946 (Update Enzyme submodule to imporve llvm-cov) - #159962 (miri subtree update) - #156570 (tests: extend remap-path-prefix-std to all stdlib rlibs) - #159617 (Fix up `#[linkage]` target checking) - #159633 (Improve workings of attribute suggestions) - #159733 (std: Switch implementations of `thread_local!` for WASI) - #159783 (Check unsafe impls on safe EIIs) - #159810 (Add tuple never coercion collection regression test) - #159826 (Remove redundant `#[rustc_paren_sugar]` feature gate) - #159846 (Implement `str::copy_from_str`) - #159849 (rustc_parse: Stop returning `Option` from statement parsing) - #159853 (Updated expect messages for `CString` struct and method documentation) - #159875 (More cleanup in `rustc_attr_parsing`) - #159882 (Update expect messages in library/alloc/boxed.rs and library/alloc/string.rs to follow the style guide) - #159891 (Split multiline derives into std/rustc macros) - #159893 (Fix `find_attr` hygiene and `rustc_hir` cleanups) - #159895 (rustc-dev-guide subtree update) - #159902 (Clarify that the expected runtime symbols signature is for the current target only) - #159914 (Fix error in diagnostic on_unmatched_args) - #159917 (spare capacity mut constification) - #159918 (rename abort_unwind → abort_on_unwind) - #159927 (Remove sve2 from the ImpliedFeatures of AArch64 v9a.) - #159936 (Minor `rustc_ast::ast` doc cleanups) - #159945 (Update expect messages in library/core/src/ptr/non_null.rs) - #159950 (Add CFI tests for return types and never type)
parse_stmt_without_recoveryhad one corner case in which it returnedOk(None)- when parsing immediately encountered a closing brace}, possibly after parsing outer attributes.It is simpler to never call
parse_stmt_without_recoveryin such contexts than deal with a possibility of no statement being returned without an error.So this PR changes the function's return type from
PResult<'a, Option<Stmt>>toPResult<'a, Stmt>and adjusts one call site to check for a closing brace.