Add section on type-relative name-resolution#2187
Add section on type-relative name-resolution#2187yaahc wants to merge 2 commits intorust-lang:masterfrom
Conversation
| - Types | ||
| - Expressions | ||
| - Patterns | ||
| - Structs & Tuple Structs |
There was a problem hiding this comment.
I think this might be mcga related except for where it overlaps w/ enums
| r[names.resolution.type-relative.stages] | ||
| These type relative paths are resolved separately in item definitions and in function bodies. | ||
|
|
||
| r[names.resolution.type-relative.stages.items] |
There was a problem hiding this comment.
there's a lot more complexity in the compiler than what I've represented here, but afaict everything else is tied to unstable syntax.
This section covers the stable logic in lower_type_relative_ty_path in rustc_hir_analysis.
| // or an inherent associated type (on unstable) | ||
| ``` | ||
|
|
||
| r[names.resolution.type-relative.stages.bodies] |
There was a problem hiding this comment.
This section represents the logic in resolve_fully_qualified_call. Still seems odd to me that variants are being resolved in this function given it's name but that seems to be whats happening in the code so /shrug.
| } | ||
| ``` | ||
|
|
||
| struct literals? |
There was a problem hiding this comment.
double check why I thought this may be a type relative case. My guess is it probably has to do with caller's of lower_qpath and I think this might reduce down to just enum literals for which stable syntax it actually covers. If so, merge this back into the enum section as a subsection.
2abea11 to
76a3139
Compare
| impl Trait for Foo {} | ||
|
|
||
| fn main() { | ||
| //<_>::inherent_func(); // ERROR: unable to get the assoc item |
There was a problem hiding this comment.
this is never considered because Self is an inference var and this method is an inherent method
|
|
||
| fn main() { | ||
| //<_>::inherent_func(); // ERROR: unable to get the assoc item | ||
| //<_>::trait_method(); // ERROR: chose trait method, unable to infer the self type |
There was a problem hiding this comment.
This is an error because candidate selection depends upon inference resolving Self. In this case Self is unconstrained so we have no candidates at all. The fact that we only have one trait_method candidate that would be considered here cannot flow backwards and help constrain the Self inference var.
| fn main() { | ||
| //<_>::inherent_func(); // ERROR: unable to get the assoc item | ||
| //<_>::trait_method(); // ERROR: chose trait method, unable to infer the self type | ||
| let _: Foo = <_>::trait_method(); // OK |
There was a problem hiding this comment.
Self is constrained by return type annotation, we consider trait methods and find a candidate.
Currently doing content reviews w/ other subject matter exports. Not yet ready for editorial review.