@@ -254,6 +254,10 @@ private TypeMention getTypeAnnotation(AstNode n) {
254254pragma [ nomagic]
255255private Type inferAnnotatedType ( AstNode n , TypePath path ) {
256256 result = getTypeAnnotation ( n ) .resolveTypeAt ( path )
257+ or
258+ // The shorthand self syntax (i.e., a self parameter without a type
259+ // annotation) is sugar for a self parameter with an annotation.
260+ result = inferShorthandSelfType ( n , path )
257261}
258262
259263/** Module for inferring certain type information. */
@@ -369,10 +373,7 @@ module CertainTypeInference {
369373 */
370374 pragma [ nomagic]
371375 Type inferCertainType ( AstNode n , TypePath path ) {
372- exists ( TypeMention tm |
373- tm = getTypeAnnotation ( n ) and
374- result = tm .resolveTypeAt ( path )
375- )
376+ result = inferAnnotatedType ( n , path )
376377 or
377378 result = inferCertainCallExprType ( n , path )
378379 or
@@ -608,7 +609,7 @@ private Type inferTypeEquality(AstNode n, TypePath path) {
608609 */
609610bindingset [ self, suffix, t]
610611pragma [ inline_late]
611- private Type getRefAdjustImplicitSelfType ( SelfParam self , TypePath suffix , Type t , TypePath path ) {
612+ private Type getRefAdjustShorthandSelfType ( SelfParam self , TypePath suffix , Type t , TypePath path ) {
612613 not self .hasTypeRepr ( ) and
613614 (
614615 if self .isRef ( )
@@ -632,13 +633,17 @@ private Type resolveImplSelfType(Impl i, TypePath path) {
632633 result = i .getSelfTy ( ) .( TypeMention ) .resolveTypeAt ( path )
633634}
634635
635- /** Gets the type at `path` of the implicitly typed `self` parameter. */
636+ /**
637+ * Gets the type at `path` of the parameter `self` which uses the [shorthand
638+ * syntax][1] which is sugar for an explicit annotation.
639+ *
640+ * [1]: https://doc.rust-lang.org/stable/reference/items/associated-items.html#r-associated.fn.method.self-pat-shorthands
641+ */
636642pragma [ nomagic]
637- private Type inferImplicitSelfType ( SelfParam self , TypePath path ) {
638- exists ( ImplOrTraitItemNode i , Function f , TypePath suffix , Type t |
639- f = i .getAnAssocItem ( ) and
640- self = f .getParamList ( ) .getSelfParam ( ) and
641- result = getRefAdjustImplicitSelfType ( self , suffix , t , path )
643+ private Type inferShorthandSelfType ( SelfParam self , TypePath path ) {
644+ exists ( ImplOrTraitItemNode i , TypePath suffix , Type t |
645+ self = i .getAnAssocItem ( ) .( Function ) .getParamList ( ) .getSelfParam ( ) and
646+ result = getRefAdjustShorthandSelfType ( self , suffix , t , path )
642647 |
643648 t = resolveImplSelfType ( i , suffix )
644649 or
@@ -926,11 +931,8 @@ private module CallExprBaseMatchingInput implements MatchingInputSig {
926931 or
927932 exists ( SelfParam self |
928933 self = pragma [ only_bind_into ] ( this .getParamList ( ) .getSelfParam ( ) ) and
929- dpos .isSelf ( )
930- |
934+ dpos .isSelf ( ) and
931935 result = inferAnnotatedType ( self , path ) // `self` parameter with type annotation
932- or
933- result = inferImplicitSelfType ( self , path ) // `self` parameter without type annotation
934936 )
935937 or
936938 // For associated functions, we may also need to match type arguments against
@@ -2420,14 +2422,10 @@ private module Cached {
24202422 else any ( )
24212423 ) and
24222424 (
2423- result = inferAnnotatedType ( n , path )
2424- or
24252425 result = inferAssignmentOperationType ( n , path )
24262426 or
24272427 result = inferTypeEquality ( n , path )
24282428 or
2429- result = inferImplicitSelfType ( n , path )
2430- or
24312429 result = inferStructExprType ( n , path )
24322430 or
24332431 result = inferPathExprType ( n , path )
@@ -2491,9 +2489,9 @@ private module Debug {
24912489 Input2:: conditionSatisfiesConstraint ( abs , condition , constraint )
24922490 }
24932491
2494- predicate debugInferImplicitSelfType ( SelfParam self , TypePath path , Type t ) {
2492+ predicate debugInferShorthandSelfType ( SelfParam self , TypePath path , Type t ) {
24952493 self = getRelevantLocatable ( ) and
2496- t = inferImplicitSelfType ( self , path )
2494+ t = inferShorthandSelfType ( self , path )
24972495 }
24982496
24992497 predicate debugInferCallExprBaseType ( AstNode n , TypePath path , Type t ) {
0 commit comments