@@ -119,6 +119,15 @@ private ItemNode getAChildSuccessor(ItemNode item, string name, SuccessorKind ki
119119 if result .isPublic ( )
120120 then kind .isBoth ( )
121121 else kind .isInternal ( )
122+ or
123+ // `Self` has scoping rules similar to type parameters and can be considered
124+ // an implicit type parameter child of the introducing item.
125+ // - https://doc.rust-lang.org/stable/reference/paths.html#r-paths.qualifiers.type-self
126+ // - https://doc.rust-lang.org/stable/reference/names/scopes.html#r-names.scopes.self
127+ ( item instanceof TypeItemTypeItemNode or item instanceof ImplOrTraitItemNode ) and
128+ name = "Self" and
129+ kind .isInternal ( ) and
130+ result = item
122131}
123132
124133private module UseOption = Option< Use > ;
@@ -405,9 +414,6 @@ abstract class ItemNode extends Locatable {
405414 this instanceof SourceFile and
406415 builtin ( name , result )
407416 or
408- name = "Self" and
409- this = result .( ImplOrTraitItemNode ) .getAnItemInSelfScope ( )
410- or
411417 name = "crate" and
412418 this = result .( CrateItemNode ) .getASourceFile ( )
413419 )
@@ -718,26 +724,12 @@ class FunctionItemNode extends AssocItemNode, ParameterizableItemNode instanceof
718724}
719725
720726abstract class ImplOrTraitItemNode extends ItemNode {
721- /** Gets an item that may refer to this node using `Self`. */
722- pragma [ nomagic]
723- ItemNode getAnItemInSelfScope ( ) {
724- result = this
725- or
726- result .getImmediateParent ( ) = this
727- or
728- exists ( ItemNode mid |
729- mid = this .getAnItemInSelfScope ( ) and
730- result .getImmediateParent ( ) = mid and
731- not mid instanceof ImplOrTraitItemNode
732- )
733- }
734-
735727 /** Gets a `Self` path that refers to this item. */
736728 cached
737729 Path getASelfPath ( ) {
738730 Stages:: PathResolutionStage:: ref ( ) and
739731 isUnqualifiedSelfPath ( result ) and
740- result = this . getAnItemInSelfScope ( ) . getADescendant ( )
732+ this = unqualifiedPathLookup ( result , _ , _ )
741733 }
742734
743735 /** Gets an associated item belonging to this trait or `impl` block. */
@@ -1610,11 +1602,7 @@ private predicate unqualifiedPathLookup(ItemNode ancestor, string name, Namespac
16101602 // lookup in an outer scope, but only if the item is not declared in inner scope
16111603 exists ( ItemNode mid |
16121604 unqualifiedPathLookup ( mid , name , ns , encl ) and
1613- not declares ( mid , ns , name ) and
1614- not (
1615- name = "Self" and
1616- mid = any ( ImplOrTraitItemNode i ) .getAnItemInSelfScope ( )
1617- )
1605+ not declares ( mid , ns , name )
16181606 |
16191607 ancestor = getOuterScope ( mid )
16201608 or
0 commit comments