Skip to content
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 from if (let ...) in parsing, instead of lowering #83407

Closed
wants to merge 2 commits into from

Commits on Mar 27, 2021

  1. Recover from if (let ...) in parsing, instead of lowering

    When we recover from `if (let ...)` in lowering we can't "ungate" the
    syntax after generating the error
    
        invalid parentheses around `let` expression in `if let`
    
    as the feature_gate::check_crate pass has already run. This is mentioned
    in these comments in the old code
    
    > Ideally, we'd remove the feature gating of a `let` expression since we
    > are already complaining about it here, but `feature_gate::check_crate`
    > has already run by now
    
    We now recover from `if (let ...)` in parsing, generate the error as
    before, and "ungate" the syntax. For example, in this code:
    
        fn main() {
            let x = Some(3);
            if (let Some(y) = x) {}
        }
    
    We would previously generate:
    
        error[E0658]: `let` expressions in this position are experimental
         --> test.rs:3:9
          |
        3 |     if (let Some(y) = x) {}
          |         ^^^^^^^^^^^^^^^
          |
          = note: see issue rust-lang#53667 <rust-lang#53667> for more information
          = help: add `#![feature(let_chains)]` to the crate attributes to enable
          = help: you can write `matches!(<expr>, <pattern>)` instead of `let <pattern> = <expr>`
    
        error: invalid parentheses around `let` expression in `if let`
         --> test.rs:3:8
          |
        3 |     if (let Some(y) = x) {}
          |        ^               ^
          |
        help: `if let` needs to be written without parentheses
          |
        3 |     if let Some(y) = x {}
          |       --             --
    
        error: aborting due to 2 previous errors
    
    The first error doesn't make sense. With the "ungating" we now generate
    just the second one:
    
        error: invalid parentheses around `let` expression in `if let`
         --> test.rs:3:8
          |
        3 |     if (let Some(y) = x) {}
          |        ^               ^
          |
        help: `if let` needs to be written without parentheses
          |
        3 |     if let Some(y) = x {}
          |       --             --
    
        error: aborting due to previous error
    
    Fixes rust-lang#83274
    osa1 committed Mar 27, 2021
    Copy the full SHA
    d23e0ed View commit details
    Browse the repository at this point in the history
  2. Copy the full SHA
    57363f4 View commit details
    Browse the repository at this point in the history