github / github/codeql

[Rust] Get type of expression

Open
#20,501 7 comments 1 reaction 0 assignees View on GitHub
question Rust
Dominant language
CodeQL
Stars
10.1k
Forks
2.1k
Avg merge
2d 15h
Merged PRs (30d)
141

Description

**Description of the issue**

How do I get the type of an expression in Rust?

For example, I want to constrain this to only accesses on string-like expressions.
```ql
private class IndexExprOnNonConstantString extends IndexExpr {
IndexExprOnNonConstantString() { not this.getBase() instanceof StringLiteralExpr }
}
```

**Actual**: No `getType` predicate on expr.
**Expected**: Predicate to get type of expr.

When will support be added for an - in my understanding - very basic feature?
Or is there a workaround/internal API?

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the Rust CodeQL expression model and the existing Expr predicates, using getBase() and StringLiteralExpr from the example as the initial entry points. Confirm whether an internal type API or workaround exists; done means an expression type can be queried well enough to constrain the shown index-expression class.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools, security
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.