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