- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
Match Ergonomics 2024: update edition 2024 behavior of feature gates #135434
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
          
     Merged
      
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            12 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      a56f9ad
              
                remove Rule 3 from `ref_pat_eat_one_layer_2024`
              
              
                dianne c57708a
              
                add more tests where the rulesets disagree
              
              
                dianne c037695
              
                "structural" ruleset: account for dbm mutability cap in Deref(EatInne…
              
              
                dianne f8315ae
              
                "structural" ruleset: use the "classic" ruleset's diagnostic and fall…
              
              
                dianne 586ff15
              
                "structural" ruleset: match against the inherited ref when a referenc…
              
              
                dianne 3f9b198
              
                rename tests' revisions to allow testing multiple editions
              
              
                dianne fdcbd71
              
                minor test cleanup
              
              
                dianne afd976b
              
                add more information to old tests
              
              
                dianne 4ed44c9
              
                add a stable edition 2021 revision to pattern typing tests
              
              
                dianne f5567e1
              
                organize old well-typed-edition-2024 tests
              
              
                dianne e288cff
              
                add tests differing between stable and new rules (with errors on new …
              
              
                dianne be7d6e3
              
                add work-in-progress unstable book chapters
              
              
                dianne File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
        
          
          
            19 changes: 19 additions & 0 deletions
          
          19 
        
  ...oc/unstable-book/src/language-features/ref-pat-eat-one-layer-2024-structural.md
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # `ref_pat_eat_one_layer_2024_structural` | ||
|  | ||
| The tracking issue for this feature is: [#123076] | ||
|  | ||
| [#123076]: https://github.com/rust-lang/rust/issues/123076 | ||
|  | ||
| --- | ||
|  | ||
| This feature is incomplete and not yet intended for general use. | ||
|  | ||
| This implements experimental, Edition-dependent match ergonomics under consideration for inclusion | ||
| in Rust. | ||
| For more information, see the corresponding typing rules for [Editions 2024 and later]. | ||
| On earlier Editions, the current behavior is unspecified. | ||
|  | ||
| For alternative experimental match ergonomics, see the feature | ||
| [`ref_pat_eat_one_layer_2024`](./ref-pat-eat-one-layer-2024.md). | ||
|  | ||
| [Editions 2024 and later]: https://nadrieril.github.io/typing-rust-patterns/?compare=false&opts1=AQEBAgEBAQEBAgIAAAAAAAAAAAAAAAA%3D&mode=rules&do_cmp=false | 
        
          
          
            19 changes: 19 additions & 0 deletions
          
          19 
        
  src/doc/unstable-book/src/language-features/ref-pat-eat-one-layer-2024.md
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # `ref_pat_eat_one_layer_2024` | ||
|  | ||
| The tracking issue for this feature is: [#123076] | ||
|  | ||
| [#123076]: https://github.com/rust-lang/rust/issues/123076 | ||
|  | ||
| --- | ||
|  | ||
| This feature is incomplete and not yet intended for general use. | ||
|  | ||
| This implements experimental, Edition-dependent match ergonomics under consideration for inclusion | ||
| in Rust. | ||
| For more information, see the corresponding typing rules for [Editions 2024 and later]. | ||
| On earlier Editions, the current behavior is unspecified. | ||
|  | ||
| For alternative experimental match ergonomics, see the feature | ||
| [`ref_pat_eat_one_layer_2024_structural`](./ref-pat-eat-one-layer-2024-structural.md). | ||
|  | ||
| [Editions 2024 and later]: https://nadrieril.github.io/typing-rust-patterns/?compare=false&opts1=AQEBAAABAQABAgIAAQEBAAEBAAABAAA%3D&mode=rules&do_cmp=false | 
        
          
          
            79 changes: 79 additions & 0 deletions
          
          79 
        
  ...ui/pattern/rfc-3627-match-ergonomics-2024/experimental/borrowck-errors.classic2024.stderr
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| error[E0508]: cannot move out of type `[&mut u32; 1]`, a non-copy array | ||
| --> $DIR/borrowck-errors.rs:13:16 | ||
| | | ||
| LL | let [&x] = &[&mut 0]; | ||
| | - ^^^^^^^^^ cannot move out of here | ||
| | | | ||
| | data moved here | ||
| | move occurs because `x` has type `&mut u32`, which does not implement the `Copy` trait | ||
| | | ||
| help: consider borrowing the pattern binding | ||
| | | ||
| LL | let [&ref x] = &[&mut 0]; | ||
| | +++ | ||
|  | ||
| error[E0508]: cannot move out of type `[&mut u32; 1]`, a non-copy array | ||
| --> $DIR/borrowck-errors.rs:19:16 | ||
| | | ||
| LL | let [&x] = &mut [&mut 0]; | ||
| | - ^^^^^^^^^^^^^ cannot move out of here | ||
| | | | ||
| | data moved here | ||
| | move occurs because `x` has type `&mut u32`, which does not implement the `Copy` trait | ||
| | | ||
| help: consider borrowing the pattern binding | ||
| | | ||
| LL | let [&ref x] = &mut [&mut 0]; | ||
| | +++ | ||
|  | ||
| error[E0507]: cannot move out of a shared reference | ||
| --> $DIR/borrowck-errors.rs:27:29 | ||
| | | ||
| LL | if let Some(&Some(x)) = Some(&Some(&mut 0)) { | ||
| | - ^^^^^^^^^^^^^^^^^^^ | ||
| | | | ||
| | data moved here | ||
| | move occurs because `x` has type `&mut u32`, which does not implement the `Copy` trait | ||
| | | ||
| help: consider removing the borrow | ||
| | | ||
| LL - if let Some(&Some(x)) = Some(&Some(&mut 0)) { | ||
| LL + if let Some(Some(x)) = Some(&Some(&mut 0)) { | ||
| | | ||
|  | ||
| error[E0596]: cannot borrow data in a `&` reference as mutable | ||
| --> $DIR/borrowck-errors.rs:32:10 | ||
| | | ||
| LL | let &ref mut x = &0; | ||
| | ^^^^^^^^^ cannot borrow as mutable | ||
|  | ||
| error[E0596]: cannot borrow data in a `&` reference as mutable | ||
| --> $DIR/borrowck-errors.rs:35:23 | ||
| | | ||
| LL | if let &Some(Some(x)) = &Some(&mut Some(0)) { | ||
| | ^ cannot borrow as mutable | ||
|  | ||
| error[E0596]: cannot borrow data in a `&` reference as mutable | ||
| --> $DIR/borrowck-errors.rs:40:11 | ||
| | | ||
| LL | let &[x] = &&mut [0]; | ||
| | ^ cannot borrow as mutable | ||
|  | ||
| error[E0508]: cannot move out of type `[&mut i32; 1]`, a non-copy array | ||
| --> $DIR/borrowck-errors.rs:44:20 | ||
| | | ||
| LL | let [&mut x] = &mut [&mut 0]; | ||
| | - ^^^^^^^^^^^^^ cannot move out of here | ||
| | | | ||
| | data moved here | ||
| | move occurs because `x` has type `&mut i32`, which does not implement the `Copy` trait | ||
| | | ||
| help: consider borrowing the pattern binding | ||
| | | ||
| LL | let [&mut ref x] = &mut [&mut 0]; | ||
| | +++ | ||
|  | ||
| error: aborting due to 7 previous errors | ||
|  | ||
| Some errors have detailed explanations: E0507, E0508, E0596. | ||
| For more information about an error, try `rustc --explain E0507`. | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
        
          
          
            69 changes: 69 additions & 0 deletions
          
          69 
        
  .../ui/pattern/rfc-3627-match-ergonomics-2024/experimental/borrowck-errors.stable2021.stderr
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| error[E0308]: mismatched types | ||
| --> $DIR/borrowck-errors.rs:13:10 | ||
| | | ||
| LL | let [&x] = &[&mut 0]; | ||
| | ^^ --------- this expression has type `&[&mut {integer}; 1]` | ||
| | | | ||
| | types differ in mutability | ||
| | | ||
| = note: expected mutable reference `&mut {integer}` | ||
| found reference `&_` | ||
| help: consider removing `&` from the pattern | ||
| | | ||
| LL - let [&x] = &[&mut 0]; | ||
| LL + let [x] = &[&mut 0]; | ||
| | | ||
|  | ||
| error[E0308]: mismatched types | ||
| --> $DIR/borrowck-errors.rs:19:10 | ||
| | | ||
| LL | let [&x] = &mut [&mut 0]; | ||
| | ^^ ------------- this expression has type `&mut [&mut {integer}; 1]` | ||
| | | | ||
| | types differ in mutability | ||
| | | ||
| = note: expected mutable reference `&mut {integer}` | ||
| found reference `&_` | ||
| help: consider removing `&` from the pattern | ||
| | | ||
| LL - let [&x] = &mut [&mut 0]; | ||
| LL + let [x] = &mut [&mut 0]; | ||
| | | ||
|  | ||
| error[E0507]: cannot move out of a shared reference | ||
| --> $DIR/borrowck-errors.rs:27:29 | ||
| | | ||
| LL | if let Some(&Some(x)) = Some(&Some(&mut 0)) { | ||
| | - ^^^^^^^^^^^^^^^^^^^ | ||
| | | | ||
| | data moved here | ||
| | move occurs because `x` has type `&mut u32`, which does not implement the `Copy` trait | ||
| | | ||
| help: consider removing the borrow | ||
| | | ||
| LL - if let Some(&Some(x)) = Some(&Some(&mut 0)) { | ||
| LL + if let Some(Some(x)) = Some(&Some(&mut 0)) { | ||
| | | ||
|  | ||
| error[E0596]: cannot borrow data in a `&` reference as mutable | ||
| --> $DIR/borrowck-errors.rs:32:10 | ||
| | | ||
| LL | let &ref mut x = &0; | ||
| | ^^^^^^^^^ cannot borrow as mutable | ||
|  | ||
| error[E0596]: cannot borrow data in a `&` reference as mutable | ||
| --> $DIR/borrowck-errors.rs:35:23 | ||
| | | ||
| LL | if let &Some(Some(x)) = &Some(&mut Some(0)) { | ||
| | ^ cannot borrow as mutable | ||
|  | ||
| error[E0596]: cannot borrow data in a `&` reference as mutable | ||
| --> $DIR/borrowck-errors.rs:40:11 | ||
| | | ||
| LL | let &[x] = &&mut [0]; | ||
| | ^ cannot borrow as mutable | ||
|  | ||
| error: aborting due to 6 previous errors | ||
|  | ||
| Some errors have detailed explanations: E0308, E0507, E0596. | ||
| For more information about an error, try `rustc --explain E0308`. | 
        
          
          
            25 changes: 0 additions & 25 deletions
          
          25 
        
  .../ui/pattern/rfc-3627-match-ergonomics-2024/experimental/borrowck-errors.structural.stderr
  
  
      
      
   
        
      
      
    This file was deleted.
      
      Oops, something went wrong.
      
    
  
      
      Oops, something went wrong.
        
    
  
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
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.
A diagnostics note: currently this means if falling back to matching on the inherited ref fails, the error will be about failing to match an inherited
&with a&mutpattern. I think it could use some rewording/explaining in general, but in particular if we adopt fallback-to-outer I think the message should also mention in some way that we first failed to match the inner&with the&mutpattern.This is also the case for the fallback-to-outer variant of the edition 2021 rules (not in this PR).
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 leave a
// FIXME(ref_pat_eat_one_layer_2024_structural): explain that there was fallback in the error message?