Skip to content

Commit 7051ad5

Browse files
authored
Merge pull request #19751 from hvitved/rust/type-inference-macro-expr
Rust: Type inference for macro expressions
2 parents 8838104 + 2f698d1 commit 7051ad5

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1810,6 +1810,12 @@ mod indexers {
18101810
}
18111811
}
18121812

1813+
mod macros {
1814+
pub fn f() {
1815+
let x = format!("Hello, {}", "World!"); // $ MISSING: type=x:String -- needs https://github.com/github/codeql/pull/19658
1816+
}
1817+
}
1818+
18131819
fn main() {
18141820
field_access::f();
18151821
method_impl::f();
@@ -1832,4 +1838,5 @@ fn main() {
18321838
async_::f();
18331839
impl_trait::f();
18341840
indexers::f();
1841+
macros::f();
18351842
}

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

Lines changed: 13 additions & 5 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 |
@@ -2642,9 +2646,13 @@ inferType
26422646
| main.rs:1809:24:1809:25 | xs | | file://:0:0:0:0 | [] |
26432647
| main.rs:1809:24:1809:25 | xs | [T;...] | main.rs:1764:5:1765:13 | S |
26442648
| main.rs:1809:24:1809:25 | xs | [T] | main.rs:1764:5:1765:13 | S |
2645-
| main.rs:1815:5:1815:20 | ...::f(...) | | main.rs:67:5:67:21 | Foo |
2646-
| main.rs:1816:5:1816:60 | ...::g(...) | | main.rs:67:5:67:21 | Foo |
2647-
| main.rs:1816:20:1816:38 | ...::Foo {...} | | main.rs:67:5:67:21 | Foo |
2648-
| main.rs:1816:41:1816:59 | ...::Foo {...} | | main.rs:67:5:67:21 | Foo |
2649-
| main.rs:1832:5:1832:15 | ...::f(...) | | {EXTERNAL LOCATION} | trait Future |
2649+
| main.rs:1815:25:1815:35 | "Hello, {}" | | {EXTERNAL LOCATION} | str |
2650+
| main.rs:1815:25:1815:45 | ...::format(...) | | {EXTERNAL LOCATION} | String |
2651+
| main.rs:1815:25:1815:45 | { ... } | | {EXTERNAL LOCATION} | String |
2652+
| main.rs:1815:38:1815:45 | "World!" | | {EXTERNAL LOCATION} | str |
2653+
| main.rs:1821:5:1821:20 | ...::f(...) | | main.rs:67:5:67:21 | Foo |
2654+
| main.rs:1822:5:1822:60 | ...::g(...) | | main.rs:67:5:67:21 | Foo |
2655+
| main.rs:1822:20:1822:38 | ...::Foo {...} | | main.rs:67:5:67:21 | Foo |
2656+
| main.rs:1822:41:1822:59 | ...::Foo {...} | | main.rs:67:5:67:21 | Foo |
2657+
| main.rs:1838:5:1838:15 | ...::f(...) | | {EXTERNAL LOCATION} | trait Future |
26502658
testFailures

0 commit comments

Comments
 (0)