CodeQL library for Rust
codeql/rust-all 0.2.25 (changelog, source)
Search

Class ItemNode

An item that may be referred to by a path, and which is a node in the item graph.

The item graph is a labeled directed graph, where an edge

item1 --name,kind--> item2

means that:

  • item2 is available inside the scope of item1 under the name name, when kind is either internal or both, and

  • item2 is available externally from item1 under the name name, when kind is either external or both.

For example, if we have

pub mod m1 {
    pub mod m2 { }
}

then there is an edge mod m1 --m2,both--> mod m2.

Associated items are example of externally visible items (inside the declaring item they must be Self prefixed), while type parameters are examples of internally visible items. For example, for

mod m {
    pub trait<T> Trait {
        fn foo(&self) -> T;
    }
}

we have the following edges

mod m       --Trait,both-->    trait Trait
trait Trait --foo,external --> fn foo
trait Trait --T,internal -->   T

Source files are also considered nodes in the item graph, and for each source file f there is an edge f --name,both--> item when f declares item with the name name.

For imports like

mod m1 {
    mod m2;
    use m2::foo;
}

we first generate an edge mod m2 --name,kind--> f::item, where item is any item (named name) inside the imported source file f, and kind is either external or both. Using this edge, m2::foo can resolve to f::foo, which results in the edge use m2 --foo,internal--> f::foo (would have been external if it was pub use m2::foo). Lastly, all edges out of use nodes are lifted to predecessors in the graph, so we get an edge mod m1 --foo,internal--> f::foo.

References:

Import path

import codeql.rust.internal.PathResolution

Direct supertypes

Indirect supertypes

Known direct subtypes

    Predicates

    getAChild

    Gets a child item of this item, if any.

    getADescendant

    Gets an element that has this item as immediately enclosing item.

    getASuccessor

    Gets an external successor named name, if any.

    getASuccessor

    Gets a successor named name of the given kind, if any.

    getAnAttr
    getAttr
    getCanonicalPath

    Gets the canonical path of this item, if any.

    getCanonicalPathPrefix

    Gets the canonical path prefix of this node, if any.

    getCanonicalPathPrefixFor

    Gets the canonical path prefix that this node provides for child.

    getImmediateParent

    Gets the immediately enclosing item of this item, if any.

    getImmediateParentModule

    Gets the immediately enclosing module (or source file) of this item.

    getLocation

    Gets the location of this item.

    getName

    Gets the (original) name of this item.

    getNamespace

    Gets the namespace that this item belongs to, if any.

    getTypeParam

    Gets the ith type parameter of this item, if any.

    getVisibility

    Gets the visibility of this item, if any.

    hasAttr
    hasCanonicalPath

    Holds if this item has a canonical path belonging to the crate c.

    hasCanonicalPathPrefix

    Holds if this node has a canonical path prefix in crate c.

    isPublic

    Holds if this item is public.

    providesCanonicalPathPrefixFor

    Holds if this node provides a canonical path prefix for child in crate c.

    Inherited predicates

    fromSource

    Holds if this element is from source code.

    from Locatable
    getAPrimaryQlClass

    Gets the name of a primary CodeQL class to which this element belongs.

    from Element
    getFile

    Gets the primary file where this element occurs.

    from Locatable
    getPrimaryQlClasses

    Gets a comma-separated list of the names of the primary CodeQL classes to which this element belongs.

    from Element
    getResolveStep

    Gets the most immediate element that should substitute this element in the explicit AST, if any. Classes can override this to indicate this node should be in the “hidden” AST, mostly reserved for conversions and syntactic sugar nodes like parentheses.

    from Element
    isUnknownfrom Element
    resolve

    Gets the element that should substitute this element in the explicit AST, applying getResolveStep transitively.

    from Element
    toAbbreviatedString

    INTERNAL: Do not use.

    from Element
    toString

    Gets the string representation of this element.

    from Element
    toStringImpl

    INTERNAL: Do not use.

    from Element

    Charpred