@@ -2,6 +2,7 @@ private import rust
22private import codeql.rust.controlflow.ControlFlowGraph
33private import codeql.rust.internal.PathResolution as PathResolution
44private import codeql.rust.elements.internal.generated.ParentChild as ParentChild
5+ private import codeql.rust.elements.internal.AstNodeImpl:: Impl as AstNodeImpl
56private import codeql.rust.elements.internal.PathImpl:: Impl as PathImpl
67private import codeql.rust.elements.internal.PathExprBaseImpl:: Impl as PathExprBaseImpl
78private import codeql.rust.elements.internal.FormatTemplateVariableAccessImpl:: Impl as FormatTemplateVariableAccessImpl
@@ -104,29 +105,32 @@ module Impl {
104105 cached
105106 predicate variableDecl ( AstNode definingNode , Name name , string text ) {
106107 Cached:: ref ( ) and
107- exists ( SelfParam sp |
108- name = sp .getName ( ) and
109- definingNode = name and
110- text = name .getText ( ) and
111- // exclude self parameters from functions without a body as these are
112- // trait method declarations without implementations
113- not exists ( Function f | not f .hasBody ( ) and f .getSelfParam ( ) = sp )
114- )
115- or
116- exists ( IdentPat pat |
117- name = pat .getName ( ) and
118- (
119- definingNode = getOutermostEnclosingOrPat ( pat )
120- or
121- not exists ( getOutermostEnclosingOrPat ( pat ) ) and definingNode = name
122- ) and
123- text = name .getText ( ) and
124- not PathResolution:: identPatIsResolvable ( pat ) and
125- // exclude parameters from functions without a body as these are trait method declarations
126- // without implementations
127- not exists ( Function f | not f .hasBody ( ) and f .getAParam ( ) .getPat ( ) = pat ) and
128- // exclude parameters from function pointer types (e.g. `x` in `fn(x: i32) -> i32`)
129- not exists ( FnPtrTypeRepr fp | fp .getParamList ( ) .getAParam ( ) .getPat ( ) = pat )
108+ not AstNodeImpl:: supersededByAttributeMacroExpansion ( definingNode ) and
109+ (
110+ exists ( SelfParam sp |
111+ name = sp .getName ( ) and
112+ definingNode = name and
113+ text = name .getText ( ) and
114+ // exclude self parameters from functions without a body as these are
115+ // trait method declarations without implementations
116+ not exists ( Function f | not f .hasBody ( ) and f .getSelfParam ( ) = sp )
117+ )
118+ or
119+ exists ( IdentPat pat |
120+ name = pat .getName ( ) and
121+ (
122+ definingNode = getOutermostEnclosingOrPat ( pat )
123+ or
124+ not exists ( getOutermostEnclosingOrPat ( pat ) ) and definingNode = name
125+ ) and
126+ text = name .getText ( ) and
127+ not PathResolution:: identPatIsResolvable ( pat ) and
128+ // exclude parameters from functions without a body as these are trait method declarations
129+ // without implementations
130+ not exists ( Function f | not f .hasBody ( ) and f .getAParam ( ) .getPat ( ) = pat ) and
131+ // exclude parameters from function pointer types (e.g. `x` in `fn(x: i32) -> i32`)
132+ not exists ( FnPtrTypeRepr fp | fp .getParamList ( ) .getAParam ( ) .getPat ( ) = pat )
133+ )
130134 )
131135 }
132136
@@ -457,7 +461,12 @@ module Impl {
457461 VariableAccessCand cand , VariableScope scope , string name , int nestLevel , int ord
458462 ) {
459463 name = cand .getName ( ) and
460- scope = [ cand .( VariableScope ) , getEnclosingScope ( cand ) ] and
464+ (
465+ scope = cand .( VariableScope )
466+ or
467+ not cand instanceof VariableScope and
468+ scope = getEnclosingScope ( cand )
469+ ) and
461470 ord = getPreOrderNumbering ( scope , cand ) and
462471 nestLevel = 0
463472 or
@@ -470,6 +479,19 @@ module Impl {
470479 )
471480 }
472481
482+ private predicate testvariableAccessCandInScope (
483+ VariableAccessCand cand , VariableScope scope , string name , int nestLevel , int ord
484+ ) {
485+ // variableAccessCandInScope(cand, scope, name, nestLevel, ord) and
486+ cand .getLocation ( ) .getStartLine ( ) = 770 and
487+ (
488+ name = cand .getName ( ) and
489+ scope = [ cand .( VariableScope ) , getEnclosingScope ( cand ) ] and
490+ ord = getPreOrderNumbering ( scope , cand ) and
491+ nestLevel = 0
492+ )
493+ }
494+
473495 private newtype TDefOrAccessCand =
474496 TDefOrAccessCandNestedFunction ( Function f , BlockExprScope scope ) {
475497 f = scope .getStmtList ( ) .getAStatement ( )
@@ -647,6 +669,14 @@ module Impl {
647669 )
648670 }
649671
672+ private predicate testvariableReachesCand (
673+ VariableScope scope , string name , NestedFunctionOrVariable v , VariableAccessCand cand ,
674+ int nestLevel
675+ ) {
676+ variableReachesCand ( scope , name , v , cand , nestLevel ) and
677+ v .getLocation ( ) .getStartLine ( ) = [ 767 , 769 ]
678+ }
679+
650680 pragma [ nomagic]
651681 predicate access ( string name , NestedFunctionOrVariable v , VariableAccessCand cand ) {
652682 v =
@@ -657,6 +687,11 @@ module Impl {
657687 )
658688 }
659689
690+ private predicate testaccess ( string name , NestedFunctionOrVariable v , VariableAccessCand cand ) {
691+ access ( name , v , cand ) and
692+ cand .getLocation ( ) .getStartLine ( ) = 770
693+ }
694+
660695 /** A variable access. */
661696 class VariableAccess extends PathExprBaseImpl:: PathExprBase {
662697 private string name ;
0 commit comments