@@ -231,6 +231,24 @@ private Type inferAssignmentOperationType(AstNode n, TypePath path) {
231
231
result = TUnit ( )
232
232
}
233
233
234
+ pragma [ nomagic]
235
+ private Struct getRangeType ( RangeExpr re ) {
236
+ re instanceof RangeFromExpr and
237
+ result instanceof RangeFromStruct
238
+ or
239
+ re instanceof RangeToExpr and
240
+ result instanceof RangeToStruct
241
+ or
242
+ re instanceof RangeFromToExpr and
243
+ result instanceof RangeStruct
244
+ or
245
+ re instanceof RangeInclusiveExpr and
246
+ result instanceof RangeInclusiveStruct
247
+ or
248
+ re instanceof RangeToInclusiveExpr and
249
+ result instanceof RangeToInclusiveStruct
250
+ }
251
+
234
252
/**
235
253
* Holds if the type tree of `n1` at `prefix1` should be equal to the type tree
236
254
* of `n2` at `prefix2` and type information should propagate in both directions
@@ -300,22 +318,8 @@ private predicate typeEquality(AstNode n1, TypePath prefix1, AstNode n2, TypePat
300
318
exists ( Struct s |
301
319
n2 = [ n1 .( RangeExpr ) .getStart ( ) , n1 .( RangeExpr ) .getEnd ( ) ] and
302
320
prefix1 = TypePath:: singleton ( TTypeParamTypeParameter ( s .getGenericParamList ( ) .getATypeParam ( ) ) ) and
303
- prefix2 .isEmpty ( )
304
- |
305
- n1 instanceof RangeFromExpr and
306
- s instanceof RangeFromStruct
307
- or
308
- n1 instanceof RangeToExpr and
309
- s instanceof RangeToStruct
310
- or
311
- n1 instanceof RangeFromToExpr and
312
- s instanceof RangeStruct
313
- or
314
- n1 instanceof RangeInclusiveExpr and
315
- s instanceof RangeInclusiveStruct
316
- or
317
- n1 instanceof RangeToInclusiveExpr and
318
- s instanceof RangeToInclusiveStruct
321
+ prefix2 .isEmpty ( ) and
322
+ s = getRangeType ( n1 )
319
323
)
320
324
}
321
325
@@ -1123,24 +1127,7 @@ private Type inferArrayExprType(ArrayExpr ae) { exists(ae) and result = TArrayTy
1123
1127
* Gets the root type of the range expression `re`.
1124
1128
*/
1125
1129
pragma [ nomagic]
1126
- private Type inferRangeExprType ( RangeExpr re ) {
1127
- exists ( Struct s | result = TStruct ( s ) |
1128
- re instanceof RangeFromExpr and
1129
- s instanceof RangeFromStruct
1130
- or
1131
- re instanceof RangeToExpr and
1132
- s instanceof RangeToStruct
1133
- or
1134
- re instanceof RangeFromToExpr and
1135
- s instanceof RangeStruct
1136
- or
1137
- re instanceof RangeInclusiveExpr and
1138
- s instanceof RangeInclusiveStruct
1139
- or
1140
- re instanceof RangeToInclusiveExpr and
1141
- s instanceof RangeToInclusiveStruct
1142
- )
1143
- }
1130
+ private Type inferRangeExprType ( RangeExpr re ) { result = TStruct ( getRangeType ( re ) ) }
1144
1131
1145
1132
/**
1146
1133
* According to [the Rust reference][1]: _"array and slice-typed expressions
0 commit comments