@@ -296,125 +296,6 @@ module LocalFlow {
296
296
}
297
297
}
298
298
299
- /**
300
- * Provides temporary modeling of built-in variants, for which no source code
301
- * `Item`s are available.
302
- *
303
- * TODO: Remove once library code is extracted.
304
- */
305
- module VariantInLib {
306
- private import codeql.util.Option
307
-
308
- private class CrateOrigin extends string {
309
- CrateOrigin ( ) { this = any ( Resolvable r ) .getResolvedCrateOrigin ( ) }
310
- }
311
-
312
- private class CrateOriginOption = Option< CrateOrigin > :: Option ;
313
-
314
- private CrateOriginOption langCoreCrate ( ) { result .asSome ( ) = "lang:core" }
315
-
316
- private newtype TVariantInLib =
317
- MkVariantInLib ( CrateOriginOption crate , string path , string name ) {
318
- crate = langCoreCrate ( ) and
319
- (
320
- path = "crate::option::Option" and
321
- name = "Some"
322
- or
323
- path = "crate::result::Result" and
324
- name = [ "Ok" , "Err" ]
325
- )
326
- }
327
-
328
- /** An enum variant from library code, represented by the enum's canonical path and the variant's name. */
329
- class VariantInLib extends MkVariantInLib {
330
- CrateOriginOption crate ;
331
- string path ;
332
- string name ;
333
-
334
- VariantInLib ( ) { this = MkVariantInLib ( crate , path , name ) }
335
-
336
- int getAPosition ( ) {
337
- this = MkVariantInLib ( langCoreCrate ( ) , "crate::option::Option" , "Some" ) and
338
- result = 0
339
- or
340
- this = MkVariantInLib ( langCoreCrate ( ) , "crate::result::Result" , [ "Ok" , "Err" ] ) and
341
- result = 0
342
- }
343
-
344
- string getExtendedCanonicalPath ( ) { result = path + "::" + name }
345
-
346
- string toString ( ) { result = name }
347
- }
348
-
349
- /** A tuple variant from library code. */
350
- class VariantInLibTupleFieldContent extends Content , TVariantInLibTupleFieldContent {
351
- private VariantInLib:: VariantInLib v ;
352
- private int pos_ ;
353
-
354
- VariantInLibTupleFieldContent ( ) { this = TVariantInLibTupleFieldContent ( v , pos_ ) }
355
-
356
- VariantInLib:: VariantInLib getVariantInLib ( int pos ) { result = v and pos = pos_ }
357
-
358
- string getExtendedCanonicalPath ( ) { result = v .getExtendedCanonicalPath ( ) }
359
-
360
- int getPosition ( ) { result = pos_ }
361
-
362
- final override string toString ( ) {
363
- // only print indices when the arity is > 1
364
- if exists ( TVariantInLibTupleFieldContent ( v , 1 ) )
365
- then result = v .toString ( ) + "(" + pos_ + ")"
366
- else result = v .toString ( )
367
- }
368
-
369
- final override Location getLocation ( ) { result instanceof EmptyLocation }
370
- }
371
-
372
- pragma [ nomagic]
373
- private predicate resolveExtendedCanonicalPath ( Resolvable r , CrateOriginOption crate , string path ) {
374
- path = r .getResolvedPath ( ) and
375
- (
376
- crate .asSome ( ) = r .getResolvedCrateOrigin ( )
377
- or
378
- crate .isNone ( ) and
379
- not r .hasResolvedCrateOrigin ( )
380
- )
381
- }
382
-
383
- /** Holds if path `p` resolves to variant `v`. */
384
- private predicate pathResolveToVariantInLib ( PathAstNode p , VariantInLib v ) {
385
- exists ( CrateOriginOption crate , string path , string name |
386
- resolveExtendedCanonicalPath ( p , pragma [ only_bind_into ] ( crate ) , path + "::" + name ) and
387
- v = MkVariantInLib ( pragma [ only_bind_into ] ( crate ) , path , name )
388
- )
389
- }
390
-
391
- /** Holds if `p` destructs an enum variant `v`. */
392
- pragma [ nomagic]
393
- private predicate tupleVariantCanonicalDestruction ( TupleStructPat p , VariantInLib v ) {
394
- pathResolveToVariantInLib ( p , v )
395
- }
396
-
397
- bindingset [ pos]
398
- predicate tupleVariantCanonicalDestruction (
399
- TupleStructPat pat , VariantInLibTupleFieldContent c , int pos
400
- ) {
401
- tupleVariantCanonicalDestruction ( pat , c .getVariantInLib ( pos ) )
402
- }
403
-
404
- /** Holds if `ce` constructs an enum value of type `v`. */
405
- pragma [ nomagic]
406
- private predicate tupleVariantCanonicalConstruction ( CallExpr ce , VariantInLib v ) {
407
- pathResolveToVariantInLib ( ce .getFunction ( ) .( PathExpr ) , v )
408
- }
409
-
410
- bindingset [ pos]
411
- predicate tupleVariantCanonicalConstruction ( CallExpr ce , VariantInLibTupleFieldContent c , int pos ) {
412
- tupleVariantCanonicalConstruction ( ce , c .getVariantInLib ( pos ) )
413
- }
414
- }
415
-
416
- class VariantInLibTupleFieldContent = VariantInLib:: VariantInLibTupleFieldContent ;
417
-
418
299
class LambdaCallKind = Unit ;
419
300
420
301
/** Holds if `creation` is an expression that creates a lambda of kind `kind`. */
@@ -480,6 +361,7 @@ module RustDataFlow implements InputSig<Location> {
480
361
private import Aliases
481
362
private import codeql.rust.dataflow.DataFlow
482
363
private import Node as Node
364
+ private import codeql.rust.frameworks.stdlib.Stdlib
483
365
484
366
/**
485
367
* An element, viewed as a node in a data flow graph. Either an expression
@@ -665,11 +547,8 @@ module RustDataFlow implements InputSig<Location> {
665
547
exists ( Content c | c = cs .( SingletonContentSet ) .getContent ( ) |
666
548
exists ( TupleStructPatCfgNode pat , int pos |
667
549
pat = node1 .asPat ( ) and
668
- node2 .asPat ( ) = pat .getField ( pos )
669
- |
550
+ node2 .asPat ( ) = pat .getField ( pos ) and
670
551
c = TTupleFieldContent ( pat .getTupleStructPat ( ) .getTupleField ( pos ) )
671
- or
672
- VariantInLib:: tupleVariantCanonicalDestruction ( pat .getPat ( ) , c , pos )
673
552
)
674
553
or
675
554
exists ( TuplePatCfgNode pat , int pos |
@@ -714,8 +593,8 @@ module RustDataFlow implements InputSig<Location> {
714
593
exists ( TryExprCfgNode try |
715
594
node1 .asExpr ( ) = try .getExpr ( ) and
716
595
node2 .asExpr ( ) = try and
717
- c .( VariantInLibTupleFieldContent ) . getVariantInLib ( 0 ) . getExtendedCanonicalPath ( ) =
718
- [ "crate::option::Option::Some" , "crate::result::Result::Ok" ]
596
+ c .( TupleFieldContent )
597
+ . isVariantField ( [ any ( OptionEnum o ) . getSome ( ) , any ( ResultEnum r ) . getOk ( ) ] , 0 )
719
598
)
720
599
or
721
600
exists ( PrefixExprCfgNode deref |
@@ -791,11 +670,8 @@ module RustDataFlow implements InputSig<Location> {
791
670
private predicate storeContentStep ( Node node1 , Content c , Node node2 ) {
792
671
exists ( CallExprCfgNode call , int pos |
793
672
node1 .asExpr ( ) = call .getArgument ( pragma [ only_bind_into ] ( pos ) ) and
794
- node2 .asExpr ( ) = call
795
- |
673
+ node2 .asExpr ( ) = call and
796
674
c = TTupleFieldContent ( call .getCallExpr ( ) .getTupleField ( pragma [ only_bind_into ] ( pos ) ) )
797
- or
798
- VariantInLib:: tupleVariantCanonicalConstruction ( call .getCallExpr ( ) , c , pos )
799
675
)
800
676
or
801
677
exists ( StructExprCfgNode re , string field |
0 commit comments