@@ -78,9 +78,33 @@ private import codeql.rust.elements.internal.PathResolution
7878/** Holds if `p` may resolve to multiple items including `i`. */
7979query predicate multiplePathResolutions ( Path p , ItemNode i ) {
8080 i = resolvePath ( p ) and
81+ // `use foo::bar` may use both a type `bar` and a value `bar`
82+ not p =
83+ any ( UseTree use |
84+ not use .isGlob ( ) and
85+ not use .hasUseTreeList ( )
86+ ) .getPath ( ) and
8187 strictcount ( resolvePath ( p ) ) > 1
8288}
8389
90+ /** Holds if `call` has multiple static call targets including `target`. */
91+ query predicate multipleStaticCallTargets ( CallExprBase call , Callable target ) {
92+ target = call .getStaticTarget ( ) and
93+ strictcount ( call .getStaticTarget ( ) ) > 1
94+ }
95+
96+ /** Holds if `fe` resolves to multiple record fields including `field`. */
97+ query predicate multipleRecordFields ( FieldExpr fe , RecordField field ) {
98+ field = fe .getRecordField ( ) and
99+ strictcount ( fe .getRecordField ( ) ) > 1
100+ }
101+
102+ /** Holds if `fe` resolves to multiple tuple fields including `field`. */
103+ query predicate multipleTupleFields ( FieldExpr fe , TupleField field ) {
104+ field = fe .getTupleField ( ) and
105+ strictcount ( fe .getTupleField ( ) ) > 1
106+ }
107+
84108/**
85109 * Gets counts of abstract syntax tree inconsistencies of each type.
86110 */
@@ -109,4 +133,13 @@ int getAstInconsistencyCounts(string type) {
109133 or
110134 type = "Multiple path resolutions" and
111135 result = count ( Path p | multiplePathResolutions ( p , _) | p )
136+ or
137+ type = "Multiple static call targets" and
138+ result = count ( CallExprBase call | multipleStaticCallTargets ( call , _) | call )
139+ or
140+ type = "Multiple record fields" and
141+ result = count ( FieldExpr fe | multipleRecordFields ( fe , _) | fe )
142+ or
143+ type = "Multiple tuple fields" and
144+ result = count ( FieldExpr fe | multipleTupleFields ( fe , _) | fe )
112145}
0 commit comments