- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
Fix invalid syntax and incomplete suggestion in impl Trait parameter type suggestions for E0311 #106167
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
      
      
    Conversation
  
    
      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
    
  
  
    
    | r? @nagisa (rustbot has picked a reviewer for you, use r? to override) | 
| r? rust-lang/compiler | 
| r? compiler | 
              
                    oli-obk
  
              
              requested changes
              
                  
                    Jan 9, 2023 
                  
              
              
            
            
ff8050b    to
    1463b22      
    Compare
  
    
              
                    oli-obk
  
              
              reviewed
              
                  
                    Jan 10, 2023 
                  
              
              
            
            
              
                    oli-obk
  
              
              reviewed
              
                  
                    Jan 10, 2023 
                  
              
              
            
            
1463b22    to
    1f106cc      
    Compare
  
    | @bors r+ rollup | 
| 📌 Commit 1f106cc86941acaa28165ad1ddd7b794935bebd6 has been approved by  It is now in the queue for this repository. | 
  This was referenced Jan 11, 2023 
      
1f106cc    to
    621d412      
    Compare
  
    
    
  Dylan-DPC 
      added a commit
        to Dylan-DPC/rust
      that referenced
      this pull request
    
      Jan 12, 2023 
    
    
      
  
    
      
    
  
…i-obk Fix invalid syntax and incomplete suggestion in impl Trait parameter type suggestions for E0311 Fixes rust-lang#105544 The problems: The suggestion given for E0311 has invalid syntax when the synthetic type parameter is used for Trait type in function declaration: ```rust fn foo(d: impl Sized) -> impl Sized ``` instead of explicitly specified like the following: ```rust fn foo<T: Sized>(d: T) -> impl Sized ``` In addition to the syntax error, the suggestions given for E0311 are not complete when multiple elided lifetimes are involved in lifetime bounds, not all involved parameters are given the named lifetime in the suggestions. For the following test case: ``` fn foo(d: impl Sized, p: &mut ()) -> impl Sized + '_ { (d, p) } ``` a good suggestion should add the lifetime 'a to both d and p, instead of d only: ``` fn foo<'a>(d: impl Sized + 'a, p: &'a mut ()) -> impl Sized + '_ { (d, p) } ``` The Solution: Fix the syntax problem in the suggestions when synthetic type parameter is used, and also add lifetimes for all involved parameters.
    
  bors 
      added a commit
        to rust-lang-ci/rust
      that referenced
      this pull request
    
      Jan 12, 2023 
    
    
      
  
    
      
    
  
…iaskrgr Rollup of 10 pull requests Successful merges: - rust-lang#106167 (Fix invalid syntax and incomplete suggestion in impl Trait parameter type suggestions for E0311) - rust-lang#106309 (Prefer non-`[type error]` candidates during selection) - rust-lang#106532 (Allow codegen to unsize `dyn*` to `dyn`) - rust-lang#106596 (Hide more of long types in E0271) - rust-lang#106638 (std tests: use __OsLocalKeyInner from realstd) - rust-lang#106676 (Test that we cannot use trait impl methods arguments as defining uses) - rust-lang#106702 (Conserve cause of `ImplDerivedObligation` in E0599) - rust-lang#106732 (rustc_llvm: replace llvm::makeArrayRef with ArrayRef constructors.) - rust-lang#106733 (Revert "warn newer available version of the x tool") - rust-lang#106748 (Clean up `OnUnimplementedFormatString::verify`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
      Labels
      
    S-waiting-on-bors
  Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 
  
    T-compiler
  Relevant to the compiler team, which will review and decide on the PR/issue. 
  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.
  
    
  
    
Fixes #105544
The problems: The suggestion given for E0311 has invalid syntax when the synthetic type parameter is used for Trait type in function declaration:
instead of explicitly specified like the following:
In addition to the syntax error, the suggestions given for E0311 are not complete when multiple elided lifetimes are involved in lifetime bounds, not all involved parameters are given the named lifetime in the suggestions. For the following test case:
a good suggestion should add the lifetime 'a to both d and p, instead of d only:
The Solution: Fix the syntax problem in the suggestions when synthetic type parameter is used, and also add lifetimes for all involved parameters.