- 
                Notifications
    
You must be signed in to change notification settings  - Fork 13.9k
 
Improve unconstrained impl diagnostic (fixes #107295) #126026
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
Improve unconstrained impl diagnostic (fixes #107295) #126026
Conversation
| 
           Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @wesleywiser (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label ( 
  | 
    
7394b00    to
    437083a      
    Compare
  
    
      
        
              This comment has been minimized.
        
        
      
    
  This comment has been minimized.
437083a    to
    e0f14e4      
    Compare
  
    | 
           r? types  | 
    
| is_impl_trait: bool, | ||
| is_bound_to_projection: bool, | ||
| is_bound_to_circular_projection: bool, | 
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 read the rest of your impl, this is just drive-by commentary.
Could please turn these bools into custom enums? And merge these three flags as much as possible unless they are already mutually exclusive?
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.
Yep 👍 is_impl_trait is orthogonal to the other two booleans, but is_bound_to_projection and is_bound_to_circular_projection can be merged
e0f14e4    to
    ba52ede      
    Compare
  
    | let mentioned_params = cgp::parameters_for(tcx, projection.term().skip_binder(), true); | ||
| let is_clause_circular = | ||
| Some(projection.required_poly_trait_ref(tcx).skip_binder()) == impl_trait_ref; | 
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.
Almost forgot, but wanted to add a quick note/question regarding skip_binder here... from what I understand, binders correspond to things like for<'a>, and skip_binder is generally a bad idea since it just unwraps the binder wo/ updating references to the quantifier.
My Q: is this specific usage safe? Or is some else more appropriate? (My understanding of this is a bit hazy 🙂)
| 
           ☔ The latest upstream changes (presumably #120639) made this pull request unmergeable. Please resolve the merge conflicts.  | 
    
| 
           @LlewVallis if you can resolve the conflicts, we can push this forward for a review. Thanks  | 
    
| 
           Hey 👋 I'm short on time lately, so might leave this for someone else to pick up  | 
    
Fixes #107295
Problem
When a type/lifetime/const generic param is unconstrained (as defined by the rules in this RFC) the current diagnostic isn't very helpful - it just tells you the param wasn't constrained. It isn't obvious (without having read the RFC) what can be done to make the param constrained.
Solution
We add some additional notes to the existing diagnostic:
I added a few UI tests which probably explain these messages better than I have here :)
After looking at the RFC I linked, AFAICT there are no more edge cases where the dot points above could be incorrect, but I'm not an expert, so please correct me if there are.
Also as a side note - the
enforce_impl_params_are_constrainedfunction is getting a bit long, lmk if you want me to split it up.