Skip to content

Commit 2f698d1

Browse files
committed
Rust: Type inference for macro expressions
1 parent fd59a27 commit 2f698d1

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,8 @@ private predicate typeEquality(AstNode n1, TypePath prefix1, AstNode n2, TypePat
265265
n1 = be.getLhs() and
266266
n2 = be.getRhs()
267267
)
268+
or
269+
n1 = n2.(MacroExpr).getMacroCall().getMacroCallExpansion()
268270
)
269271
or
270272
n1 = n2.(RefExpr).getExpr() and

rust/ql/test/library-tests/type-inference/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1812,7 +1812,7 @@ mod indexers {
18121812

18131813
mod macros {
18141814
pub fn f() {
1815-
let x = format!("Hello, {}", "World!"); // $ MISSING: type=x:String
1815+
let x = format!("Hello, {}", "World!"); // $ MISSING: type=x:String -- needs https://github.com/github/codeql/pull/19658
18161816
}
18171817
}
18181818

rust/ql/test/library-tests/type-inference/type-inference.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,8 +1021,12 @@ inferType
10211021
| main.rs:912:19:912:22 | self | Snd | main.rs:910:15:910:17 | Snd |
10221022
| main.rs:913:43:913:82 | MacroExpr | | main.rs:910:15:910:17 | Snd |
10231023
| main.rs:913:50:913:81 | "PairNone has no second elemen... | | {EXTERNAL LOCATION} | str |
1024+
| main.rs:913:50:913:81 | MacroExpr | | main.rs:910:15:910:17 | Snd |
1025+
| main.rs:913:50:913:81 | { ... } | | main.rs:910:15:910:17 | Snd |
10241026
| main.rs:914:43:914:81 | MacroExpr | | main.rs:910:15:910:17 | Snd |
10251027
| main.rs:914:50:914:80 | "PairFst has no second element... | | {EXTERNAL LOCATION} | str |
1028+
| main.rs:914:50:914:80 | MacroExpr | | main.rs:910:15:910:17 | Snd |
1029+
| main.rs:914:50:914:80 | { ... } | | main.rs:910:15:910:17 | Snd |
10261030
| main.rs:915:37:915:39 | snd | | main.rs:910:15:910:17 | Snd |
10271031
| main.rs:915:45:915:47 | snd | | main.rs:910:15:910:17 | Snd |
10281032
| main.rs:916:41:916:43 | snd | | main.rs:910:15:910:17 | Snd |

0 commit comments

Comments
 (0)