-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Rust: Check call arities in path resolution #20502
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
|
|
||
| private import rust | ||
| private import codeql.rust.elements.internal.generated.ParentChild | ||
| private import codeql.rust.elements.internal.CallExprImpl::Impl as CallExprImpl | ||
| private import codeql.rust.internal.CachedStages | ||
| private import codeql.rust.frameworks.stdlib.Builtins as Builtins | ||
| private import codeql.util.Option | ||
|
|
@@ -604,7 +605,13 @@ private class EnumItemNode extends TypeItemNode instanceof Enum { | |
| } | ||
| } | ||
|
|
||
| private class VariantItemNode extends ItemNode instanceof Variant { | ||
| /** An item that can be called with arguments. */ | ||
| abstract class CallableItemNode extends ItemNode { | ||
|
||
| /** Gets the number of parameters of this item. */ | ||
| abstract int getNumberOfParameters(); | ||
| } | ||
|
|
||
| private class VariantItemNode extends CallableItemNode instanceof Variant { | ||
| override string getName() { result = Variant.super.getName().getText() } | ||
|
|
||
| override Namespace getNamespace() { | ||
|
|
@@ -617,6 +624,10 @@ private class VariantItemNode extends ItemNode instanceof Variant { | |
|
|
||
| override Visibility getVisibility() { result = super.getEnum().getVisibility() } | ||
|
|
||
| override int getNumberOfParameters() { | ||
| result = super.getFieldList().(TupleFieldList).getNumberOfFields() | ||
| } | ||
|
|
||
| override predicate hasCanonicalPath(Crate c) { this.hasCanonicalPathPrefix(c) } | ||
|
|
||
| bindingset[c] | ||
|
|
@@ -638,7 +649,7 @@ private class VariantItemNode extends ItemNode instanceof Variant { | |
| } | ||
| } | ||
|
|
||
| class FunctionItemNode extends AssocItemNode instanceof Function { | ||
| class FunctionItemNode extends AssocItemNode, CallableItemNode instanceof Function { | ||
| override string getName() { result = Function.super.getName().getText() } | ||
|
|
||
| override predicate hasImplementation() { Function.super.hasImplementation() } | ||
|
|
@@ -648,6 +659,13 @@ class FunctionItemNode extends AssocItemNode instanceof Function { | |
| override TypeParam getTypeParam(int i) { result = super.getGenericParamList().getTypeParam(i) } | ||
|
|
||
| override Visibility getVisibility() { result = Function.super.getVisibility() } | ||
|
|
||
| override int getNumberOfParameters() { | ||
| exists(int arr | | ||
| arr = super.getNumberOfParams() and | ||
| if super.hasSelfParam() then result = arr + 1 else result = arr | ||
| ) | ||
| } | ||
|
||
| } | ||
|
|
||
| abstract class ImplOrTraitItemNode extends ItemNode { | ||
|
|
@@ -712,8 +730,10 @@ final class ImplItemNode extends ImplOrTraitItemNode instanceof Impl { | |
| TypeParamItemNode getBlanketImplementationTypeParam() { result = this.resolveSelfTy() } | ||
|
|
||
| /** | ||
| * Holds if this impl block is a blanket implementation. That is, the | ||
| * Holds if this impl block is a [blanket implementation][1]. That is, the | ||
| * implementation targets a generic parameter of the impl block. | ||
| * | ||
| * [1]: https://doc.rust-lang.org/book/ch10-02-traits.html#using-trait-bounds-to-conditionally-implement-methods | ||
| */ | ||
| predicate isBlanketImplementation() { exists(this.getBlanketImplementationTypeParam()) } | ||
|
|
||
|
|
@@ -865,7 +885,7 @@ private class ImplItemNodeImpl extends ImplItemNode { | |
| TraitItemNode resolveTraitTyCand() { result = resolvePathCand(this.getTraitPath()) } | ||
| } | ||
|
|
||
| private class StructItemNode extends TypeItemNode instanceof Struct { | ||
| private class StructItemNode extends TypeItemNode, CallableItemNode instanceof Struct { | ||
| override string getName() { result = Struct.super.getName().getText() } | ||
|
|
||
| override Namespace getNamespace() { | ||
|
|
@@ -877,6 +897,10 @@ private class StructItemNode extends TypeItemNode instanceof Struct { | |
|
|
||
| override Visibility getVisibility() { result = Struct.super.getVisibility() } | ||
|
|
||
| override int getNumberOfParameters() { | ||
| result = super.getFieldList().(TupleFieldList).getNumberOfFields() | ||
| } | ||
|
|
||
| override TypeParam getTypeParam(int i) { result = super.getGenericParamList().getTypeParam(i) } | ||
|
|
||
| override predicate hasCanonicalPath(Crate c) { this.hasCanonicalPathPrefix(c) } | ||
|
|
@@ -1687,6 +1711,14 @@ private ItemNode resolvePathCand(RelevantPath path) { | |
| or | ||
| not pathUsesNamespace(path, _) and | ||
| not path = any(MacroCall mc).getPath() | ||
| ) and | ||
| ( | ||
| not path = CallExprImpl::getFunctionPath(_) | ||
| or | ||
| exists(CallExpr ce | | ||
| path = CallExprImpl::getFunctionPath(ce) and | ||
| result.(CallableItemNode).getNumberOfParameters() = ce.getNumberOfArgs() | ||
| ) | ||
paldepind marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,2 @@ | ||
| multipleCallTargets | ||
| | test_cipher.rs:20:27:20:48 | ...::new(...) | | ||
| | test_cipher.rs:26:27:26:48 | ...::new(...) | | ||
| | test_cipher.rs:29:27:29:48 | ...::new(...) | | ||
| | test_cipher.rs:36:30:36:59 | ...::new(...) | | ||
| | test_cipher.rs:39:30:39:63 | ...::new(...) | | ||
| | test_cipher.rs:114:23:114:50 | ...::new(...) | |
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.