44
55private import rust
66private import codeql.rust.elements.internal.generated.ParentChild
7+ private import codeql.rust.elements.internal.CallExprImpl:: Impl as CallExprImpl
78private import codeql.rust.internal.CachedStages
89private import codeql.rust.frameworks.stdlib.Builtins as Builtins
910private import codeql.util.Option
@@ -604,7 +605,13 @@ private class EnumItemNode extends TypeItemNode instanceof Enum {
604605 }
605606}
606607
607- private class VariantItemNode extends ItemNode instanceof Variant {
608+ /** An item that can be called with arguments. */
609+ abstract class CallableItemNode extends ItemNode {
610+ /** Gets the number of parameters of this item. */
611+ abstract int getNumberOfParameters ( ) ;
612+ }
613+
614+ private class VariantItemNode extends CallableItemNode instanceof Variant {
608615 override string getName ( ) { result = Variant .super .getName ( ) .getText ( ) }
609616
610617 override Namespace getNamespace ( ) {
@@ -617,6 +624,10 @@ private class VariantItemNode extends ItemNode instanceof Variant {
617624
618625 override Visibility getVisibility ( ) { result = super .getEnum ( ) .getVisibility ( ) }
619626
627+ override int getNumberOfParameters ( ) {
628+ result = super .getFieldList ( ) .( TupleFieldList ) .getNumberOfFields ( )
629+ }
630+
620631 override predicate hasCanonicalPath ( Crate c ) { this .hasCanonicalPathPrefix ( c ) }
621632
622633 bindingset [ c]
@@ -638,7 +649,7 @@ private class VariantItemNode extends ItemNode instanceof Variant {
638649 }
639650}
640651
641- class FunctionItemNode extends AssocItemNode instanceof Function {
652+ class FunctionItemNode extends AssocItemNode , CallableItemNode instanceof Function {
642653 override string getName ( ) { result = Function .super .getName ( ) .getText ( ) }
643654
644655 override predicate hasImplementation ( ) { Function .super .hasImplementation ( ) }
@@ -648,6 +659,13 @@ class FunctionItemNode extends AssocItemNode instanceof Function {
648659 override TypeParam getTypeParam ( int i ) { result = super .getGenericParamList ( ) .getTypeParam ( i ) }
649660
650661 override Visibility getVisibility ( ) { result = Function .super .getVisibility ( ) }
662+
663+ override int getNumberOfParameters ( ) {
664+ exists ( int arr |
665+ arr = super .getNumberOfParams ( ) and
666+ if super .hasSelfParam ( ) then result = arr + 1 else result = arr
667+ )
668+ }
651669}
652670
653671abstract class ImplOrTraitItemNode extends ItemNode {
@@ -712,8 +730,10 @@ final class ImplItemNode extends ImplOrTraitItemNode instanceof Impl {
712730 TypeParamItemNode getBlanketImplementationTypeParam ( ) { result = this .resolveSelfTy ( ) }
713731
714732 /**
715- * Holds if this impl block is a blanket implementation. That is, the
733+ * Holds if this impl block is a [ blanket implementation][1] . That is, the
716734 * implementation targets a generic parameter of the impl block.
735+ *
736+ * [1]: https://doc.rust-lang.org/book/ch10-02-traits.html#using-trait-bounds-to-conditionally-implement-methods
717737 */
718738 predicate isBlanketImplementation ( ) { exists ( this .getBlanketImplementationTypeParam ( ) ) }
719739
@@ -865,7 +885,7 @@ private class ImplItemNodeImpl extends ImplItemNode {
865885 TraitItemNode resolveTraitTyCand ( ) { result = resolvePathCand ( this .getTraitPath ( ) ) }
866886}
867887
868- private class StructItemNode extends TypeItemNode instanceof Struct {
888+ private class StructItemNode extends TypeItemNode , CallableItemNode instanceof Struct {
869889 override string getName ( ) { result = Struct .super .getName ( ) .getText ( ) }
870890
871891 override Namespace getNamespace ( ) {
@@ -877,6 +897,10 @@ private class StructItemNode extends TypeItemNode instanceof Struct {
877897
878898 override Visibility getVisibility ( ) { result = Struct .super .getVisibility ( ) }
879899
900+ override int getNumberOfParameters ( ) {
901+ result = super .getFieldList ( ) .( TupleFieldList ) .getNumberOfFields ( )
902+ }
903+
880904 override TypeParam getTypeParam ( int i ) { result = super .getGenericParamList ( ) .getTypeParam ( i ) }
881905
882906 override predicate hasCanonicalPath ( Crate c ) { this .hasCanonicalPathPrefix ( c ) }
@@ -1687,6 +1711,14 @@ private ItemNode resolvePathCand(RelevantPath path) {
16871711 or
16881712 not pathUsesNamespace ( path , _) and
16891713 not path = any ( MacroCall mc ) .getPath ( )
1714+ ) and
1715+ (
1716+ not path = CallExprImpl:: getFunctionPath ( _)
1717+ or
1718+ exists ( CallExpr ce |
1719+ path = CallExprImpl:: getFunctionPath ( ce ) and
1720+ result .( CallableItemNode ) .getNumberOfParameters ( ) = ce .getNumberOfArgs ( )
1721+ )
16901722 )
16911723}
16921724
0 commit comments