|
1 | 1 | private import rust |
2 | 2 | private import codeql.rust.controlflow.ControlFlowGraph |
| 3 | +private import codeql.rust.internal.PathResolution as PathResolution |
3 | 4 | private import codeql.rust.elements.internal.generated.ParentChild as ParentChild |
| 5 | +private import codeql.rust.elements.internal.AstNodeImpl::Impl as AstNodeImpl |
4 | 6 | private import codeql.rust.elements.internal.PathImpl::Impl as PathImpl |
5 | 7 | private import codeql.rust.elements.internal.PathExprBaseImpl::Impl as PathExprBaseImpl |
6 | 8 | private import codeql.rust.elements.internal.FormatTemplateVariableAccessImpl::Impl as FormatTemplateVariableAccessImpl |
@@ -98,35 +100,34 @@ module Impl { |
98 | 100 | * pattern. |
99 | 101 | */ |
100 | 102 | cached |
101 | | - private predicate variableDecl(AstNode definingNode, Name name, string text) { |
| 103 | + predicate variableDecl(AstNode definingNode, Name name, string text) { |
102 | 104 | Cached::ref() and |
103 | | - exists(SelfParam sp | |
104 | | - name = sp.getName() and |
105 | | - definingNode = name and |
106 | | - text = name.getText() and |
107 | | - // exclude self parameters from functions without a body as these are |
108 | | - // trait method declarations without implementations |
109 | | - not exists(Function f | not f.hasBody() and f.getSelfParam() = sp) |
110 | | - ) |
111 | | - or |
112 | | - exists(IdentPat pat | |
113 | | - name = pat.getName() and |
114 | | - ( |
115 | | - definingNode = getOutermostEnclosingOrPat(pat) |
116 | | - or |
117 | | - not exists(getOutermostEnclosingOrPat(pat)) and definingNode = name |
118 | | - ) and |
119 | | - text = name.getText() and |
120 | | - // exclude for now anything starting with an uppercase character, which may be a reference to |
121 | | - // an enum constant (e.g. `None`). This excludes static and constant variables (UPPERCASE), |
122 | | - // which we don't appear to recognize yet anyway. This also assumes programmers follow the |
123 | | - // naming guidelines, which they generally do, but they're not enforced. |
124 | | - not text.charAt(0).isUppercase() 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) |
| 105 | + not AstNodeImpl::supersededByAttributeMacroExpansion(definingNode) and |
| 106 | + ( |
| 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) |
| 130 | + ) |
130 | 131 | ) |
131 | 132 | } |
132 | 133 |
|
|
0 commit comments