Skip to content

Rust: Use verbose type paths in inline expectation comments#21778

Open
hvitved wants to merge 2 commits intogithub:mainfrom
hvitved:rust/type-inference-verbose-type-path-expectations
Open

Rust: Use verbose type paths in inline expectation comments#21778
hvitved wants to merge 2 commits intogithub:mainfrom
hvitved:rust/type-inference-verbose-type-path-expectations

Conversation

@hvitved
Copy link
Copy Markdown
Contributor

@hvitved hvitved commented Apr 30, 2026

Updates the inline type test expectations to follow the same format as in #21777. For example, for a variable x of type Result<Option<i32>, bool> we would previously have these four comments

type=x:Result
type=x:T.Option
type=x:T.T.i32
type=x:E.bool

but now we instead have the more verbose (and human verifiable) format

type=x@Result<T>.Option<T>:i32
type=x@Result<E>:bool

Note that since the type parameters are tagged with the types that they belong to, we can distinguish the two parameters both named T, and there is also no need to add the comments type=x:Result and type=x@Result<T>:Option (the former is implied by both comments, the latter is implied by the first comment).

@github-actions github-actions Bot added the Rust Pull requests that update Rust code label Apr 30, 2026
@hvitved hvitved force-pushed the rust/type-inference-verbose-type-path-expectations branch from de564a5 to e1cd708 Compare April 30, 2026 11:54
@hvitved hvitved added the no-change-note-required This PR does not need a change note label Apr 30, 2026
@hvitved hvitved marked this pull request as ready for review April 30, 2026 12:18
@hvitved hvitved requested a review from a team as a code owner April 30, 2026 12:18
Copilot AI review requested due to automatic review settings April 30, 2026 12:18
@hvitved hvitved requested a review from a team as a code owner April 30, 2026 12:18
@hvitved hvitved requested a review from geoffw0 April 30, 2026 12:18
for cell in row { // $ MISSING: type=cell:i32
}
};

let mut map1 = std::collections::HashMap::new(); // $ target=new type=map1:K.i32 type=map1:V.Box $ MISSING: type=map1:Hashmap type1=map1:V.T.TRef.str
let mut map1 = std::collections::HashMap::new(); // $ target=new type=map1@HashMap<K>:i32 type=map1@HashMap<V>.Box<T>.&<TRef>:str
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The MISSING parts were in fact not missing; the first misspelled Hashmap and the second misspelled type1.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates Rust type-inference inline expectation tests to use a more verbose, owner-qualified type-path format (matching the approach used in #21777), making expectations easier to verify by humans and unambiguous when type parameters share names.

Changes:

  • Add TypePath::printTypePathVerbose to produce owner-qualified type-parameter paths (for example S1<T1>.S2<T2>).
  • Update the Rust type-inference inline-expectations harness to emit element@<verbose-type-path>:<type> for non-empty TypePaths.
  • Migrate Rust type-inference library test .rs files to the new inline expectation comment format.
Show a summary per file
File Description
shared/typeinference/codeql/typeinference/internal/TypeInference.qll Introduces verbose printing for type paths by including the owning type of each type parameter.
rust/ql/test/library-tests/type-inference/type-inference.ql Changes emitted expectation value format to include @<verbose-type-path> for nested type paths.
rust/ql/test/library-tests/type-inference/regressions.rs Updates regression inline expectations to the new verbose type-path format.
rust/ql/test/library-tests/type-inference/raw_pointer.rs Updates raw-pointer type expectations to the new verbose format.
rust/ql/test/library-tests/type-inference/pattern_matching.rs Updates pattern-matching type expectations to the new verbose format.
rust/ql/test/library-tests/type-inference/main.rs Broad updates to type inference expectations across many Rust constructs (generics, collections, ranges, etc.).
rust/ql/test/library-tests/type-inference/dereference.rs Updates dereference-related type expectations to the new verbose format.
rust/ql/test/library-tests/type-inference/associated_types.rs Updates associated-type expectations to the new verbose format.

Copilot's findings

  • Files reviewed: 8/8 changed files
  • Comments generated: 1

Comment thread rust/ql/test/library-tests/type-inference/main.rs Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-change-note-required This PR does not need a change note Rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants