- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
          Un-shadow object bound candidate in NormalizesTo goal if self_ty is trait object
          #148292
        
          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
base: master
Are you sure you want to change the base?
Conversation
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.
Trait objects always have their associated types specified so
candidateswon't be empty.
That comments exists to state why we never treat the alias as rigid in this case?
CAn you add something along the lines of
"This is somewhat inconsistent and may make #57893 slightly easier to exploit. However, it matches the behavior of the old solver"
as a comment
| @@ -0,0 +1,17 @@ | |||
| //@ compile-flags: -Znext-solver | |||
| //@ check-pass | |||
|  | |||
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.
pls add // Regression test for trait-system-refactor-initiative#whatever
| // See `tests/ui/winnowing/norm-where-bound-gt-alias-bound.rs`. | ||
| if candidates.iter().any(|c| matches!(c.source, CandidateSource::ParamEnv(_))) { | ||
| candidates.retain(|c| matches!(c.source, CandidateSource::ParamEnv(_))); | ||
| } else if matches!(goal.predicate.self_ty().kind(), ty::Dynamic(..)) { | 
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 think we should move this into assemble_and_evaluate_candidates as rn this doesn't handle cases where the self type is an alias, e.g. the following should still fail with ur PR
trait Trait {
    type Assoc;
}
trait Id {
    type This;
}
impl<T: ?Sized> Id for T {
    type This = T;
}
fn foo<T>(x: <dyn Trait<Assoc = T> as Trait>::Assoc) -> T
where
    <dyn Trait<Assoc = T> as Id>::This: Trait,
{
    x
}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.
This doesn't fail (after fixing ?Sized bound). And the Assoc projection's self_ty is not alias?
The trait goal in param env has alias self_ty but it's irrelevant for the NormalizesTo goal.
Besides, the following doesn't fail either. Perhaps the self_ty is normalized somehow?
trait Trait {
    type Assoc;
}
trait Id {
    type This: ?Sized;
}
impl<T: ?Sized> Id for T {
    type This = T;
}
fn foo<T>(x: <<dyn Trait<Assoc = T> as Id>::This as Trait>::Assoc) -> T
where
    <dyn Trait<Assoc = T> as Id>::This: Trait,
{
    x
}Nonetheless, I moved the code into assemble_and_evaluate_candidates and removed comments specific to NormalizesTo goal since trait goals also use this method.
| 
 Yes, just a reminder that we won't take the  | 
Fixes rust-lang/trait-system-refactor-initiative#244
r? lcnr