@@ -302,125 +302,6 @@ module LocalFlow {
302302 }
303303}
304304
305- /**
306- * Provides temporary modeling of built-in variants, for which no source code
307- * `Item`s are available.
308- *
309- * TODO: Remove once library code is extracted.
310- */
311- module VariantInLib {
312- private import codeql.util.Option
313-
314- private class CrateOrigin extends string {
315- CrateOrigin ( ) { this = any ( Resolvable r ) .getResolvedCrateOrigin ( ) }
316- }
317-
318- private class CrateOriginOption = Option< CrateOrigin > :: Option ;
319-
320- private CrateOriginOption langCoreCrate ( ) { result .asSome ( ) = "lang:core" }
321-
322- private newtype TVariantInLib =
323- MkVariantInLib ( CrateOriginOption crate , string path , string name ) {
324- crate = langCoreCrate ( ) and
325- (
326- path = "crate::option::Option" and
327- name = "Some"
328- or
329- path = "crate::result::Result" and
330- name = [ "Ok" , "Err" ]
331- )
332- }
333-
334- /** An enum variant from library code, represented by the enum's canonical path and the variant's name. */
335- class VariantInLib extends MkVariantInLib {
336- CrateOriginOption crate ;
337- string path ;
338- string name ;
339-
340- VariantInLib ( ) { this = MkVariantInLib ( crate , path , name ) }
341-
342- int getAPosition ( ) {
343- this = MkVariantInLib ( langCoreCrate ( ) , "crate::option::Option" , "Some" ) and
344- result = 0
345- or
346- this = MkVariantInLib ( langCoreCrate ( ) , "crate::result::Result" , [ "Ok" , "Err" ] ) and
347- result = 0
348- }
349-
350- string getExtendedCanonicalPath ( ) { result = path + "::" + name }
351-
352- string toString ( ) { result = name }
353- }
354-
355- /** A tuple variant from library code. */
356- class VariantInLibTupleFieldContent extends Content , TVariantInLibTupleFieldContent {
357- private VariantInLib:: VariantInLib v ;
358- private int pos_ ;
359-
360- VariantInLibTupleFieldContent ( ) { this = TVariantInLibTupleFieldContent ( v , pos_ ) }
361-
362- VariantInLib:: VariantInLib getVariantInLib ( int pos ) { result = v and pos = pos_ }
363-
364- string getExtendedCanonicalPath ( ) { result = v .getExtendedCanonicalPath ( ) }
365-
366- int getPosition ( ) { result = pos_ }
367-
368- final override string toString ( ) {
369- // only print indices when the arity is > 1
370- if exists ( TVariantInLibTupleFieldContent ( v , 1 ) )
371- then result = v .toString ( ) + "(" + pos_ + ")"
372- else result = v .toString ( )
373- }
374-
375- final override Location getLocation ( ) { result instanceof EmptyLocation }
376- }
377-
378- pragma [ nomagic]
379- private predicate resolveExtendedCanonicalPath ( Resolvable r , CrateOriginOption crate , string path ) {
380- path = r .getResolvedPath ( ) and
381- (
382- crate .asSome ( ) = r .getResolvedCrateOrigin ( )
383- or
384- crate .isNone ( ) and
385- not r .hasResolvedCrateOrigin ( )
386- )
387- }
388-
389- /** Holds if path `p` resolves to variant `v`. */
390- private predicate pathResolveToVariantInLib ( PathAstNode p , VariantInLib v ) {
391- exists ( CrateOriginOption crate , string path , string name |
392- resolveExtendedCanonicalPath ( p , pragma [ only_bind_into ] ( crate ) , path + "::" + name ) and
393- v = MkVariantInLib ( pragma [ only_bind_into ] ( crate ) , path , name )
394- )
395- }
396-
397- /** Holds if `p` destructs an enum variant `v`. */
398- pragma [ nomagic]
399- private predicate tupleVariantCanonicalDestruction ( TupleStructPat p , VariantInLib v ) {
400- pathResolveToVariantInLib ( p , v )
401- }
402-
403- bindingset [ pos]
404- predicate tupleVariantCanonicalDestruction (
405- TupleStructPat pat , VariantInLibTupleFieldContent c , int pos
406- ) {
407- tupleVariantCanonicalDestruction ( pat , c .getVariantInLib ( pos ) )
408- }
409-
410- /** Holds if `ce` constructs an enum value of type `v`. */
411- pragma [ nomagic]
412- private predicate tupleVariantCanonicalConstruction ( CallExpr ce , VariantInLib v ) {
413- pathResolveToVariantInLib ( ce .getFunction ( ) .( PathExpr ) , v )
414- }
415-
416- bindingset [ pos]
417- predicate tupleVariantCanonicalConstruction ( CallExpr ce , VariantInLibTupleFieldContent c , int pos ) {
418- tupleVariantCanonicalConstruction ( ce , c .getVariantInLib ( pos ) )
419- }
420- }
421-
422- class VariantInLibTupleFieldContent = VariantInLib:: VariantInLibTupleFieldContent ;
423-
424305class LambdaCallKind = Unit ;
425306
426307/** Holds if `creation` is an expression that creates a lambda of kind `kind`. */
@@ -486,6 +367,7 @@ module RustDataFlow implements InputSig<Location> {
486367 private import Aliases
487368 private import codeql.rust.dataflow.DataFlow
488369 private import Node as Node
370+ private import codeql.rust.frameworks.stdlib.Stdlib
489371
490372 /**
491373 * An element, viewed as a node in a data flow graph. Either an expression
@@ -671,11 +553,8 @@ module RustDataFlow implements InputSig<Location> {
671553 exists ( Content c | c = cs .( SingletonContentSet ) .getContent ( ) |
672554 exists ( TupleStructPatCfgNode pat , int pos |
673555 pat = node1 .asPat ( ) and
674- node2 .asPat ( ) = pat .getField ( pos )
675- |
556+ node2 .asPat ( ) = pat .getField ( pos ) and
676557 c = TTupleFieldContent ( pat .getTupleStructPat ( ) .getTupleField ( pos ) )
677- or
678- VariantInLib:: tupleVariantCanonicalDestruction ( pat .getPat ( ) , c , pos )
679558 )
680559 or
681560 exists ( TuplePatCfgNode pat , int pos |
@@ -720,8 +599,8 @@ module RustDataFlow implements InputSig<Location> {
720599 exists ( TryExprCfgNode try |
721600 node1 .asExpr ( ) = try .getExpr ( ) and
722601 node2 .asExpr ( ) = try and
723- c .( VariantInLibTupleFieldContent ) . getVariantInLib ( 0 ) . getExtendedCanonicalPath ( ) =
724- [ "crate::option::Option::Some" , "crate::result::Result::Ok" ]
602+ c .( TupleFieldContent )
603+ . isVariantField ( [ any ( OptionEnum o ) . getSome ( ) , any ( ResultEnum r ) . getOk ( ) ] , 0 )
725604 )
726605 or
727606 exists ( PrefixExprCfgNode deref |
@@ -797,11 +676,8 @@ module RustDataFlow implements InputSig<Location> {
797676 private predicate storeContentStep ( Node node1 , Content c , Node node2 ) {
798677 exists ( CallExprCfgNode call , int pos |
799678 node1 .asExpr ( ) = call .getArgument ( pragma [ only_bind_into ] ( pos ) ) and
800- node2 .asExpr ( ) = call
801- |
679+ node2 .asExpr ( ) = call and
802680 c = TTupleFieldContent ( call .getCallExpr ( ) .getTupleField ( pragma [ only_bind_into ] ( pos ) ) )
803- or
804- VariantInLib:: tupleVariantCanonicalConstruction ( call .getCallExpr ( ) , c , pos )
805681 )
806682 or
807683 exists ( StructExprCfgNode re , string field |
0 commit comments