Skip to content

Commit 5fb425f

Browse files
committed
Rust: Update extractor and QL code after removing MacroBlockExpr
1 parent 3eafca0 commit 5fb425f

File tree

4 files changed

+35
-27
lines changed

4 files changed

+35
-27
lines changed

rust/extractor/src/translate/base.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ impl<'a> Translator<'a> {
518518
pub(crate) fn emit_macro_stmts(
519519
&mut self,
520520
node: &ast::MacroStmts,
521-
) -> Option<Label<generated::MacroBlockExpr>> {
521+
) -> Option<Label<generated::BlockExpr>> {
522522
// not generated to work around a bug in rust-analyzer AST generation machinery.
523523
// Because an Expr can also be a Stmt (AsmExpr: Expr and AsmExpr: Item: Stmt)
524524
// then such an element will be returned by both `expr()` and `statements()`
@@ -537,10 +537,23 @@ impl<'a> Translator<'a> {
537537
.iter()
538538
.filter_map(|x| self.emit_stmt(x))
539539
.collect();
540-
let label = self.trap.emit(generated::MacroBlockExpr {
540+
let stmt_list = self.trap.emit(generated::StmtList {
541541
id: TrapId::Star,
542-
tail_expr,
542+
attrs: vec![],
543543
statements,
544+
tail_expr,
545+
});
546+
let label = self.trap.emit(generated::BlockExpr {
547+
id: TrapId::Star,
548+
label: None,
549+
attrs: vec![],
550+
is_async: false,
551+
is_const: false,
552+
is_gen: false,
553+
is_move: false,
554+
is_try: false,
555+
is_unsafe: false,
556+
stmt_list: Some(stmt_list),
544557
});
545558
self.emit_location(label, node);
546559
self.emit_tokens(node, label.into(), node.syntax().children_with_tokens());

rust/ql/lib/codeql/rust/controlflow/internal/ControlFlowGraphImpl.qll

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class FormatTemplateVariableAccessTree extends LeafTree, FormatTemplateVariableA
9999
class ItemTree extends LeafTree, Item {
100100
ItemTree() {
101101
not this instanceof MacroCall and
102-
this = [any(StmtList s).getAStatement(), any(MacroBlockExpr s).getAStatement()]
102+
this = any(StmtList s).getAStatement()
103103
}
104104
}
105105

@@ -140,15 +140,6 @@ class MacroCallTree extends StandardPostOrderTree, MacroCall {
140140
override AstNode getChildNode(int i) { i = 0 and result = this.getMacroCallExpansion() }
141141
}
142142

143-
class MacroBlockExprTree extends StandardPostOrderTree, MacroBlockExpr {
144-
override AstNode getChildNode(int i) {
145-
result = this.getStatement(i)
146-
or
147-
i = this.getNumberOfStatements() and
148-
result = this.getTailExpr()
149-
}
150-
}
151-
152143
class MatchArmTree extends ControlFlowTree, MatchArm {
153144
override predicate propagatesAbnormal(AstNode child) { child = this.getExpr() }
154145

rust/ql/lib/codeql/rust/dataflow/internal/DataFlowImpl.qll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ private Expr getALastEvalNode(Expr e) {
149149
not be.isAsync() and
150150
result = be.getTailExpr()
151151
) or
152-
result = e.(MacroBlockExpr).getTailExpr() or
153152
result = e.(MatchExpr).getAnArm().getExpr() or
154153
result = e.(MacroExpr).getMacroCall().getMacroCallExpansion() or
155154
result.(BreakExpr).getTarget() = e or

rust/ql/lib/codeql/rust/internal/PathResolution.qll

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -110,20 +110,18 @@ pragma[nomagic]
110110
private ItemNode getAChildSuccessor(ItemNode item, string name, SuccessorKind kind) {
111111
item = result.getImmediateParent() and
112112
name = result.getName() and
113-
(
114-
// type parameters are only available inside the declaring item
115-
if result instanceof TypeParam
116-
then kind.isInternal()
113+
// type parameters are only available inside the declaring item
114+
if result instanceof TypeParam
115+
then kind.isInternal()
116+
else
117+
// associated items must always be qualified, also within the declaring
118+
// item (using `Self`)
119+
if item instanceof ImplOrTraitItemNode and result instanceof AssocItem
120+
then kind.isExternal()
117121
else
118-
// associated items must always be qualified, also within the declaring
119-
// item (using `Self`)
120-
if item instanceof ImplOrTraitItemNode and result instanceof AssocItem
121-
then kind.isExternal()
122-
else
123-
if result.isPublic()
124-
then kind.isBoth()
125-
else kind.isInternal()
126-
)
122+
if result.isPublic()
123+
then kind.isBoth()
124+
else kind.isInternal()
127125
}
128126

129127
private module UseOption = Option<Use>;
@@ -372,6 +370,13 @@ abstract class ItemNode extends Locatable {
372370
result = this.(TypeAliasItemNodeImpl).resolveAliasCand().getASuccessor(name, kind, useOpt) and
373371
kind.isExternalOrBoth()
374372
or
373+
// items declared at top-level inside macros are also available at the macro invocation sites
374+
exists(BlockExprItemNode be |
375+
this = be.getImmediateParent() and
376+
be = any(MacroCall mc).getMacroCallExpansion() and
377+
result = be.getASuccessor(name, kind, useOpt)
378+
)
379+
or
375380
name = "super" and
376381
useOpt.isNone() and
377382
(

0 commit comments

Comments
 (0)