@@ -272,7 +272,7 @@ import M2
272272private module Input3 implements InputSig3 {
273273 private import rust as Rust
274274
275- predicate cachedStageRevRef ( ) {
275+ predicate cacheRevRef ( ) {
276276 Stages:: TypeInferenceStage:: ref ( )
277277 or
278278 ( implicitDerefChainBorrow ( _, _, _) implies any ( ) )
@@ -306,6 +306,16 @@ private module Input3 implements InputSig3 {
306306 )
307307 or
308308 result = n .( ShorthandSelfParameterMention )
309+ or
310+ exists ( Static static |
311+ n = static and
312+ result = static .getTypeRepr ( )
313+ )
314+ or
315+ exists ( Const c |
316+ n = c and
317+ result = c .getTypeRepr ( )
318+ )
309319 }
310320
311321 class Expr = Rust:: Expr ;
@@ -342,32 +352,61 @@ private module Input3 implements InputSig3 {
342352
343353 class ParenExpr = Rust:: ParenExpr ;
344354
345- class Variable extends Rust:: Variable {
355+ private newtype TLocalVariable =
356+ TVariableVariable ( Rust:: Variable v ) or
357+ TConstVariable ( Const c ) or
358+ TStaticVariable ( Static s )
359+
360+ class LocalVariable extends TLocalVariable {
361+ Rust:: Variable asVariable ( ) { this = TVariableVariable ( result ) }
362+
363+ Const asConst ( ) { this = TConstVariable ( result ) }
364+
365+ Static asStatic ( ) { this = TStaticVariable ( result ) }
366+
346367 AstNode getDefiningNode ( ) {
347- result = this .getPat ( ) .getName ( ) or
348- result = this .getParameter ( ) .( SelfParam )
368+ result = this .asVariable ( ) .getPat ( ) .getName ( ) or
369+ result = this .asVariable ( ) .getParameter ( ) .( SelfParam ) or
370+ result = this .asConst ( ) or
371+ result = this .asStatic ( )
372+ }
373+
374+ Expr getAnAccess ( ) {
375+ result = this .asVariable ( ) .getAnAccess ( )
376+ or
377+ result = this .asConst ( ) .getAnAccess ( )
378+ or
379+ result = this .asStatic ( ) .getAnAccess ( )
380+ }
381+
382+ string toString ( ) {
383+ result = this .asVariable ( ) .toString ( )
384+ or
385+ result = this .asConst ( ) .toString ( )
386+ or
387+ result = this .asStatic ( ) .toString ( )
349388 }
350389
351- Expr getAnAccess ( ) { result = super . getAnAccess ( ) }
390+ Location getLocation ( ) { result = this . getDefiningNode ( ) . getLocation ( ) }
352391 }
353392
354- abstract class LetDeclaration extends AstNode {
393+ abstract class LocalVariableDeclaration extends AstNode {
355394 abstract predicate isCoercionSite ( ) ;
356395
357396 abstract AstNode getLeftOperand ( ) ;
358397
359398 abstract AstNode getRightOperand ( ) ;
360399 }
361400
362- private class LetExprLetDeclaration extends LetDeclaration , LetExpr {
401+ private class LetExprDeclaration extends LocalVariableDeclaration , LetExpr {
363402 override predicate isCoercionSite ( ) { not this .getPat ( ) instanceof IdentPat }
364403
365404 override AstNode getLeftOperand ( ) { result = this .getPat ( ) }
366405
367406 override AstNode getRightOperand ( ) { result = this .getScrutinee ( ) }
368407 }
369408
370- private class LetStmtLetDeclaration extends LetDeclaration , LetStmt {
409+ private class LetStmtDeclaration extends LocalVariableDeclaration , LetStmt {
371410 override predicate isCoercionSite ( ) {
372411 this .hasTypeRepr ( ) or
373412 not identLetStmt ( this , _, _)
@@ -393,16 +432,6 @@ private module Input3 implements InputSig3 {
393432 }
394433
395434 class Call extends FunctionCallMatchingInput:: Access {
396- /** Gets the target of this call. */
397- Callable getTargetCertain ( ) {
398- exists ( ImplOrTraitItemNodeOption i , FunctionDeclaration f , Path p |
399- result .isFunction ( i , f ) and
400- p = CallExprImpl:: getFunctionPath ( this ) and
401- f = resolvePath ( p ) and
402- f .isDirectlyFor ( i )
403- )
404- }
405-
406435 Callable getTarget ( string derefChainBorrow ) { result = super .getTarget ( derefChainBorrow ) }
407436 }
408437
@@ -467,8 +496,6 @@ private module Input3 implements InputSig3 {
467496 }
468497
469498 Type inferTypeCertainSpecific ( AstNode n , TypePath path ) {
470- result = inferFunctionBodyType ( n , path )
471- or
472499 result = inferLiteralType ( n , path , true )
473500 or
474501 result = inferRefPatType ( n ) and
@@ -498,16 +525,14 @@ private module Input3 implements InputSig3 {
498525 path .isEmpty ( ) and
499526 result instanceof UnitType
500527 or
501- isPanicMacroCall ( n ) and
502- path .isEmpty ( ) and
503- result instanceof NeverType
504- or
505528 n instanceof ClosureExpr and
506529 path .isEmpty ( ) and
507530 result = closureRootType ( )
508531 }
509532
510533 predicate inferStepSymmetric ( AstNode n1 , TypePath prefix1 , AstNode n2 , TypePath prefix2 ) {
534+ // inferStepSymmetricCertain0(n1, prefix1, n2, prefix2)
535+ // or
511536 prefix1 .isEmpty ( ) and
512537 prefix2 .isEmpty ( ) and
513538 (
@@ -619,9 +644,17 @@ private module Input3 implements InputSig3 {
619644 or
620645 result = inferOperationType ( n , pos , path )
621646 )
647+ or
648+ result = inferFieldExprType ( n , path , true )
622649 }
623650
624651 Type inferTypeSpecific ( AstNode n , TypePath path ) {
652+ // result = inferTypeCertainSpecific0(n, path)
653+ // or
654+ isPanicMacroCall ( n ) and
655+ path .isEmpty ( ) and
656+ result instanceof UnknownType
657+ or
625658 result = inferAssignmentOperationType ( n , path )
626659 or
627660 exists ( FunctionPosition pos | pos .isReturn ( ) |
@@ -630,7 +663,7 @@ private module Input3 implements InputSig3 {
630663 result = inferOperationType ( n , pos , path )
631664 )
632665 or
633- result = inferFieldExprType ( n , path )
666+ result = inferFieldExprType ( n , path , false )
634667 or
635668 result = inferTryExprType ( n , path )
636669 or
@@ -666,7 +699,7 @@ module Consistency {
666699
667700 private Type inferTypeCertainAdj ( AstNode n , TypePath path ) {
668701 result = inferTypeCertain ( n , path ) and
669- not result = TNeverType ( )
702+ not result = TUnknownType ( )
670703 }
671704
672705 predicate nonUniqueCertainType ( AstNode n , TypePath path , Type t ) {
@@ -834,17 +867,6 @@ private Type getCallExprTypeArgument(CallExpr ce, TypeArgumentPosition apos, Typ
834867 )
835868}
836869
837- pragma [ nomagic]
838- private Type inferFunctionBodyType ( AstNode n , TypePath path ) {
839- exists ( Function f |
840- n = f .getFunctionBody ( ) and
841- result = getReturnTypeMention ( f ) .getTypeAt ( path ) and
842- not exists ( ImplTraitReturnType i | i .getFunction ( ) = f |
843- result = i or result = i .getATypeParameter ( )
844- )
845- )
846- }
847-
848870/**
849871 * Holds if `me` is a call to the `panic!` macro.
850872 *
@@ -1127,17 +1149,14 @@ private module ContextTyping {
11271149 */
11281150bindingset [ path, type]
11291151private predicate isComplexRootStripped ( TypePath path , Type type ) {
1130- (
1131- path .isEmpty ( ) and
1132- not validSelfType ( type )
1133- or
1134- exists ( TypeParameter tp |
1135- complexSelfRoot ( _, tp ) and
1136- path = TypePath:: singleton ( tp ) and
1137- exists ( type )
1138- )
1139- ) and
1140- type != TNeverType ( )
1152+ path .isEmpty ( ) and
1153+ not validSelfType ( type )
1154+ or
1155+ exists ( TypeParameter tp |
1156+ complexSelfRoot ( _, tp ) and
1157+ path = TypePath:: singleton ( tp ) and
1158+ exists ( type )
1159+ )
11411160}
11421161
11431162private newtype TBorrowKind =
@@ -1606,7 +1625,6 @@ private module AssocFunctionResolution {
16061625 not this .hasReceiver ( ) and
16071626 exists ( TypePath strippedTypePath , Type strippedType |
16081627 strippedType = substituteLookupTraits ( this , this .getTypeAt ( selfPos , strippedTypePath ) ) and
1609- strippedType != TNeverType ( ) and
16101628 strippedType != TUnknownType ( )
16111629 |
16121630 nonBlanketLikeCandidate ( this , _, selfPos , _, _, strippedTypePath , strippedType )
@@ -1703,7 +1721,6 @@ private module AssocFunctionResolution {
17031721 FunctionPosition selfPos , DerefChain derefChain , BorrowKind borrow , TypePath path
17041722 ) {
17051723 result = this .getSelfTypeAt ( selfPos , derefChain , borrow , path ) and
1706- result != TNeverType ( ) and
17071724 result != TUnknownType ( )
17081725 }
17091726
@@ -2343,7 +2360,6 @@ private module AssocFunctionResolution {
23432360
23442361 Type getTypeAt ( TypePath path ) {
23452362 result = substituteLookupTraits ( afc , afc .getSelfTypeAtNoBorrow ( selfPos , derefChain , path ) ) and
2346- result != TNeverType ( ) and
23472363 result != TUnknownType ( )
23482364 }
23492365
@@ -3313,7 +3329,7 @@ private module FieldExprMatching = Matching<FieldExprMatchingInput>;
33133329 * the receiver of field expression call.
33143330 */
33153331pragma [ nomagic]
3316- private Type inferFieldExprType ( AstNode n , TypePath path ) {
3332+ private Type inferFieldExprType ( AstNode n , TypePath path , boolean topDown ) {
33173333 exists (
33183334 FieldExprMatchingInput:: Access a , FieldExprMatchingInput:: AccessPosition apos , TypePath path0
33193335 |
@@ -3322,6 +3338,7 @@ private Type inferFieldExprType(AstNode n, TypePath path) {
33223338 |
33233339 if apos .isSelf ( )
33243340 then
3341+ topDown = true and
33253342 exists ( Type receiverType | receiverType = inferType ( n ) |
33263343 if receiverType instanceof RefType
33273344 then
@@ -3331,7 +3348,9 @@ private Type inferFieldExprType(AstNode n, TypePath path) {
33313348 path = TypePath:: cons ( getRefTypeParameter ( _) , path0 )
33323349 else path = path0
33333350 )
3334- else path = path0
3351+ else (
3352+ topDown = false and path = path0
3353+ )
33353354 )
33363355}
33373356
@@ -3437,7 +3456,10 @@ private DynTraitTypeParameter getDynFutureOutputTypeParameter() {
34373456pragma [ nomagic]
34383457predicate isUnitBlockExpr ( BlockExpr be ) {
34393458 not be .getStmtList ( ) .hasTailExpr ( ) and
3440- not be = any ( Callable c ) .getBody ( ) and
3459+ not exists ( Callable c |
3460+ be = c .getBody ( ) and
3461+ c = any ( ReturnExpr re ) .getEnclosingCallable ( )
3462+ ) and
34413463 not be .hasLabel ( )
34423464}
34433465
0 commit comments