-
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
Resolve shorthand projections (T::A
-style associated type paths) based solely on type, instead of a Def
#22519
Comments
This also addresses the annoying behaviour that inside |
cc me |
…atsakis It is currently broken to use syntax such as `<T as Foo>::U::static_method()` where `<T as Foo>::U` is an associated type. I was able to fix this and simplify the parser a bit at the same time. This also fixes the corresponding issue with associated types (#22139), but that's somewhat irrelevant because #22519 is still open, so this syntax still causes an error in type checking. Similarly, although this fix applies to associated consts, #25046 forbids associated constants from using type parameters or `Self`, while #19559 means that associated types have to always have one of those two. Therefore, I think that you can't use an associated const from an associated type anyway.
Unless someone else has a serious head start, I'm going to take a crack at this. |
@quantheory Not that I know of. I couldn't implement this initially because @nikomatsakis hadn't merged #22172 and #22512 at the time. |
@eddyb That makes sense. What I've done so far is to separate out the resolution parts of I'm not entirely done with that step, though, since I still have some things in |
@quantheory You might end up moving this to |
I'm still trying to figure this out, but it is a bit slow and difficult. I figured that I'd document things here in case anyone had any bright ideas. Instead of inventing a The main difficulties are:
|
Triage: this ticket is deep in the weeds of compiler internals; I'm not sure if it's still relevant or not. |
Still is entirely relevant. |
Triage: not aware of changes, guessing like last time it's still relevant |
I am not sure which issue is the canonical one for @nikomatsakis So I was thinking about the lazy normalization approach and what you'd need to encode in the typesystem. To handle everything supported today, this would work:
But to extend this to take into account traits in scope (via fn foo() {
{
use std::ops::Deref;
<&i32>::Target::default();
}
} While However, there is something that might be even simpler to work with: an interned scope chain. struct TraitsInScope<'tcx> {
parent: &'tcx TraitsInScope<'tcx>,
traits: StableVec<DefId>,
} So then the (We have |
T::A
-style associated types based solely on type, instead of a Def
Implement consecutive shorthand projections (associated type paths) like `T::AssocA::AssocB` I'd like to resolve / get feedback on the `FIXME` concerning "`Identity<T::Assoc>::Assoc`". Then I'll polish up this PR and make it ready for a types FCP (i.e., tests, tests, tests). Addresses rust-lang#126360 (comment). CC rust-lang#22519 (arbitrary shorthand projections).
T::A
-style associated types based solely on type, instead of a DefT::A
-style associated type paths) based solely on type, instead of a Def
Right now
astconv::associated_path_def_to_ty
takes adef::TyParamProvenance
obtained from eitherdef::DefTyParam
ordef::DefSelfTy
.This information cannot be easily extracted from the type, and #22172 doesn't change that, which means
<T>::AssocTy
does not work at all (pretends to be ambiguous).We should be able to make progress after #22172 and #22512 both land, and I believe @nikomatsakis has a solution in mind for dealing with at least some cases.
After this is fixed, the
finish_resolving_def_to_ty
function introduced in #22172 can be split intodef_to_ty
andresolve_extra_associated_types
and its callers would only need the latter for<T>::A::B::C
, instead of providing a dummyDef
to the entire thing.The text was updated successfully, but these errors were encountered: