-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Recover parentheses in range patterns #119397
Conversation
r? @TaKO8Ki (rustbot has picked a reviewer for you, use r? to override) |
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.
I'm pretty sure this needs .may_recover()
checks in some places not to regress code like:
macro_rules! m {
($pat:pat) => {};
(($l:literal)..) => {};
}
fn main() {
m!((0)..);
}
The code above now fails to compile or am I mistaken?
d9e140e
to
6b71d23
Compare
This comment has been minimized.
This comment has been minimized.
6b71d23
to
d114f47
Compare
r? fmease |
Co-authored-by: León Orell Valerian Liehr <[email protected]>
1ec28f8
to
04128be
Compare
Co-authored-by: León Orell Valerian Liehr <[email protected]>
04128be
to
9566efe
Compare
Co-authored-by: León Orell Valerian Liehr <[email protected]>
@rustbot ready |
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.
Thanks for applying my suggestions!
I've had a think about #119397 (comment) again and while that diagnostic (expected `)`, found `+`
) isn't ideal, you plan on fixing that soon anyway . Now, the latest version of your PR contains two ad hoc diagnostics (unexpected token: `(`
) which aren't ideal either.
So let's go back to bailing out early with ?
if we fail to parse bound
in parse_pat_range_end
and to expect
'ing )
instead of eat_noexpect
'ing to eliminate both occurrences of struct_span_err
.
After, that this PR is good to go! Sorry for taking a while to respond. I'm excited to see you improving the parse errors for patterns! ❤️
Co-authored-by: León Orell Valerian Liehr <[email protected]>
9566efe
to
4e0badd
Compare
@bors r+ rollup |
🌲 The tree is currently closed for pull requests below priority 100. This pull request will be tested once the tree is reopened. |
…=fmease Recover parentheses in range patterns Before: ```rs match n { (0).. => (), _ => () } ``` ``` error: expected one of `=>`, `if`, or `|`, found `..` --> src/lib.rs:3:12 | 3 | (0).. => (), | ^^ expected one of `=>`, `if`, or `|` ``` After: ``` error: range pattern bounds cannot have parentheses --> main.rs:3:5 | 3 | (0).. => (), | ^ ^ | help: remove these parentheses | 3 - (0).. => (), 3 + 0.. => (), | ``` This sets the groundwork for rust-lang#118625, which will extend the recovery to expressions like `(0 + 1)..` where users may tend to add parentheses to avoid dealing with precedence. --- `@rustbot` label +A-parser +A-patterns +A-diagnostics
…iaskrgr Rollup of 8 pull requests Successful merges: - rust-lang#119184 (Switch from using `//~ERROR` annotations with `--error-format` to `error-pattern`) - rust-lang#119325 (custom mir: make it clear what the return block is) - rust-lang#119391 (Use Result::flatten in catch_with_exit_code) - rust-lang#119397 (Recover parentheses in range patterns) - rust-lang#119414 (bootstrap: Move -Clto= setting from Rustc::run to rustc_cargo) - rust-lang#119417 (Uplift some miscellaneous coroutine-specific machinery into `check_closure`) - rust-lang#119527 (don't reexport atomic::ordering via rustc_data_structures, use std import) - rust-lang#119540 (Don't synthesize host effect args inside trait object types) r? `@ghost` `@rustbot` modify labels: rollup
…=fmease Recover parentheses in range patterns Before: ```rs match n { (0).. => (), _ => () } ``` ``` error: expected one of `=>`, `if`, or `|`, found `..` --> src/lib.rs:3:12 | 3 | (0).. => (), | ^^ expected one of `=>`, `if`, or `|` ``` After: ``` error: range pattern bounds cannot have parentheses --> main.rs:3:5 | 3 | (0).. => (), | ^ ^ | help: remove these parentheses | 3 - (0).. => (), 3 + 0.. => (), | ``` This sets the groundwork for rust-lang#118625, which will extend the recovery to expressions like `(0 + 1)..` where users may tend to add parentheses to avoid dealing with precedence. --- ``@rustbot`` label +A-parser +A-patterns +A-diagnostics
…mpiler-errors Rollup of 10 pull requests Successful merges: - rust-lang#118521 (Enable address sanitizer for MSVC targets using INFERASANLIBS linker flag) - rust-lang#119026 (std::net::bind using -1 for openbsd which in turn sets it to somaxconn.) - rust-lang#119195 (Make named_asm_labels lint not trigger on unicode and trigger on format args) - rust-lang#119204 (macro_rules: Less hacky heuristic for using `tt` metavariable spans) - rust-lang#119362 (Make `derive(Trait)` suggestion more accurate) - rust-lang#119397 (Recover parentheses in range patterns) - rust-lang#119414 (bootstrap: Move -Clto= setting from Rustc::run to rustc_cargo) - rust-lang#119417 (Uplift some miscellaneous coroutine-specific machinery into `check_closure`) - rust-lang#119540 (Don't synthesize host effect args inside trait object types) - rust-lang#119555 (Add codegen test for RVO on MaybeUninit) r? `@ghost` `@rustbot` modify labels: rollup
…mpiler-errors Rollup of 10 pull requests Successful merges: - rust-lang#118521 (Enable address sanitizer for MSVC targets using INFERASANLIBS linker flag) - rust-lang#119026 (std::net::bind using -1 for openbsd which in turn sets it to somaxconn.) - rust-lang#119195 (Make named_asm_labels lint not trigger on unicode and trigger on format args) - rust-lang#119204 (macro_rules: Less hacky heuristic for using `tt` metavariable spans) - rust-lang#119362 (Make `derive(Trait)` suggestion more accurate) - rust-lang#119397 (Recover parentheses in range patterns) - rust-lang#119414 (bootstrap: Move -Clto= setting from Rustc::run to rustc_cargo) - rust-lang#119417 (Uplift some miscellaneous coroutine-specific machinery into `check_closure`) - rust-lang#119540 (Don't synthesize host effect args inside trait object types) - rust-lang#119555 (Add codegen test for RVO on MaybeUninit) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 10 pull requests Successful merges: - rust-lang#118521 (Enable address sanitizer for MSVC targets using INFERASANLIBS linker flag) - rust-lang#119026 (std::net::bind using -1 for openbsd which in turn sets it to somaxconn.) - rust-lang#119195 (Make named_asm_labels lint not trigger on unicode and trigger on format args) - rust-lang#119204 (macro_rules: Less hacky heuristic for using `tt` metavariable spans) - rust-lang#119362 (Make `derive(Trait)` suggestion more accurate) - rust-lang#119397 (Recover parentheses in range patterns) - rust-lang#119417 (Uplift some miscellaneous coroutine-specific machinery into `check_closure`) - rust-lang#119539 (Fix typos) - rust-lang#119540 (Don't synthesize host effect args inside trait object types) - rust-lang#119555 (Add codegen test for RVO on MaybeUninit) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 10 pull requests Successful merges: - rust-lang#118521 (Enable address sanitizer for MSVC targets using INFERASANLIBS linker flag) - rust-lang#119026 (std::net::bind using -1 for openbsd which in turn sets it to somaxconn.) - rust-lang#119195 (Make named_asm_labels lint not trigger on unicode and trigger on format args) - rust-lang#119204 (macro_rules: Less hacky heuristic for using `tt` metavariable spans) - rust-lang#119362 (Make `derive(Trait)` suggestion more accurate) - rust-lang#119397 (Recover parentheses in range patterns) - rust-lang#119417 (Uplift some miscellaneous coroutine-specific machinery into `check_closure`) - rust-lang#119539 (Fix typos) - rust-lang#119540 (Don't synthesize host effect args inside trait object types) - rust-lang#119555 (Add codegen test for RVO on MaybeUninit) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 10 pull requests Successful merges: - rust-lang#118521 (Enable address sanitizer for MSVC targets using INFERASANLIBS linker flag) - rust-lang#119026 (std::net::bind using -1 for openbsd which in turn sets it to somaxconn.) - rust-lang#119195 (Make named_asm_labels lint not trigger on unicode and trigger on format args) - rust-lang#119204 (macro_rules: Less hacky heuristic for using `tt` metavariable spans) - rust-lang#119362 (Make `derive(Trait)` suggestion more accurate) - rust-lang#119397 (Recover parentheses in range patterns) - rust-lang#119417 (Uplift some miscellaneous coroutine-specific machinery into `check_closure`) - rust-lang#119539 (Fix typos) - rust-lang#119540 (Don't synthesize host effect args inside trait object types) - rust-lang#119555 (Add codegen test for RVO on MaybeUninit) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#119397 - ShE3py:pat-range-paren-recovery, r=fmease Recover parentheses in range patterns Before: ```rs match n { (0).. => (), _ => () } ``` ``` error: expected one of `=>`, `if`, or `|`, found `..` --> src/lib.rs:3:12 | 3 | (0).. => (), | ^^ expected one of `=>`, `if`, or `|` ``` After: ``` error: range pattern bounds cannot have parentheses --> main.rs:3:5 | 3 | (0).. => (), | ^ ^ | help: remove these parentheses | 3 - (0).. => (), 3 + 0.. => (), | ``` This sets the groundwork for rust-lang#118625, which will extend the recovery to expressions like `(0 + 1)..` where users may tend to add parentheses to avoid dealing with precedence. --- ```@rustbot``` label +A-parser +A-patterns +A-diagnostics
Before:
After:
This sets the groundwork for #118625, which will extend the recovery to expressions like
(0 + 1)..
where users may tend to add parentheses to avoid dealing with precedence.@rustbot label +A-parser +A-patterns +A-diagnostics