@@ -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,13 +352,42 @@ 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
354393 abstract class LetDeclaration extends AstNode {
@@ -395,6 +434,7 @@ private module Input3 implements InputSig3 {
395434 class Call extends FunctionCallMatchingInput:: Access {
396435 /** Gets the target of this call. */
397436 Callable getTargetCertain ( ) {
437+ none ( ) and
398438 exists ( ImplOrTraitItemNodeOption i , FunctionDeclaration f , Path p |
399439 result .isFunction ( i , f ) and
400440 p = CallExprImpl:: getFunctionPath ( this ) and
@@ -467,8 +507,8 @@ private module Input3 implements InputSig3 {
467507 }
468508
469509 Type inferTypeCertainSpecific ( AstNode n , TypePath path ) {
470- result = inferFunctionBodyType ( n , path )
471- or
510+ // result = inferFunctionBodyType(n, path)
511+ // or
472512 result = inferLiteralType ( n , path , true )
473513 or
474514 result = inferRefPatType ( n ) and
@@ -498,16 +538,14 @@ private module Input3 implements InputSig3 {
498538 path .isEmpty ( ) and
499539 result instanceof UnitType
500540 or
501- isPanicMacroCall ( n ) and
502- path .isEmpty ( ) and
503- result instanceof NeverType
504- or
505541 n instanceof ClosureExpr and
506542 path .isEmpty ( ) and
507543 result = closureRootType ( )
508544 }
509545
510546 predicate inferStepSymmetric ( AstNode n1 , TypePath prefix1 , AstNode n2 , TypePath prefix2 ) {
547+ // inferStepSymmetricCertain0(n1, prefix1, n2, prefix2)
548+ // or
511549 prefix1 .isEmpty ( ) and
512550 prefix2 .isEmpty ( ) and
513551 (
@@ -619,9 +657,17 @@ private module Input3 implements InputSig3 {
619657 or
620658 result = inferOperationType ( n , pos , path )
621659 )
660+ or
661+ result = inferFieldExprType ( n , path , true )
622662 }
623663
624664 Type inferTypeSpecific ( AstNode n , TypePath path ) {
665+ // result = inferTypeCertainSpecific0(n, path)
666+ // or
667+ isPanicMacroCall ( n ) and
668+ path .isEmpty ( ) and
669+ result instanceof UnknownType
670+ or
625671 result = inferAssignmentOperationType ( n , path )
626672 or
627673 exists ( FunctionPosition pos | pos .isReturn ( ) |
@@ -630,7 +676,7 @@ private module Input3 implements InputSig3 {
630676 result = inferOperationType ( n , pos , path )
631677 )
632678 or
633- result = inferFieldExprType ( n , path )
679+ result = inferFieldExprType ( n , path , false )
634680 or
635681 result = inferTryExprType ( n , path )
636682 or
@@ -666,7 +712,7 @@ module Consistency {
666712
667713 private Type inferTypeCertainAdj ( AstNode n , TypePath path ) {
668714 result = inferTypeCertain ( n , path ) and
669- not result = TNeverType ( )
715+ not result = TUnknownType ( )
670716 }
671717
672718 predicate nonUniqueCertainType ( AstNode n , TypePath path , Type t ) {
@@ -1127,17 +1173,14 @@ private module ContextTyping {
11271173 */
11281174bindingset [ path, type]
11291175private 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 ( )
1176+ path .isEmpty ( ) and
1177+ not validSelfType ( type )
1178+ or
1179+ exists ( TypeParameter tp |
1180+ complexSelfRoot ( _, tp ) and
1181+ path = TypePath:: singleton ( tp ) and
1182+ exists ( type )
1183+ )
11411184}
11421185
11431186private newtype TBorrowKind =
@@ -1606,7 +1649,6 @@ private module AssocFunctionResolution {
16061649 not this .hasReceiver ( ) and
16071650 exists ( TypePath strippedTypePath , Type strippedType |
16081651 strippedType = substituteLookupTraits ( this , this .getTypeAt ( selfPos , strippedTypePath ) ) and
1609- strippedType != TNeverType ( ) and
16101652 strippedType != TUnknownType ( )
16111653 |
16121654 nonBlanketLikeCandidate ( this , _, selfPos , _, _, strippedTypePath , strippedType )
@@ -1703,7 +1745,6 @@ private module AssocFunctionResolution {
17031745 FunctionPosition selfPos , DerefChain derefChain , BorrowKind borrow , TypePath path
17041746 ) {
17051747 result = this .getSelfTypeAt ( selfPos , derefChain , borrow , path ) and
1706- result != TNeverType ( ) and
17071748 result != TUnknownType ( )
17081749 }
17091750
@@ -2343,7 +2384,6 @@ private module AssocFunctionResolution {
23432384
23442385 Type getTypeAt ( TypePath path ) {
23452386 result = substituteLookupTraits ( afc , afc .getSelfTypeAtNoBorrow ( selfPos , derefChain , path ) ) and
2346- result != TNeverType ( ) and
23472387 result != TUnknownType ( )
23482388 }
23492389
@@ -3313,7 +3353,7 @@ private module FieldExprMatching = Matching<FieldExprMatchingInput>;
33133353 * the receiver of field expression call.
33143354 */
33153355pragma [ nomagic]
3316- private Type inferFieldExprType ( AstNode n , TypePath path ) {
3356+ private Type inferFieldExprType ( AstNode n , TypePath path , boolean topDown ) {
33173357 exists (
33183358 FieldExprMatchingInput:: Access a , FieldExprMatchingInput:: AccessPosition apos , TypePath path0
33193359 |
@@ -3322,6 +3362,7 @@ private Type inferFieldExprType(AstNode n, TypePath path) {
33223362 |
33233363 if apos .isSelf ( )
33243364 then
3365+ topDown = true and
33253366 exists ( Type receiverType | receiverType = inferType ( n ) |
33263367 if receiverType instanceof RefType
33273368 then
@@ -3331,7 +3372,9 @@ private Type inferFieldExprType(AstNode n, TypePath path) {
33313372 path = TypePath:: cons ( getRefTypeParameter ( _) , path0 )
33323373 else path = path0
33333374 )
3334- else path = path0
3375+ else (
3376+ topDown = false and path = path0
3377+ )
33353378 )
33363379}
33373380
@@ -3437,7 +3480,7 @@ private DynTraitTypeParameter getDynFutureOutputTypeParameter() {
34373480pragma [ nomagic]
34383481predicate isUnitBlockExpr ( BlockExpr be ) {
34393482 not be .getStmtList ( ) .hasTailExpr ( ) and
3440- not be = any ( Callable c ) .getBody ( ) and
3483+ // not be = any(Callable c).getBody() and
34413484 not be .hasLabel ( )
34423485}
34433486
0 commit comments