Rust: Make RefExpr an Operation.

This commit is contained in:
Geoffrey White
2025-05-21 14:15:47 +01:00
parent b8f0e4d7e0
commit b22ce5515f
2 changed files with 7 additions and 2 deletions

View File

@@ -5,6 +5,7 @@
*/
private import codeql.rust.elements.internal.generated.RefExpr
private import codeql.rust.elements.internal.OperationImpl::Impl as OperationImpl
/**
* INTERNAL: This module contains the customizable definition of `RefExpr` and should not
@@ -21,11 +22,15 @@ module Impl {
* let raw_mut: &mut i32 = &raw mut foo;
* ```
*/
class RefExpr extends Generated::RefExpr {
class RefExpr extends Generated::RefExpr, OperationImpl::Operation {
override string toStringImpl() {
result = "&" + concat(int i | | this.getSpecPart(i), " " order by i)
}
override string getOperatorName() { result = "&" }
override Expr getAnOperand() { result = this.getExpr() }
private string getSpecPart(int index) {
index = 0 and this.isRaw() and result = "raw"
or

View File

@@ -50,7 +50,7 @@ fn test_operations(
// miscellaneous expressions that might be operations
*ptr; // $ Operation Op=* Operands=1 PrefixExpr DerefExpr
&x; // $ RefExpr
&x; // $ Operation Op=& Operands=1 RefExpr MISSING: PrefixExpr
res?;
return Ok(());