@@ -1237,6 +1237,10 @@ private predicate implSiblingCandidate(
1237
1237
Impl impl , TraitItemNode trait , Type rootType , TypeMention selfTy
1238
1238
) {
1239
1239
trait = impl .( ImplItemNode ) .resolveTraitTy ( ) and
1240
+ // If `impl` has an expansion from a macro attribute, then it's been
1241
+ // superseded by the output of the expansion (and usually the expansion
1242
+ // contains the same `impl` block so considering both would give spurious
1243
+ // siblings).
1240
1244
not exists ( impl .getAttributeMacroExpansion ( ) ) and
1241
1245
// We use this for resolving methods, so exclude traits that do not have methods.
1242
1246
exists ( Function f | f = trait .getASuccessor ( _) and f .getParamList ( ) .hasSelfParam ( ) ) and
@@ -1296,12 +1300,13 @@ private predicate methodTypeAtPath(Function f, int pos, TypePath path, Type type
1296
1300
}
1297
1301
1298
1302
/**
1299
- * Holds if resolving the method in `impl` with the name `methodName` requires
1300
- * inspecting the types of applied _arguments_ in order to determine whether it
1301
- * is the correct resolution.
1303
+ * Holds if resolving the method `f` in `impl` with the name `methodName`
1304
+ * requires inspecting the types of applied _arguments_ in order to determine
1305
+ * whether it is the correct resolution.
1302
1306
*/
1307
+ pragma [ nomagic]
1303
1308
private predicate methodResolutionDependsOnArgument (
1304
- Impl impl , string methodName , int pos , TypePath path , Type type
1309
+ Impl impl , string methodName , Function f , int pos , TypePath path , Type type
1305
1310
) {
1306
1311
/*
1307
1312
* As seen in the example below, when an implementation has a sibling for a
@@ -1317,8 +1322,8 @@ private predicate methodResolutionDependsOnArgument(
1317
1322
* // ^ `path` = "T"
1318
1323
* }
1319
1324
* impl MyAdd<i64> for i64 {
1320
- * fn method(&self, value: i64) -> Self { ... }
1321
- * // ^^^ `type` = i64
1325
+ * fn method(&self, value: Foo< i64> ) -> Self { ... }
1326
+ * // ^^^ `type` = i64
1322
1327
* }
1323
1328
* ```
1324
1329
*
@@ -1331,7 +1336,8 @@ private predicate methodResolutionDependsOnArgument(
1331
1336
exists ( TraitItemNode trait |
1332
1337
implHasSibling ( impl , trait ) and
1333
1338
traitTypeParameterOccurrence ( trait , methodName , pos , path ) and
1334
- methodTypeAtPath ( getMethodSuccessor ( impl , methodName ) , pos , path , type )
1339
+ methodTypeAtPath ( getMethodSuccessor ( impl , methodName ) , pos , path , type ) and
1340
+ f = getMethodSuccessor ( impl , methodName )
1335
1341
)
1336
1342
}
1337
1343
@@ -1341,10 +1347,11 @@ private Function getMethodFromImpl(MethodCall mc) {
1341
1347
IsInstantiationOf< MethodCall , IsInstantiationOfInput > :: isInstantiationOf ( mc , impl , _) and
1342
1348
result = getMethodSuccessor ( impl , mc .getMethodName ( ) )
1343
1349
|
1344
- not methodResolutionDependsOnArgument ( impl , _, _, _, _)
1350
+ not methodResolutionDependsOnArgument ( impl , _, _, _, _, _) and
1351
+ result = getMethodSuccessor ( impl , mc .getMethodName ( ) )
1345
1352
or
1346
1353
exists ( int pos , TypePath path , Type type |
1347
- methodResolutionDependsOnArgument ( impl , mc .getMethodName ( ) , pos , path , type ) and
1354
+ methodResolutionDependsOnArgument ( impl , mc .getMethodName ( ) , result , pos , path , type ) and
1348
1355
inferType ( mc .getArgument ( pos ) , path ) = type
1349
1356
)
1350
1357
)
0 commit comments