@@ -1538,7 +1538,7 @@ private module MethodResolution {
15381538 pragma [ nomagic]
15391539 Type getACandidateReceiverTypeAtNoBorrow ( DerefChain derefChain , TypePath path ) {
15401540 result = this .getReceiverTypeAt ( path ) and
1541- derefChain = ""
1541+ derefChain . isEmpty ( )
15421542 or
15431543 exists ( DerefImplItemNode impl , DerefChain suffix |
15441544 result = ImplicitDeref:: getDereferencedCandidateReceiverType ( this , impl , suffix , path ) and
@@ -1647,7 +1647,7 @@ private module MethodResolution {
16471647 or
16481648 // needed for the `hasNoCompatibleTarget` check in
16491649 // `ReceiverSatisfiesBlanketLikeConstraintInput::hasBlanketCandidate`
1650- derefChain = ""
1650+ derefChain . isEmpty ( )
16511651 ) and
16521652 strippedType = this .getComplexStrippedType ( derefChain , TNoBorrowKind ( ) , strippedTypePath ) and
16531653 n = - 1
@@ -1680,7 +1680,7 @@ private module MethodResolution {
16801680 or
16811681 // needed for the `hasNoCompatibleTarget` check in
16821682 // `ReceiverSatisfiesBlanketLikeConstraintInput::hasBlanketCandidate`
1683- derefChain = ""
1683+ derefChain . isEmpty ( )
16841684 ) and
16851685 strippedType = this .getComplexStrippedType ( derefChain , TNoBorrowKind ( ) , strippedTypePath ) and
16861686 n = - 1
@@ -1830,7 +1830,7 @@ private module MethodResolution {
18301830 * as long as the method cannot be resolved in an earlier candidate type, and possibly
18311831 * applying a borrow at the end.
18321832 *
1833- * The string `derefChain` encodes the sequence of dereferences, and `borrows` indicates
1833+ * The parameter `derefChain` encodes the sequence of dereferences, and `borrows` indicates
18341834 * whether a borrow has been applied.
18351835 *
18361836 * [1]: https://doc.rust-lang.org/reference/expressions/method-call-expr.html#r-expr.method.candidate-receivers
@@ -1865,8 +1865,8 @@ private module MethodResolution {
18651865
18661866 /**
18671867 * Gets a method that this call resolves to after having applied a sequence of
1868- * dereferences and possibly a borrow on the receiver type, encoded in the string
1869- * `derefChain` and the enum `borrow`.
1868+ * dereferences and possibly a borrow on the receiver type, encoded in `derefChain`
1869+ * and `borrow`.
18701870 */
18711871 pragma [ nomagic]
18721872 Method resolveCallTarget ( ImplOrTraitItemNode i , DerefChain derefChain , BorrowKind borrow ) {
@@ -1881,9 +1881,7 @@ private module MethodResolution {
18811881 * and borrowed according to `derefChain` and `borrow`, in order to be able to
18821882 * resolve the call target.
18831883 */
1884- predicate argumentHasImplicitDerefChainBorrow (
1885- AstNode arg , DerefChain derefChain , BorrowKind borrow
1886- ) {
1884+ predicate argumentHasImplicitDerefChainBorrow ( Expr arg , DerefChain derefChain , BorrowKind borrow ) {
18871885 exists ( this .resolveCallTarget ( _, derefChain , borrow ) ) and
18881886 arg = this .getArg ( any ( ArgumentPosition pos | pos .isSelf ( ) ) ) and
18891887 not ( derefChain .isEmpty ( ) and borrow .isNoBorrow ( ) )
@@ -2025,7 +2023,7 @@ private module MethodResolution {
20252023 }
20262024
20272025 override predicate argumentHasImplicitDerefChainBorrow (
2028- AstNode arg , DerefChain derefChain , BorrowKind borrow
2026+ Expr arg , DerefChain derefChain , BorrowKind borrow
20292027 ) {
20302028 exists ( ArgumentPosition pos , boolean isMutable |
20312029 this .implicitBorrowAt ( pos , isMutable ) and
@@ -2161,7 +2159,7 @@ private module MethodResolution {
21612159 MkMethodCallDerefCand ( MethodCall mc , DerefChain derefChain ) {
21622160 mc .supportsAutoDerefAndBorrow ( ) and
21632161 mc .hasNoCompatibleTargetMutBorrow ( derefChain ) and
2164- exists ( mc .getACandidateReceiverTypeAtNoBorrow ( derefChain , _ ) )
2162+ exists ( mc .getACandidateReceiverTypeAtNoBorrow ( derefChain , TypePath :: nil ( ) ) )
21652163 }
21662164
21672165 /** A method call with a dereference chain. */
@@ -2579,6 +2577,13 @@ private Type inferMethodCallTypeNonSelf(AstNode n, boolean isReturn, TypePath pa
25792577 )
25802578}
25812579
2580+ /**
2581+ * Gets the type of `n` at `path` after applying `derefChain` and `borrow`,
2582+ * where `n` is the `self` argument of a method call.
2583+ *
2584+ * The predicate recursively pops the head of `derefChain` until it becomes
2585+ * empty, at which point the inferred type can be applied back to `n`.
2586+ */
25822587pragma [ nomagic]
25832588private Type inferMethodCallTypeSelf (
25842589 AstNode n , DerefChain derefChain , BorrowKind borrow , TypePath path
@@ -2604,14 +2609,14 @@ private Type inferMethodCallTypeSelf(
26042609 t0 = inferMethodCallTypeSelf ( n , derefChain0 , borrow , path0 ) and
26052610 derefChain0 .isCons ( impl , derefChain ) and
26062611 borrow .isNoBorrow ( ) and
2607- selfParamType = impl .resolveSelfParamTypeStrippedAt ( selfPath )
2612+ selfParamType = impl .resolveSelfTypeAt ( selfPath )
26082613 |
26092614 result = selfParamType and
26102615 path = selfPath and
26112616 not result instanceof TypeParameter
26122617 or
26132618 exists ( TypeParameter tp , TypePath pathToTypeParam , TypePath suffix |
2614- impl .returnTypeStrippedMentionsTypeParameterAt ( tp , pathToTypeParam ) and
2619+ impl .targetTypeParameterAt ( tp , pathToTypeParam ) and
26152620 path0 = pathToTypeParam .appendInverse ( suffix ) and
26162621 result = t0 and
26172622 path = selfPath .append ( suffix )
@@ -3911,13 +3916,13 @@ cached
39113916private module Cached {
39123917 /** Holds if `n` is implicitly dereferenced and/or borrowed. */
39133918 cached
3914- predicate implicitDerefChainBorrow ( AstNode n , DerefChain derefChain , boolean borrow ) {
3919+ predicate implicitDerefChainBorrow ( Expr e , DerefChain derefChain , boolean borrow ) {
39153920 exists ( BorrowKind bk |
3916- any ( MethodResolution:: MethodCall mc ) .argumentHasImplicitDerefChainBorrow ( n , derefChain , bk ) and
3921+ any ( MethodResolution:: MethodCall mc ) .argumentHasImplicitDerefChainBorrow ( e , derefChain , bk ) and
39173922 if bk .isNoBorrow ( ) then borrow = false else borrow = true
39183923 )
39193924 or
3920- n =
3925+ e =
39213926 any ( FieldExpr fe |
39223927 exists ( resolveStructFieldExpr ( fe , derefChain ) )
39233928 or
0 commit comments