@@ -386,7 +386,7 @@ private predicate resolveExtendedCanonicalPath(Resolvable r, CrateOriginOption c
386
386
}
387
387
388
388
/**
389
- * A reference contained in an object. For example a field in a struct.
389
+ * A path to a value contained in an object. For example a field name of a struct.
390
390
*/
391
391
abstract class Content extends TContent {
392
392
/** Gets a textual representation of this content. */
@@ -416,34 +416,34 @@ private class VariantCanonicalPath extends MkVariantCanonicalPath {
416
416
abstract class VariantContent extends Content { }
417
417
418
418
/** A tuple variant. */
419
- private class TupleVariantContent extends VariantContent , TTupleVariantContent {
419
+ private class VariantPositionContent extends VariantContent , TVariantPositionContent {
420
420
private VariantCanonicalPath v ;
421
421
private int pos_ ;
422
422
423
- TupleVariantContent ( ) { this = TTupleVariantContent ( v , pos_ ) }
423
+ VariantPositionContent ( ) { this = TVariantPositionContent ( v , pos_ ) }
424
424
425
425
VariantCanonicalPath getVariantCanonicalPath ( int pos ) { result = v and pos = pos_ }
426
426
427
427
final override string toString ( ) {
428
428
// only print indices when the arity is > 1
429
- if exists ( TTupleVariantContent ( v , 1 ) )
429
+ if exists ( TVariantPositionContent ( v , 1 ) )
430
430
then result = v .toString ( ) + "(" + pos_ + ")"
431
431
else result = v .toString ( )
432
432
}
433
433
}
434
434
435
435
/** A record variant. */
436
- private class RecordVariantContent extends VariantContent , TRecordVariantContent {
436
+ private class VariantFieldContent extends VariantContent , TVariantFieldContent {
437
437
private VariantCanonicalPath v ;
438
438
private string field_ ;
439
439
440
- RecordVariantContent ( ) { this = TRecordVariantContent ( v , field_ ) }
440
+ VariantFieldContent ( ) { this = TVariantFieldContent ( v , field_ ) }
441
441
442
442
VariantCanonicalPath getVariantCanonicalPath ( string field ) { result = v and field = field_ }
443
443
444
444
final override string toString ( ) {
445
445
// only print field when the arity is > 1
446
- if strictcount ( string f | exists ( TRecordVariantContent ( v , f ) ) ) > 1
446
+ if strictcount ( string f | exists ( TVariantFieldContent ( v , f ) ) ) > 1
447
447
then result = v .toString ( ) + "{" + field_ + "}"
448
448
else result = v .toString ( )
449
449
}
@@ -461,7 +461,7 @@ abstract class ContentSet extends TContentSet {
461
461
abstract Content getAReadContent ( ) ;
462
462
}
463
463
464
- private class SingletonContentSet extends ContentSet , TSingletonContentSet {
464
+ final private class SingletonContentSet extends ContentSet , TSingletonContentSet {
465
465
private Content c ;
466
466
467
467
SingletonContentSet ( ) { this = TSingletonContentSet ( c ) }
@@ -539,21 +539,18 @@ module RustDataFlow implements InputSig<Location> {
539
539
final class ReturnKind = ReturnKindAlias ;
540
540
541
541
pragma [ nomagic]
542
- private predicate callResolveExtendedCanonicalPath (
543
- CallExprBase call , CrateOriginOption crate , string path
544
- ) {
545
- exists ( Resolvable r | resolveExtendedCanonicalPath ( r , crate , path ) |
546
- r = call .( MethodCallExpr )
547
- or
548
- r = call .( CallExpr ) .getExpr ( ) .( PathExpr ) .getPath ( )
549
- )
542
+ private Resolvable getCallResolvable ( CallExprBase call ) {
543
+ result = call .( MethodCallExpr )
544
+ or
545
+ result = call .( CallExpr ) .getExpr ( ) .( PathExpr ) .getPath ( )
550
546
}
551
547
552
548
/** Gets a viable implementation of the target of the given `Call`. */
553
549
DataFlowCallable viableCallable ( DataFlowCall call ) {
554
- exists ( string path , CrateOriginOption crate |
550
+ exists ( Resolvable r , string path , CrateOriginOption crate |
555
551
hasExtendedCanonicalPath ( result .asCfgScope ( ) , crate , path ) and
556
- callResolveExtendedCanonicalPath ( call .asCallBaseExprCfgNode ( ) .getExpr ( ) , crate , path )
552
+ r = getCallResolvable ( call .asCallBaseExprCfgNode ( ) .getExpr ( ) ) and
553
+ resolveExtendedCanonicalPath ( r , crate , path )
557
554
)
558
555
}
559
556
@@ -581,7 +578,7 @@ module RustDataFlow implements InputSig<Location> {
581
578
582
579
predicate forceHighPrecision ( Content c ) { none ( ) }
583
580
584
- final class ContentApprox = Content ; // todo
581
+ final class ContentApprox = Content ; // TODO: Implement if needed
585
582
586
583
ContentApprox getContentApprox ( Content c ) { result = c }
587
584
@@ -621,6 +618,10 @@ module RustDataFlow implements InputSig<Location> {
621
618
// TODO: Remove once library types are extracted
622
619
not p .hasQualifier ( ) and
623
620
v = MkVariantCanonicalPath ( _, "crate::std::option::Option" , p .getPart ( ) .getNameRef ( ) .getText ( ) )
621
+ or
622
+ // TODO: Remove once library types are extracted
623
+ not p .hasQualifier ( ) and
624
+ v = MkVariantCanonicalPath ( _, "crate::std::result::Result" , p .getPart ( ) .getNameRef ( ) .getText ( ) )
624
625
}
625
626
626
627
/** Holds if `p` destructs an enum variant `v`. */
@@ -642,22 +643,19 @@ module RustDataFlow implements InputSig<Location> {
642
643
*/
643
644
predicate readStep ( Node node1 , ContentSet cs , Node node2 ) {
644
645
exists ( Content c | c = cs .( SingletonContentSet ) .getContent ( ) |
645
- node1 .asPat ( ) =
646
- any ( TupleStructPatCfgNode pat , int pos |
647
- tupleVariantDestruction ( pat .getPat ( ) , c .( TupleVariantContent ) .getVariantCanonicalPath ( pos ) ) and
648
- node2 .asPat ( ) = pat .getField ( pos )
649
- |
650
- pat
651
- )
646
+ exists ( TupleStructPatCfgNode pat , int pos |
647
+ pat = node1 .asPat ( ) and
648
+ tupleVariantDestruction ( pat .getPat ( ) ,
649
+ c .( VariantPositionContent ) .getVariantCanonicalPath ( pos ) ) and
650
+ node2 .asPat ( ) = pat .getField ( pos )
651
+ )
652
652
or
653
- node1 .asPat ( ) =
654
- any ( RecordPatCfgNode pat , string field |
655
- recordVariantDestruction ( pat .getPat ( ) ,
656
- c .( RecordVariantContent ) .getVariantCanonicalPath ( field ) ) and
657
- node2 .asPat ( ) = pat .getFieldPat ( field )
658
- |
659
- pat
660
- )
653
+ exists ( RecordPatCfgNode pat , string field |
654
+ pat = node1 .asPat ( ) and
655
+ recordVariantDestruction ( pat .getPat ( ) ,
656
+ c .( VariantFieldContent ) .getVariantCanonicalPath ( field ) ) and
657
+ node2 .asPat ( ) = pat .getFieldPat ( field )
658
+ )
661
659
)
662
660
}
663
661
@@ -683,7 +681,7 @@ module RustDataFlow implements InputSig<Location> {
683
681
node2 .asExpr ( ) =
684
682
any ( CallExprCfgNode call , int pos |
685
683
tupleVariantConstruction ( call .getCallExpr ( ) ,
686
- c .( TupleVariantContent ) .getVariantCanonicalPath ( pos ) ) and
684
+ c .( VariantPositionContent ) .getVariantCanonicalPath ( pos ) ) and
687
685
node1 .asExpr ( ) = call .getArgument ( pos )
688
686
|
689
687
call
@@ -692,7 +690,7 @@ module RustDataFlow implements InputSig<Location> {
692
690
node2 .asExpr ( ) =
693
691
any ( RecordExprCfgNode re , string field |
694
692
recordVariantConstruction ( re .getRecordExpr ( ) ,
695
- c .( RecordVariantContent ) .getVariantCanonicalPath ( field ) ) and
693
+ c .( VariantFieldContent ) .getVariantCanonicalPath ( field ) ) and
696
694
node1 .asExpr ( ) = re .getFieldExpr ( field )
697
695
|
698
696
re
@@ -806,18 +804,27 @@ private module Cached {
806
804
crate .isNone ( ) and
807
805
path = "crate::std::option::Option" and
808
806
name = "Some"
807
+ or
808
+ // TODO: Remove once library types are extracted
809
+ crate .isNone ( ) and
810
+ path = "crate::std::result::Result" and
811
+ name = [ "Ok" , "Err" ]
809
812
}
810
813
811
814
cached
812
815
newtype TContent =
813
- TTupleVariantContent ( VariantCanonicalPath v , int pos ) {
816
+ TVariantPositionContent ( VariantCanonicalPath v , int pos ) {
814
817
pos in [ 0 .. v .getVariant ( ) .getFieldList ( ) .( TupleFieldList ) .getNumberOfFields ( ) - 1 ]
815
818
or
816
819
// TODO: Remove once library types are extracted
817
820
v = MkVariantCanonicalPath ( _, "crate::std::option::Option" , "Some" ) and
818
821
pos = 0
822
+ or
823
+ // TODO: Remove once library types are extracted
824
+ v = MkVariantCanonicalPath ( _, "crate::std::result::Result" , [ "Ok" , "Err" ] ) and
825
+ pos = 0
819
826
} or
820
- TRecordVariantContent ( VariantCanonicalPath v , string field ) {
827
+ TVariantFieldContent ( VariantCanonicalPath v , string field ) {
821
828
field = v .getVariant ( ) .getFieldList ( ) .( RecordFieldList ) .getAField ( ) .getName ( ) .getText ( )
822
829
}
823
830
0 commit comments