@@ -772,45 +772,48 @@ private Type inferCallExprBaseType(AstNode n, TypePath path) {
772772 n = a .getNodeAt ( apos ) and
773773 result = CallExprBaseMatching:: inferAccessType ( a , apos , path0 )
774774 |
775- (
775+ if
776776 apos .isBorrowed ( true )
777777 or
778- // The desugaring of the unary `*e` is `*Deref::deref(&e)`. To handle the
779- // deref expression after the call we must strip a `&` from the type at
780- // the return position.
781- apos .isReturn ( ) and a instanceof DerefExpr
782- ) and
783- path0 .isCons ( TRefTypeParameter ( ) , path )
784- or
785- apos .isBorrowed ( false ) and
786- exists ( Type argType | argType = inferType ( n ) |
787- if argType = TRefType ( )
778+ // The desugaring of the unary `*e` is `*Deref::deref(&e)` and the
779+ // desugaring of `a[b]` is `*Index::index(&a, b)`. To handle the deref
780+ // expression after the call we must strip a `&` from the type at the
781+ // return position.
782+ apos .isReturn ( ) and
783+ ( a instanceof DerefExpr or a instanceof IndexExpr )
784+ then path0 .isCons ( TRefTypeParameter ( ) , path )
785+ else
786+ if apos .isBorrowed ( false )
788787 then
789- path = path0 and
790- path0 .isCons ( TRefTypeParameter ( ) , _)
791- or
792- // adjust for implicit deref
793- not path0 .isCons ( TRefTypeParameter ( ) , _) and
794- not ( path0 .isEmpty ( ) and result = TRefType ( ) ) and
795- path = TypePath:: cons ( TRefTypeParameter ( ) , path0 )
796- else (
797- not (
798- argType .( StructType ) .asItemNode ( ) instanceof StringStruct and
799- result .( StructType ) .asItemNode ( ) instanceof Builtins:: Str
800- ) and
801- (
802- not path0 .isCons ( TRefTypeParameter ( ) , _) and
803- not ( path0 .isEmpty ( ) and result = TRefType ( ) ) and
804- path = path0
805- or
806- // adjust for implicit borrow
807- path0 .isCons ( TRefTypeParameter ( ) , path )
788+ exists ( Type argType | argType = inferType ( n ) |
789+ if argType = TRefType ( )
790+ then
791+ path = path0 and
792+ path0 .isCons ( TRefTypeParameter ( ) , _)
793+ or
794+ // adjust for implicit deref
795+ not path0 .isCons ( TRefTypeParameter ( ) , _) and
796+ not ( path0 .isEmpty ( ) and result = TRefType ( ) ) and
797+ path = TypePath:: cons ( TRefTypeParameter ( ) , path0 )
798+ else (
799+ not (
800+ argType .( StructType ) .asItemNode ( ) instanceof StringStruct and
801+ result .( StructType ) .asItemNode ( ) instanceof Builtins:: Str
802+ ) and
803+ (
804+ not path0 .isCons ( TRefTypeParameter ( ) , _) and
805+ not ( path0 .isEmpty ( ) and result = TRefType ( ) ) and
806+ path = path0
807+ or
808+ // adjust for implicit borrow
809+ path0 .isCons ( TRefTypeParameter ( ) , path )
810+ )
811+ )
808812 )
813+ else (
814+ not apos .isBorrowed ( _) and
815+ path = path0
809816 )
810- )
811- or
812- not apos .isBorrowed ( _) and
813- path = path0
814817 )
815818}
816819
@@ -1046,8 +1049,8 @@ private class Vec extends Struct {
10461049 */
10471050pragma [ nomagic]
10481051private Type inferIndexExprType ( IndexExpr ie , TypePath path ) {
1049- // TODO: Should be implemented as method resolution, using the special
1050- // `std::ops:: Index` trait .
1052+ // TODO: Method resolution to the `std::ops::Index` trait can handle the
1053+ // `Index` instances for slices and arrays .
10511054 exists ( TypePath exprPath , Builtins:: BuiltinType t |
10521055 TStruct ( t ) = inferType ( ie .getIndex ( ) ) and
10531056 (
0 commit comments