@@ -312,7 +312,7 @@ private module Input3 implements InputSig3 {
312312
313313 class Expr = Rust:: Expr ;
314314
315- class SwitchExpr extends Rust:: MatchExpr {
315+ class Switch extends Rust:: MatchExpr {
316316 Expr getExpr ( ) { result = this .getScrutinee ( ) }
317317
318318 Case getCase ( int index ) { result = this .getArm ( index ) }
@@ -321,7 +321,7 @@ private module Input3 implements InputSig3 {
321321 class Case extends Rust:: MatchArm {
322322 AstNode getAPattern ( ) { result = this .getPat ( ) }
323323
324- Expr getBody ( ) { result = this .getExpr ( ) }
324+ AstNode getBody ( ) { result = this .getExpr ( ) }
325325 }
326326
327327 class ConditionalExpr extends IfExpr {
@@ -430,7 +430,7 @@ private module Input3 implements InputSig3 {
430430 )
431431 }
432432
433- predicate certainTypeEqualityInput ( AstNode n1 , TypePath prefix1 , AstNode n2 , TypePath prefix2 ) {
433+ predicate inferStepSymmetricCertain ( AstNode n1 , TypePath prefix1 , AstNode n2 , TypePath prefix2 ) {
434434 n1 =
435435 any ( IdentPat ip |
436436 n2 = ip .getName ( ) and
@@ -459,7 +459,7 @@ private module Input3 implements InputSig3 {
459459 )
460460 }
461461
462- Type inferCertainTypeInput ( AstNode n , TypePath path ) {
462+ Type inferTypeCertainInput ( AstNode n , TypePath path ) {
463463 result = inferFunctionBodyType ( n , path )
464464 or
465465 result = inferLiteralType ( n , path , true )
@@ -500,15 +500,10 @@ private module Input3 implements InputSig3 {
500500 result = closureRootType ( )
501501 }
502502
503- predicate typeEqualityInput ( AstNode n1 , TypePath prefix1 , AstNode n2 , TypePath prefix2 ) {
503+ predicate inferStepSymmetric ( AstNode n1 , TypePath prefix1 , AstNode n2 , TypePath prefix2 ) {
504504 prefix1 .isEmpty ( ) and
505505 prefix2 .isEmpty ( ) and
506506 (
507- exists ( MatchExpr me |
508- n1 = me .getScrutinee ( ) and
509- n2 = me .getAnArm ( ) .getPat ( )
510- )
511- or
512507 n1 = n2 .( OrPat ) .getAPat ( )
513508 or
514509 n1 = n2 .( ParenPat ) .getPat ( )
@@ -572,7 +567,7 @@ private module Input3 implements InputSig3 {
572567 prefix2 .isEmpty ( )
573568 }
574569
575- predicate typeEqualityAsymmetricInput ( AstNode n1 , TypePath prefix1 , AstNode n2 , TypePath prefix2 ) {
570+ predicate inferStep ( AstNode n1 , TypePath prefix1 , AstNode n2 , TypePath prefix2 ) {
576571 // When `n2` is `*n1` propagate type information from a raw pointer type
577572 // parameter at `n1`. The other direction is handled in
578573 // `inferDereferencedExprPtrType`.
@@ -596,23 +591,21 @@ private module Input3 implements InputSig3 {
596591 *
597592 * [1]: https://doc.rust-lang.org/reference/type-coercions.html#r-coerce.least-upper-bound
598593 */
599- predicate parentChildType ( AstNode parent , AstNode child , TypePath prefix ) {
600- child = parent .( IfExpr ) .getABranch ( ) and
601- prefix .isEmpty ( )
602- or
603- parent = any ( MatchExpr me | child = me .getAnArm ( ) .getExpr ( ) ) and
604- prefix .isEmpty ( )
605- or
606- parent = any ( ArrayListExpr ale | child = ale .getAnExpr ( ) ) and
607- prefix = TypePath:: singleton ( getArrayTypeParameter ( ) )
608- or
609- bodyReturns ( parent , child ) and
610- prefix .isEmpty ( )
611- or
612- exists ( Struct s |
613- child = [ parent .( RangeExpr ) .getStart ( ) , parent .( RangeExpr ) .getEnd ( ) ] and
614- prefix = TypePath:: singleton ( TTypeParamTypeParameter ( s .getGenericParamList ( ) .getATypeParam ( ) ) ) and
615- s = getRangeType ( parent )
594+ predicate inferLubStep ( AstNode child , TypePath path1 , AstNode parent , TypePath prefix ) {
595+ path1 .isEmpty ( ) and
596+ (
597+ parent = any ( ArrayListExpr ale | child = ale .getAnExpr ( ) ) and
598+ prefix = TypePath:: singleton ( getArrayTypeParameter ( ) )
599+ or
600+ bodyReturns ( parent , child ) and
601+ prefix .isEmpty ( )
602+ or
603+ exists ( Struct s |
604+ child = [ parent .( RangeExpr ) .getStart ( ) , parent .( RangeExpr ) .getEnd ( ) ] and
605+ prefix =
606+ TypePath:: singleton ( TTypeParamTypeParameter ( s .getGenericParamList ( ) .getATypeParam ( ) ) ) and
607+ s = getRangeType ( parent )
608+ )
616609 )
617610 }
618611
@@ -652,14 +645,14 @@ import M3
652645module Consistency {
653646 import M2:: Consistency
654647
655- private Type inferCertainTypeAdj ( AstNode n , TypePath path ) {
656- result = CertainTypeInference :: inferCertainType ( n , path ) and
648+ private Type inferTypeCertainAdj ( AstNode n , TypePath path ) {
649+ result = inferTypeCertain ( n , path ) and
657650 not result = TNeverType ( )
658651 }
659652
660653 predicate nonUniqueCertainType ( AstNode n , TypePath path , Type t ) {
661- strictcount ( inferCertainTypeAdj ( n , path ) ) > 1 and
662- t = inferCertainTypeAdj ( n , path ) and
654+ strictcount ( inferTypeCertainAdj ( n , path ) ) > 1 and
655+ t = inferTypeCertainAdj ( n , path ) and
663656 // Suppress the inconsistency if `n` is a self parameter and the type
664657 // mention for the self type has multiple types for a path.
665658 not exists ( ImplItemNode impl , TypePath selfTypePath |
@@ -922,8 +915,8 @@ private predicate bodyReturns(Expr body, Expr e) {
922915 )
923916}
924917
925- private Type inferUnknownTypeFromAnnotation ( AstNode n , TypePath path ) {
926- inferType ( n , path ) = TUnknownType ( ) and
918+ pragma [ nomagic ]
919+ private Type inferUnknownTypeFromAnnotationCand ( AstNode n , TypePath path , TypePath prefix ) {
927920 // Normally, these are coercion sites, but in case a type is unknown we
928921 // allow for type information to flow from the type annotation.
929922 exists ( TypeMention tm | result = tm .getTypeAt ( path ) |
@@ -932,6 +925,14 @@ private Type inferUnknownTypeFromAnnotation(AstNode n, TypePath path) {
932925 tm = any ( ClosureExpr ce | n = ce .getBody ( ) ) .getRetType ( ) .getTypeRepr ( )
933926 or
934927 tm = getReturnTypeMention ( any ( Function f | n = f .getBody ( ) ) )
928+ ) and
929+ prefix = path .getAPrefix ( )
930+ }
931+
932+ private Type inferUnknownTypeFromAnnotation ( AstNode n , TypePath path ) {
933+ exists ( TypePath prefix |
934+ result = inferUnknownTypeFromAnnotationCand ( n , path , prefix ) and
935+ hasUnknownTypeAt ( n , prefix )
935936 )
936937}
937938
@@ -3019,7 +3020,7 @@ private module ConstructionMatchingInput implements MatchingInputSig {
30193020 or
30203021 exists ( TypePath suffix |
30213022 suffix .isCons ( TTypeParamTypeParameter ( apos .asTypeParam ( ) ) , path ) and
3022- result = CertainTypeInference :: inferCertainType ( this , suffix )
3023+ result = inferTypeCertain ( this , suffix )
30233024 )
30243025 }
30253026
@@ -3628,6 +3629,15 @@ private Type inferForLoopExprType(AstNode n, TypePath path) {
36283629 )
36293630}
36303631
3632+ pragma [ nomagic]
3633+ private Type inferClosureExprBodyTypeCand ( AstNode n , TypePath path , TypePath prefix ) {
3634+ exists ( ClosureExpr ce |
3635+ n = ce .getClosureBody ( ) and
3636+ result = inferType ( ce , closureReturnPath ( ) .appendInverse ( path ) ) and
3637+ prefix = path .getAPrefix ( )
3638+ )
3639+ }
3640+
36313641pragma [ nomagic]
36323642private Type inferClosureExprType ( AstNode n , TypePath path ) {
36333643 exists ( ClosureExpr ce |
@@ -3650,6 +3660,11 @@ private Type inferClosureExprType(AstNode n, TypePath path) {
36503660 path .isEmpty ( )
36513661 )
36523662 )
3663+ or
3664+ exists ( TypePath prefix |
3665+ result = inferClosureExprBodyTypeCand ( n , path , prefix ) and
3666+ hasUnknownTypeAt ( n , prefix )
3667+ )
36533668}
36543669
36553670pragma [ nomagic]
@@ -3716,7 +3731,7 @@ private module Debug {
37163731 exists ( string filepath , int startline , int startcolumn , int endline , int endcolumn |
37173732 result .getLocation ( ) .hasLocationInfo ( filepath , startline , startcolumn , endline , endcolumn ) and
37183733 filepath .matches ( "%/main.rs" ) and
3719- startline = 103
3734+ startline = 1102
37203735 )
37213736 }
37223737
@@ -3756,11 +3771,10 @@ private module Debug {
37563771 tm .getTypeAt ( path ) = type
37573772 }
37583773
3759- Type debugInferAnnotatedType ( AstNode n , TypePath path ) {
3760- n = getRelevantLocatable ( ) and
3761- result = CertainTypeInference:: inferAnnotatedType ( n , path )
3762- }
3763-
3774+ // Type debugInferAnnotatedType(AstNode n, TypePath path) {
3775+ // n = getRelevantLocatable() and
3776+ // result = inferAnnotatedType(n, path)
3777+ // }
37643778 pragma [ nomagic]
37653779 private int countTypesAtPath ( AstNode n , TypePath path , Type t ) {
37663780 t = inferType ( n , path ) and
@@ -3809,9 +3823,9 @@ private module Debug {
38093823 c = max ( countTypePaths ( _, _, _) )
38103824 }
38113825
3812- Type debugInferCertainType ( AstNode n , TypePath path ) {
3826+ Type debuginferTypeCertain ( AstNode n , TypePath path ) {
38133827 n = getRelevantLocatable ( ) and
3814- result = CertainTypeInference :: inferCertainType ( n , path )
3828+ result = inferTypeCertain ( n , path )
38153829 }
38163830
38173831 Type debugInferCertainNonUniqueType ( AstNode n , TypePath path ) {
0 commit comments