-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
better errors when resolving bad Self in impl block #93971
better errors when resolving bad Self in impl block #93971
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
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 really convinced by this implementation. If having Self
in the type reference is illegal, we should report it right away.
Could we use a new RibKind::InImplBlockType
binding Self
to Res::Err
, and have validate_res_from_ribs
emit the error in the resolver.
this.with_self_rib(Res::SelfTy(None, None), |this| { | ||
// FIXME(compiler-errors): `Self` may still exist in the value namespace, | ||
// so we might be able to resolve an outer `Self` in, e.g., a const generic default. | ||
this.with_no_self_type(|this| { |
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.
Why is this required? IIUC, current_self_type
is only used for diagnostics.
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.
it's probably not useful in that case.
pub struct ResImpl { | ||
pub def_id: DefId, | ||
pub generics_allowed: bool, | ||
pub in_trait_ref: 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'm not sure I understand where this flag is used.
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.
We specifically need to deny this:
impl Trait<Self::A> for () {}
But we should not deny this:
impl Trait<Self> for () {}
So we use this flag during astconv to catch cases (like the former) where we have an associated type with a Self
in the path, which without this flag would try to elaborate the supertraits of the trait ref, looking for one with the associated type.
Since resolving the trait ref would itself require resolving an associated type in the trait ref, we get a cycle error.
@cjgillot: I could try this! Do you think that splitting out all of the combinations of Still not sure if this fixes the cycle error with a associated type on @rustbot author |
I'd personally close this and close #93952 as well as not an issue. |
☔ The latest upstream changes (presumably #93938) made this pull request unmergeable. Please resolve the merge conflicts. |
Welp, don't think I'll get around to fixing this. I may re-attempt this with that rib idea suggested above later. |
impl Self
by resolving an impl's self type outside of its own scope.impl Tr<Self::A> for Ty {}
by distinguishing when we're resolving an impl's trait ref, and marking any associated types in that trait ref as ambiguous.Fixes #93952