Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions rust/ql/lib/codeql/rust/internal/TypeInference.qll
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ private predicate typeEquality(AstNode n1, TypePath prefix1, AstNode n2, TypePat
n1 = be.getLhs() and
n2 = be.getRhs()
)
or
Copy link

Copilot AI Jun 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider adding a brief comment above this clause explaining why macro expressions require special handling here, improving future maintainability.

Suggested change
or
or
// Macro expressions require special handling because they can expand into multiple
// expressions or statements, which affects type inference.

Copilot uses AI. Check for mistakes.
n1 = n2.(MacroExpr).getMacroCall().getMacroCallExpansion()
)
or
n1 = n2.(RefExpr).getExpr() and
Expand Down
7 changes: 7 additions & 0 deletions rust/ql/test/library-tests/type-inference/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1810,6 +1810,12 @@ mod indexers {
}
}

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

fn main() {
field_access::f();
method_impl::f();
Expand All @@ -1832,4 +1838,5 @@ fn main() {
async_::f();
impl_trait::f();
indexers::f();
macros::f();
}
Original file line number Diff line number Diff line change
Expand Up @@ -1021,8 +1021,12 @@ inferType
| main.rs:912:19:912:22 | self | Snd | main.rs:910:15:910:17 | Snd |
| main.rs:913:43:913:82 | MacroExpr | | main.rs:910:15:910:17 | Snd |
| main.rs:913:50:913:81 | "PairNone has no second elemen... | | {EXTERNAL LOCATION} | str |
| main.rs:913:50:913:81 | MacroExpr | | main.rs:910:15:910:17 | Snd |
| main.rs:913:50:913:81 | { ... } | | main.rs:910:15:910:17 | Snd |
| main.rs:914:43:914:81 | MacroExpr | | main.rs:910:15:910:17 | Snd |
| main.rs:914:50:914:80 | "PairFst has no second element... | | {EXTERNAL LOCATION} | str |
| main.rs:914:50:914:80 | MacroExpr | | main.rs:910:15:910:17 | Snd |
| main.rs:914:50:914:80 | { ... } | | main.rs:910:15:910:17 | Snd |
| main.rs:915:37:915:39 | snd | | main.rs:910:15:910:17 | Snd |
| main.rs:915:45:915:47 | snd | | main.rs:910:15:910:17 | Snd |
| main.rs:916:41:916:43 | snd | | main.rs:910:15:910:17 | Snd |
Expand Down Expand Up @@ -2642,9 +2646,13 @@ inferType
| main.rs:1809:24:1809:25 | xs | | file://:0:0:0:0 | [] |
| main.rs:1809:24:1809:25 | xs | [T;...] | main.rs:1764:5:1765:13 | S |
| main.rs:1809:24:1809:25 | xs | [T] | main.rs:1764:5:1765:13 | S |
| main.rs:1815:5:1815:20 | ...::f(...) | | main.rs:67:5:67:21 | Foo |
| main.rs:1816:5:1816:60 | ...::g(...) | | main.rs:67:5:67:21 | Foo |
| main.rs:1816:20:1816:38 | ...::Foo {...} | | main.rs:67:5:67:21 | Foo |
| main.rs:1816:41:1816:59 | ...::Foo {...} | | main.rs:67:5:67:21 | Foo |
| main.rs:1832:5:1832:15 | ...::f(...) | | {EXTERNAL LOCATION} | trait Future |
| main.rs:1815:25:1815:35 | "Hello, {}" | | {EXTERNAL LOCATION} | str |
| main.rs:1815:25:1815:45 | ...::format(...) | | {EXTERNAL LOCATION} | String |
| main.rs:1815:25:1815:45 | { ... } | | {EXTERNAL LOCATION} | String |
| main.rs:1815:38:1815:45 | "World!" | | {EXTERNAL LOCATION} | str |
| main.rs:1821:5:1821:20 | ...::f(...) | | main.rs:67:5:67:21 | Foo |
| main.rs:1822:5:1822:60 | ...::g(...) | | main.rs:67:5:67:21 | Foo |
| main.rs:1822:20:1822:38 | ...::Foo {...} | | main.rs:67:5:67:21 | Foo |
| main.rs:1822:41:1822:59 | ...::Foo {...} | | main.rs:67:5:67:21 | Foo |
| main.rs:1838:5:1838:15 | ...::f(...) | | {EXTERNAL LOCATION} | trait Future |
testFailures