- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
suggestion for attempted integer identifier in patterns #106591
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
      
      
    
      
        
          +99
        
        
          −4
        
        
          
        
      
    
  
  
     Merged
                    Changes from all commits
      Commits
    
    
  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
    
  
  
    
              
  
    
      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
    
  
  
    
              
  
    
      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
    
  
  
    
              
  
    
      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
    
  
  
    
              
  
    
      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
    
  
  
    
              
  
    
      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
    
  
  
    
              
  
    
      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,7 @@ | ||
| fn main() { | ||
| let 5 = 6; | ||
| //~^ error refutable pattern in local binding [E0005] | ||
|  | ||
| let x @ 5 = 6; | ||
| //~^ error refutable pattern in local binding [E0005] | ||
| } | 
  
    
      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,35 @@ | ||
| error[E0005]: refutable pattern in local binding | ||
| --> $DIR/issue-106552.rs:2:9 | ||
| | | ||
| LL | let 5 = 6; | ||
| | ^ patterns `i32::MIN..=4_i32` and `6_i32..=i32::MAX` not covered | ||
| | | ||
| = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant | ||
| = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html | ||
| = note: the matched value is of type `i32` | ||
| help: you might want to use `if let` to ignore the variants that aren't matched | ||
| | | ||
| LL | if let 5 = 6 { todo!() } | ||
| | ++ ~~~~~~~~~~~ | ||
| help: alternatively, you could prepend the pattern with an underscore to define a new named variable; identifiers cannot begin with digits | ||
| | | ||
| LL | let _5 = 6; | ||
| | + | ||
|  | ||
| error[E0005]: refutable pattern in local binding | ||
| --> $DIR/issue-106552.rs:5:9 | ||
| | | ||
| LL | let x @ 5 = 6; | ||
| | ^^^^^ patterns `i32::MIN..=4_i32` and `6_i32..=i32::MAX` not covered | ||
| | | ||
| = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant | ||
| = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html | ||
| = note: the matched value is of type `i32` | ||
| help: you might want to use `let else` to handle the variants that aren't matched | ||
| | | ||
| LL | let x @ 5 = 6 else { todo!() }; | ||
| | ++++++++++++++++ | ||
|  | ||
| error: aborting due to 2 previous errors | ||
|  | ||
| For more information about this error, try `rustc --explain E0005`. | ||
  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.
Looking at this with fresh eyes, shouldn't we be suggesting
if lethere? 🤔Uh oh!
There was an error while loading. Please reload this page.
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 haven't touched the
if letandelsesuggestion code, so I haven't really looked at this but: My understanding is that this situation is a bit like an alternative if let. You can bind the value, and if it doesn't match, the else branch is called (which must diverge).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 not asking you to fix it now necessarily, just leaving a paper trail of my thinking so we don't forget to fix it in the future :)