-
Notifications
You must be signed in to change notification settings - Fork 1.9k
-
I just saw the developer preview for Rust and wanted to try it out.
I'm trying to find all calls to len() on a String object.
pub fn name_length(name: String) -> usize { name.len() }
I expected it to work like this but there is no method for accessing the type information.
I saw other languages having this getType() function. Is Rust different here?
import rust from MethodCallExpr call where call.getIdentifier().toString() = "len" and call.getReceiver().getType().toString() = "String" select call
From looking at the AST it seems I could get the TypeRepr from the function argument by tracing it back via dataflow analysis.
But I'm thinking there must be an easier way?
I'm new to codeql.
Beta Was this translation helpful? Give feedback.
All reactions
Type information is currently not exposed in the public API, since we still haven't decided what that API should look like.
In the meantime, you can use the following:
from MethodCallExpr call where call.getStaticTarget().getCanonicalPath() = "<core::str>::len" select call
Replies: 1 comment
-
Type information is currently not exposed in the public API, since we still haven't decided what that API should look like.
In the meantime, you can use the following:
from MethodCallExpr call where call.getStaticTarget().getCanonicalPath() = "<core::str>::len" select call
Beta Was this translation helpful? Give feedback.