File tree Expand file tree Collapse file tree 2 files changed +180
-146
lines changed
rust/ql/lib/codeql/rust/internal Expand file tree Collapse file tree 2 files changed +180
-146
lines changed Original file line number Diff line number Diff line change @@ -186,7 +186,7 @@ class FunctionType extends TFunctionType {
186186 * For functions belonging to a `trait`, we use the type of the trait itself instead
187187 * of the implicit `Self` type parameter, as otherwise any type will match.
188188 *
189- * Calls will use `substituteLookupTraits` to map receiver types to the relevant
189+ * Calls should use `substituteLookupTraits` to map receiver types to the relevant
190190 * traits when matching.
191191 */
192192 Type getTypeAt ( TypePath path ) {
@@ -219,3 +219,25 @@ class FunctionType extends TFunctionType {
219219
220220 Location getLocation ( ) { result = this .getReportingNode ( ) .getLocation ( ) }
221221}
222+
223+ private Trait getALookupTrait ( Type t ) {
224+ result = t .( TypeParamTypeParameter ) .getTypeParam ( ) .( TypeParamItemNode ) .resolveABound ( )
225+ or
226+ result = t .( SelfTypeParameter ) .getTrait ( )
227+ or
228+ result = t .( ImplTraitType ) .getImplTraitTypeRepr ( ) .( ImplTraitTypeReprItemNode ) .resolveABound ( )
229+ or
230+ result = t .( DynTraitType ) .getTrait ( )
231+ }
232+
233+ /**
234+ * Gets the type obtained by substituting in relevant traits in which to do function
235+ * lookup, or `t` itself when no such trait exist.
236+ */
237+ bindingset [ t]
238+ Type substituteLookupTraits ( Type t ) {
239+ not exists ( getALookupTrait ( t ) ) and
240+ result = t
241+ or
242+ result = TTrait ( getALookupTrait ( t ) )
243+ }
You can’t perform that action at this time.
0 commit comments