@@ -74,32 +74,34 @@ module Impl {
74
74
* pattern.
75
75
*/
76
76
private predicate variableDecl ( AstNode definingNode , AstNode p , string name ) {
77
- exists ( SelfParam sp | sp = p |
78
- definingNode = sp .getName ( ) and
79
- name = sp .getName ( ) .getText ( ) and
80
- // exclude self parameters from functions without a body as these are
81
- // trait method declarations without implementations
82
- not exists ( Function f | not f .hasBody ( ) and f .getParamList ( ) .getSelfParam ( ) = sp )
83
- )
77
+ p =
78
+ any ( SelfParam sp |
79
+ definingNode = sp .getName ( ) and
80
+ name = sp .getName ( ) .getText ( ) and
81
+ // exclude self parameters from functions without a body as these are
82
+ // trait method declarations without implementations
83
+ not exists ( Function f | not f .hasBody ( ) and f .getParamList ( ) .getSelfParam ( ) = sp )
84
+ )
84
85
or
85
- exists ( IdentPat pat | pat = p |
86
- (
87
- definingNode = getOutermostEnclosingOrPat ( pat )
88
- or
89
- not exists ( getOutermostEnclosingOrPat ( pat ) ) and definingNode = pat .getName ( )
90
- ) and
91
- name = pat .getName ( ) .getText ( ) and
92
- // exclude for now anything starting with an uppercase character, which may be a reference to
93
- // an enum constant (e.g. `None`). This excludes static and constant variables (UPPERCASE),
94
- // which we don't appear to recognize yet anyway. This also assumes programmers follow the
95
- // naming guidelines, which they generally do, but they're not enforced.
96
- not name .charAt ( 0 ) .isUppercase ( ) and
97
- // exclude parameters from functions without a body as these are trait method declarations
98
- // without implementations
99
- not exists ( Function f | not f .hasBody ( ) and f .getParamList ( ) .getAParam ( ) .getPat ( ) = pat ) and
100
- // exclude parameters from function pointer types (e.g. `x` in `fn(x: i32) -> i32`)
101
- not exists ( FnPtrType fp | fp .getParamList ( ) .getParam ( _) .getPat ( ) = pat )
102
- )
86
+ p =
87
+ any ( IdentPat pat |
88
+ (
89
+ definingNode = getOutermostEnclosingOrPat ( pat )
90
+ or
91
+ not exists ( getOutermostEnclosingOrPat ( pat ) ) and definingNode = pat .getName ( )
92
+ ) and
93
+ name = pat .getName ( ) .getText ( ) and
94
+ // exclude for now anything starting with an uppercase character, which may be a reference to
95
+ // an enum constant (e.g. `None`). This excludes static and constant variables (UPPERCASE),
96
+ // which we don't appear to recognize yet anyway. This also assumes programmers follow the
97
+ // naming guidelines, which they generally do, but they're not enforced.
98
+ not name .charAt ( 0 ) .isUppercase ( ) and
99
+ // exclude parameters from functions without a body as these are trait method declarations
100
+ // without implementations
101
+ not exists ( Function f | not f .hasBody ( ) and f .getParamList ( ) .getAParam ( ) .getPat ( ) = pat ) and
102
+ // exclude parameters from function pointer types (e.g. `x` in `fn(x: i32) -> i32`)
103
+ not exists ( FnPtrType fp | fp .getParamList ( ) .getParam ( _) .getPat ( ) = pat )
104
+ )
103
105
}
104
106
105
107
/** A variable. */
@@ -125,7 +127,7 @@ module Impl {
125
127
SelfParam getSelfParam ( ) { variableDecl ( definingNode , result , name ) }
126
128
127
129
/**
128
- * Gets the pattern that declares this variable, if one exists .
130
+ * Gets the pattern that declares this variable, if any .
129
131
*
130
132
* Normally, the pattern is unique, except when introduced in an or pattern:
131
133
*
@@ -148,7 +150,7 @@ module Impl {
148
150
149
151
/** Gets the parameter that introduces this variable, if any. */
150
152
ParamBase getParameter ( ) {
151
- result = this .getSelfParam ( ) or result = getAVariablePatAncestor ( this ) . getParentNode ( )
153
+ result = this .getSelfParam ( ) or result . ( Param ) . getPat ( ) = getAVariablePatAncestor ( this )
152
154
}
153
155
154
156
/** Hold is this variable is mutable. */
@@ -217,8 +219,7 @@ module Impl {
217
219
}
218
220
219
221
/**
220
- * Holds if parameter `p` introduces the variable `v` inside variable scope
221
- * `scope`.
222
+ * Holds if a parameter declares the variable `v` inside variable scope `scope`.
222
223
*/
223
224
private predicate parameterDeclInScope ( Variable v , VariableScope scope ) {
224
225
exists ( Callable f |
0 commit comments