diff --git a/rust/ql/integration-tests/hello-workspace/path-resolution.ql b/rust/ql/integration-tests/hello-workspace/path-resolution.ql index 9ec97b61eeb3..574a95531558 100644 --- a/rust/ql/integration-tests/hello-workspace/path-resolution.ql +++ b/rust/ql/integration-tests/hello-workspace/path-resolution.ql @@ -2,7 +2,7 @@ import rust import codeql.rust.internal.PathResolution import utils.test.PathResolutionInlineExpectationsTest -query predicate resolveDollarCrate(RelevantPath p, Crate c) { +query predicate resolveDollarCrate(PathExt p, Crate c) { c = resolvePath(p) and p.isDollarCrate() and p.fromSource() and diff --git a/rust/ql/lib/codeql/rust/controlflow/internal/Completion.qll b/rust/ql/lib/codeql/rust/controlflow/internal/Completion.qll index 0250f1cbc435..33da4db473eb 100644 --- a/rust/ql/lib/codeql/rust/controlflow/internal/Completion.qll +++ b/rust/ql/lib/codeql/rust/controlflow/internal/Completion.qll @@ -1,5 +1,6 @@ private import codeql.util.Boolean private import codeql.rust.controlflow.ControlFlowGraph +private import codeql.rust.elements.internal.VariableImpl::Impl as VariableImpl private import rust newtype TCompletion = @@ -123,13 +124,7 @@ class BooleanCompletion extends ConditionalCompletion, TBooleanCompletion { */ private predicate cannotCauseMatchFailure(Pat pat) { pat instanceof RangePat or - // Identifier patterns that are in fact path patterns can cause failures. For - // instance `None`. Only if an `@ ...` part is present can we be sure that - // it's an actual identifier pattern. As a heuristic, if the identifier starts - // with a lower case letter, then we assume that it's an identifier. This - // works for code that follows the Rust naming convention for enums and - // constants. - pat = any(IdentPat p | p.hasPat() or p.getName().getText().charAt(0).isLowercase()) or + pat = any(IdentPat p | p.hasPat() or VariableImpl::variableDecl(_, p.getName(), _)) or pat instanceof WildcardPat or pat instanceof RestPat or pat instanceof RefPat or diff --git a/rust/ql/lib/codeql/rust/elements/internal/CallImpl.qll b/rust/ql/lib/codeql/rust/elements/internal/CallImpl.qll index 210820fd1053..71c6cfbffc07 100644 --- a/rust/ql/lib/codeql/rust/elements/internal/CallImpl.qll +++ b/rust/ql/lib/codeql/rust/elements/internal/CallImpl.qll @@ -82,7 +82,7 @@ module Impl { } private predicate callHasTraitQualifier(CallExpr call, Trait qualifier) { - exists(RelevantPath qualifierPath | + exists(PathExt qualifierPath | callHasQualifier(call, _, qualifierPath) and qualifier = resolvePath(qualifierPath) and // When the qualifier is `Self` and resolves to a trait, it's inside a diff --git a/rust/ql/lib/codeql/rust/elements/internal/ConstImpl.qll b/rust/ql/lib/codeql/rust/elements/internal/ConstImpl.qll index 0234f7cf7302..44114674a566 100644 --- a/rust/ql/lib/codeql/rust/elements/internal/ConstImpl.qll +++ b/rust/ql/lib/codeql/rust/elements/internal/ConstImpl.qll @@ -5,6 +5,8 @@ */ private import codeql.rust.elements.internal.generated.Const +private import codeql.rust.elements.internal.AstNodeImpl::Impl as AstNodeImpl +private import codeql.rust.elements.internal.IdentPatImpl::Impl as IdentPatImpl private import codeql.rust.elements.internal.PathExprImpl::Impl as PathExprImpl private import codeql.rust.internal.PathResolution @@ -36,14 +38,30 @@ module Impl { * } * ``` */ - class ConstAccess extends PathExprImpl::PathExpr { + abstract class ConstAccess extends AstNodeImpl::AstNode { + /** Gets the constant being accessed. */ + abstract Const getConst(); + + override string getAPrimaryQlClass() { result = "ConstAccess" } + } + + private class PathExprConstAccess extends ConstAccess, PathExprImpl::PathExpr { private Const c; - ConstAccess() { c = resolvePath(this.getPath()) } + PathExprConstAccess() { c = resolvePath(this.getPath()) } - /** Gets the constant being accessed. */ - Const getConst() { result = c } + override Const getConst() { result = c } - override string getAPrimaryQlClass() { result = "ConstAccess" } + override string getAPrimaryQlClass() { result = ConstAccess.super.getAPrimaryQlClass() } + } + + private class IdentPatConstAccess extends ConstAccess, IdentPatImpl::IdentPat { + private Const c; + + IdentPatConstAccess() { c = resolvePath(this) } + + override Const getConst() { result = c } + + override string getAPrimaryQlClass() { result = ConstAccess.super.getAPrimaryQlClass() } } } diff --git a/rust/ql/lib/codeql/rust/elements/internal/FormatTemplateVariableAccessImpl.qll b/rust/ql/lib/codeql/rust/elements/internal/FormatTemplateVariableAccessImpl.qll index adb12a359316..35154ae0acb0 100644 --- a/rust/ql/lib/codeql/rust/elements/internal/FormatTemplateVariableAccessImpl.qll +++ b/rust/ql/lib/codeql/rust/elements/internal/FormatTemplateVariableAccessImpl.qll @@ -31,6 +31,8 @@ module Impl { override string toStringImpl() { result = this.getName() } + override string getAPrimaryQlClass() { result = "FormatTemplateVariableAccess" } + /** Gets the name of the variable */ string getName() { result = argument.getName() } diff --git a/rust/ql/lib/codeql/rust/elements/internal/PathExprImpl.qll b/rust/ql/lib/codeql/rust/elements/internal/PathExprImpl.qll index 652dc68b3c9c..cb2abc45e10c 100644 --- a/rust/ql/lib/codeql/rust/elements/internal/PathExprImpl.qll +++ b/rust/ql/lib/codeql/rust/elements/internal/PathExprImpl.qll @@ -4,6 +4,7 @@ * INTERNAL: Do not use. */ +private import rust private import codeql.rust.elements.internal.generated.PathExpr /** @@ -25,5 +26,11 @@ module Impl { override string toStringImpl() { result = this.toAbbreviatedString() } override string toAbbreviatedString() { result = this.getPath().toStringImpl() } + + override string getAPrimaryQlClass() { + if this instanceof VariableAccess + then result = "VariableAccess" + else result = super.getAPrimaryQlClass() + } } } diff --git a/rust/ql/lib/codeql/rust/elements/internal/VariableImpl.qll b/rust/ql/lib/codeql/rust/elements/internal/VariableImpl.qll index 61f022c8bfda..4569a108cd8c 100644 --- a/rust/ql/lib/codeql/rust/elements/internal/VariableImpl.qll +++ b/rust/ql/lib/codeql/rust/elements/internal/VariableImpl.qll @@ -1,8 +1,9 @@ private import rust private import codeql.rust.controlflow.ControlFlowGraph +private import codeql.rust.internal.PathResolution as PathResolution private import codeql.rust.elements.internal.generated.ParentChild as ParentChild +private import codeql.rust.elements.internal.AstNodeImpl::Impl as AstNodeImpl private import codeql.rust.elements.internal.PathImpl::Impl as PathImpl -private import codeql.rust.elements.internal.PathExprBaseImpl::Impl as PathExprBaseImpl private import codeql.rust.elements.internal.FormatTemplateVariableAccessImpl::Impl as FormatTemplateVariableAccessImpl private import codeql.util.DenseRank @@ -98,7 +99,7 @@ module Impl { * pattern. */ cached - private predicate variableDecl(AstNode definingNode, Name name, string text) { + predicate variableDecl(AstNode definingNode, Name name, string text) { Cached::ref() and exists(SelfParam sp | name = sp.getName() and @@ -117,11 +118,7 @@ module Impl { not exists(getOutermostEnclosingOrPat(pat)) and definingNode = name ) and text = name.getText() and - // exclude for now anything starting with an uppercase character, which may be a reference to - // an enum constant (e.g. `None`). This excludes static and constant variables (UPPERCASE), - // which we don't appear to recognize yet anyway. This also assumes programmers follow the - // naming guidelines, which they generally do, but they're not enforced. - not text.charAt(0).isUppercase() and + not PathResolution::identPatIsResolvable(pat) and // exclude parameters from functions without a body as these are trait method declarations // without implementations not exists(Function f | not f.hasBody() and f.getAParam().getPat() = pat) and @@ -666,7 +663,7 @@ module Impl { } /** A variable access. */ - class VariableAccess extends PathExprBaseImpl::PathExprBase { + class VariableAccess extends PathExprBase { private string name; private Variable v; @@ -677,10 +674,6 @@ module Impl { /** Holds if this access is a capture. */ predicate isCapture() { this.getEnclosingCfgScope() != v.getEnclosingCfgScope() } - - override string toStringImpl() { result = name } - - override string getAPrimaryQlClass() { result = "VariableAccess" } } /** Holds if `e` occurs in the LHS of an assignment or compound assignment. */ @@ -722,7 +715,7 @@ module Impl { } /** A nested function access. */ - class NestedFunctionAccess extends PathExprBaseImpl::PathExprBase { + class NestedFunctionAccess extends PathExprBase { private Function f; NestedFunctionAccess() { nestedFunctionAccess(_, f, this) } diff --git a/rust/ql/lib/codeql/rust/internal/CachedStages.qll b/rust/ql/lib/codeql/rust/internal/CachedStages.qll index 132b9ec8f7e8..dc80fc09dad9 100644 --- a/rust/ql/lib/codeql/rust/internal/CachedStages.qll +++ b/rust/ql/lib/codeql/rust/internal/CachedStages.qll @@ -115,13 +115,11 @@ module Stages { predicate backref() { 1 = 1 or - exists(resolvePath(_)) + exists(resolvePathIgnoreVariableShadowing(_)) or exists(any(ItemNode i).getASuccessor(_, _, _)) or exists(any(ImplOrTraitItemNode i).getASelfPath()) - or - any(TypeParamItemNode i).hasTraitBound() } } diff --git a/rust/ql/lib/codeql/rust/internal/Definitions.qll b/rust/ql/lib/codeql/rust/internal/Definitions.qll index b1b3e475c468..60520a77cbf5 100644 --- a/rust/ql/lib/codeql/rust/internal/Definitions.qll +++ b/rust/ql/lib/codeql/rust/internal/Definitions.qll @@ -37,6 +37,9 @@ private module Cached { TFormatArgsArgIndex(Expr e) { e = any(FormatArgsArg a).getExpr() } or TItemNode(ItemNode i) + pragma[nomagic] + private predicate isMacroCallLocation(Location loc) { loc = any(MacroCall m).getLocation() } + /** * Gets an element, of kind `kind`, that element `use` uses, if any. */ @@ -44,7 +47,7 @@ private module Cached { Definition definitionOf(Use use, string kind) { result = use.getDefinition() and kind = use.getUseType() and - not result.getLocation() = any(MacroCall m).getLocation() + not isMacroCallLocation(result.getLocation()) } } diff --git a/rust/ql/lib/codeql/rust/internal/PathResolution.qll b/rust/ql/lib/codeql/rust/internal/PathResolution.qll index 0933f2dcd958..f7981c846abb 100644 --- a/rust/ql/lib/codeql/rust/internal/PathResolution.qll +++ b/rust/ql/lib/codeql/rust/internal/PathResolution.qll @@ -1,9 +1,49 @@ /** * Provides functionality for resolving paths, using the predicate `resolvePath`. + * + * Path resolution needs to happen before variable resolution, because otherwise + * we cannot know whether an identifier pattern binds a new variable or whether it + * refers to a constructor: + * + * ```rust + * let x = ...; // `x` is only a variable if it does not resolve to a constructor + * ``` + * + * Even though variable names typically start with a lowercase letter and constructors + * with an uppercase letter, this is not enforced by the Rust language. + * + * Variables may shadow declarations, so variable resolution also needs to affect + * path resolution: + * + * ```rust + * fn foo() {} // (1) + * + * fn bar() { + * let f = foo; // `foo` here refers to (1) via path resolution + * let foo = f(); // (2) + * foo // `foo` here refers to (2) via variable resolution + * } + * ``` + * + * So it may seem that path resolution and variable resolution must happen in mutual + * recursion, but we would like to keep the inherently global path resolution logic + * separate from the inherently local variable resolution logic. We acheive this by + * + * - First computing global path resolution, where variable shadowing is ignored, + * exposed as the internal predicate `resolvePathIgnoreVariableShadowing`. + * - `resolvePathIgnoreVariableShadowing` is sufficient to determine whether an + * identifier pattern resolves to a constructor, since if it does, it cannot be + * shadowed by a variable. We expose this as the predicate `identPatIsResolvable`. + * - Variable resolution can then be computed as a local property, using only the + * global information from `identPatIsResolvable`. + * - Finally, path resolution can be computed by restricting + * `resolvePathIgnoreVariableShadowing` to paths that are not resolvable via + * variable resolution. */ private import rust private import codeql.rust.elements.internal.generated.ParentChild +private import codeql.rust.elements.internal.AstNodeImpl::Impl as AstNodeImpl 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 @@ -184,7 +224,7 @@ abstract class ItemNode extends Locatable { pragma[nomagic] final Attr getAttr(string name) { result = this.getAnAttr() and - result.getMeta().getPath().(RelevantPath).isUnqualified(name) + result.getMeta().getPath().(PathExt).isUnqualified(name) } final predicate hasAttr(string name) { exists(this.getAttr(name)) } @@ -1134,34 +1174,6 @@ final class TypeParamItemNode extends TypeItemNode instanceof TypeParam { ItemNode resolveABound() { result = resolvePath(this.getABoundPath()) } - /** - * Holds if this type parameter has a trait bound. Examples: - * - * ```rust - * impl Foo { ... } // has no trait bound - * - * impl Foo { ... } // has trait bound - * - * impl Foo where T: Trait { ... } // has trait bound - * ``` - */ - cached - predicate hasTraitBound() { Stages::PathResolutionStage::ref() and exists(this.getABoundPath()) } - - /** - * Holds if this type parameter has no trait bound. Examples: - * - * ```rust - * impl Foo { ... } // has no trait bound - * - * impl Foo { ... } // has trait bound - * - * impl Foo where T: Trait { ... } // has trait bound - * ``` - */ - pragma[nomagic] - predicate hasNoTraitBound() { not this.hasTraitBound() } - override string getName() { result = TypeParam.super.getName().getText() } override Namespace getNamespace() { result.isType() } @@ -1500,20 +1512,22 @@ private predicate declares(ItemNode item, Namespace ns, string name) { ) } -/** A path that does not access a local variable. */ -class RelevantPath extends Path { - RelevantPath() { not this = any(VariableAccess va).(PathExpr).getPath() } +/** + * A `Path` or an `IdentPat`. + * + * `IdentPat`s are included in order to resolve unqualified references to + * constructors in patterns. + */ +abstract class PathExt extends AstNode { + abstract string getText(); /** Holds if this is an unqualified path with the textual value `name`. */ pragma[nomagic] - predicate isUnqualified(string name) { - not exists(this.getQualifier()) and - not exists(UseTree tree | - tree.hasPath() and - this = getAUseTreeUseTree(tree).getPath().getQualifier*() - ) and - name = this.getText() - } + abstract predicate isUnqualified(string name); + + abstract Path getQualifier(); + + abstract string toStringDebug(); /** * Holds if this is an unqualified path with the textual value `name` and @@ -1535,6 +1549,33 @@ class RelevantPath extends Path { predicate isDollarCrate() { this.isUnqualified("$crate", _) } } +private class PathExtPath extends PathExt instanceof Path { + override string getText() { result = Path.super.getText() } + + override predicate isUnqualified(string name) { + not exists(Path.super.getQualifier()) and + not exists(UseTree tree | + tree.hasPath() and + this = getAUseTreeUseTree(tree).getPath().getQualifier*() + ) and + name = Path.super.getText() + } + + override Path getQualifier() { result = Path.super.getQualifier() } + + override string toStringDebug() { result = Path.super.toStringDebug() } +} + +private class PathExtIdentPat extends PathExt, IdentPat { + override string getText() { result = this.getName().getText() } + + override predicate isUnqualified(string name) { name = this.getText() } + + override Path getQualifier() { none() } + + override string toStringDebug() { result = this.getText() } +} + private predicate isModule(ItemNode m) { m instanceof Module } /** Holds if source file `source` contains the module `m`. */ @@ -1558,7 +1599,7 @@ private ItemNode getOuterScope(ItemNode i) { pragma[nomagic] private predicate unqualifiedPathLookup(ItemNode ancestor, string name, Namespace ns, ItemNode encl) { // lookup in the immediately enclosing item - exists(RelevantPath path | + exists(PathExt path | path.isUnqualified(name, encl) and ancestor = encl and not name = ["crate", "$crate", "super", "self"] @@ -1594,7 +1635,7 @@ private ItemNode getASuccessor( private predicate isSourceFile(ItemNode source) { source instanceof SourceFileItemNode } -private predicate hasCratePath(ItemNode i) { any(RelevantPath path).isCratePath(_, i) } +private predicate hasCratePath(ItemNode i) { any(PathExt path).isCratePath(_, i) } private predicate hasChild(ItemNode parent, ItemNode child) { child.getImmediateParent() = parent } @@ -1606,7 +1647,7 @@ private predicate sourceFileHasCratePathTc(ItemNode i1, ItemNode i2) = * `name` may be looked up inside `ancestor`. */ pragma[nomagic] -private predicate keywordLookup(ItemNode ancestor, string name, RelevantPath p) { +private predicate keywordLookup(ItemNode ancestor, string name, PathExt p) { // For `crate`, jump directly to the root module exists(ItemNode i | p.isCratePath(name, i) | ancestor instanceof SourceFile and @@ -1620,7 +1661,7 @@ private predicate keywordLookup(ItemNode ancestor, string name, RelevantPath p) } pragma[nomagic] -private ItemNode unqualifiedPathLookup(RelevantPath p, Namespace ns, SuccessorKind kind) { +private ItemNode unqualifiedPathLookup(PathExt p, Namespace ns, SuccessorKind kind) { exists(ItemNode ancestor, string name | result = getASuccessor(ancestor, pragma[only_bind_into](name), ns, kind, _) and kind.isInternalOrBoth() @@ -1635,7 +1676,7 @@ private ItemNode unqualifiedPathLookup(RelevantPath p, Namespace ns, SuccessorKi } pragma[nomagic] -private predicate isUnqualifiedSelfPath(RelevantPath path) { path.isUnqualified("Self") } +private predicate isUnqualifiedSelfPath(PathExt path) { path.isUnqualified("Self") } /** Provides the input to `TraitIsVisible`. */ signature predicate relevantTraitVisibleSig(Element element, Trait trait); @@ -1718,14 +1759,14 @@ private module DollarCrateResolution { isDollarCrateSupportedMacroExpansion(_, expansion) } - private predicate isDollarCratePath(RelevantPath p) { p.isDollarCrate() } + private predicate isDollarCratePath(PathExt p) { p.isDollarCrate() } - private predicate isInDollarCrateMacroExpansion(RelevantPath p, AstNode expansion) = + private predicate isInDollarCrateMacroExpansion(PathExt p, AstNode expansion) = doublyBoundedFastTC(hasParent/2, isDollarCratePath/1, isDollarCrateSupportedMacroExpansion/1)(p, expansion) pragma[nomagic] - private predicate isInDollarCrateMacroExpansionFromFile(File macroDefFile, RelevantPath p) { + private predicate isInDollarCrateMacroExpansionFromFile(File macroDefFile, PathExt p) { exists(Path macroDefPath, AstNode expansion | isDollarCrateSupportedMacroExpansion(macroDefPath, expansion) and isInDollarCrateMacroExpansion(p, expansion) and @@ -1740,17 +1781,17 @@ private module DollarCrateResolution { * calls. */ pragma[nomagic] - predicate resolveDollarCrate(RelevantPath p, CrateItemNode crate) { + predicate resolveDollarCrate(PathExt p, CrateItemNode crate) { isInDollarCrateMacroExpansionFromFile(crate.getASourceFile().getFile(), p) } } pragma[nomagic] -private ItemNode resolvePathCand0(RelevantPath path, Namespace ns) { +private ItemNode resolvePathCand0(PathExt path, Namespace ns) { exists(ItemNode res | res = unqualifiedPathLookup(path, ns, _) and if - not any(RelevantPath parent).getQualifier() = path and + not any(PathExt parent).getQualifier() = path and isUnqualifiedSelfPath(path) and res instanceof ImplItemNode then result = res.(ImplItemNodeImpl).resolveSelfTyCand() @@ -1767,7 +1808,7 @@ private ItemNode resolvePathCand0(RelevantPath path, Namespace ns) { } pragma[nomagic] -private ItemNode resolvePathCandQualifier(RelevantPath qualifier, RelevantPath path, string name) { +private ItemNode resolvePathCandQualifier(PathExt qualifier, PathExt path, string name) { qualifier = path.getQualifier() and result = resolvePathCand(qualifier) and name = path.getText() @@ -1815,9 +1856,7 @@ private predicate checkQualifiedVisibility( * qualifier of `path` and `qualifier` resolves to `q`, if any. */ pragma[nomagic] -private ItemNode resolvePathCandQualified( - RelevantPath qualifier, ItemNode q, RelevantPath path, Namespace ns -) { +private ItemNode resolvePathCandQualified(PathExt qualifier, ItemNode q, PathExt path, Namespace ns) { exists(string name, SuccessorKind kind, UseOption useOpt | q = resolvePathCandQualifier(qualifier, path, name) and result = getASuccessor(q, name, ns, kind, useOpt) and @@ -1826,12 +1865,14 @@ private ItemNode resolvePathCandQualified( } /** Holds if path `p` must be looked up in namespace `n`. */ -private predicate pathUsesNamespace(Path p, Namespace n) { +private predicate pathUsesNamespace(PathExt p, Namespace n) { n.isValue() and ( p = any(PathExpr pe).getPath() or p = any(TupleStructPat tsp).getPath() + or + p instanceof PathExtIdentPat ) or n.isType() and @@ -1907,7 +1948,7 @@ private predicate macroUseEdge( * result in non-monotonic recursion. */ pragma[nomagic] -private ItemNode resolvePathCand(RelevantPath path) { +private ItemNode resolvePathCand(PathExt path) { exists(Namespace ns | result = resolvePathCand0(path, ns) and if path = any(ImplItemNode i).getSelfPath() @@ -1920,7 +1961,13 @@ private ItemNode resolvePathCand(RelevantPath path) { else if path = any(PathTypeRepr p).getPath() then result instanceof TypeItemNode - else any() + else + if path instanceof IdentPat + then + result instanceof VariantItemNode or + result instanceof StructItemNode or + result instanceof ConstItemNode + else any() | pathUsesNamespace(path, ns) or @@ -1937,7 +1984,7 @@ private ItemNode resolvePathCand(RelevantPath path) { } /** Get a trait that should be visible when `path` resolves to `node`, if any. */ -private Trait getResolvePathTraitUsed(RelevantPath path, AssocItemNode node) { +private Trait getResolvePathTraitUsed(PathExt path, AssocItemNode node) { exists(TypeItemNode type, ImplItemNodeImpl impl | node = resolvePathCandQualified(_, type, path, _) and typeImplEdge(type, impl, _, _, node, _) and @@ -1949,9 +1996,9 @@ private predicate pathTraitUsed(Element path, Trait trait) { trait = getResolvePathTraitUsed(path, _) } -/** Gets the item that `path` resolves to, if any. */ +/** INTERNAL: Do not use; use `resolvePath` instead. */ cached -ItemNode resolvePath(RelevantPath path) { +ItemNode resolvePathIgnoreVariableShadowing(PathExt path) { result = resolvePathCand(path) and not path = any(Path parent | exists(resolvePathCand(parent))).getQualifier() and ( @@ -1964,29 +2011,43 @@ ItemNode resolvePath(RelevantPath path) { or // if `path` is the qualifier of a resolvable `parent`, then we should // resolve `path` to something consistent with what `parent` resolves to - exists(RelevantPath parent | - resolvePathCandQualified(path, result, parent, _) = resolvePath(parent) + exists(PathExt parent | + resolvePathCandQualified(path, result, parent, _) = resolvePathIgnoreVariableShadowing(parent) ) } -private predicate isUseTreeSubPath(UseTree tree, RelevantPath path) { +/** + * Holds if `ip` resolves to some constructor. + */ +// use `forceLocal` once we implement overlay support +pragma[nomagic] +predicate identPatIsResolvable(IdentPat ip) { exists(resolvePathIgnoreVariableShadowing(ip)) } + +/** Gets the item that `path` resolves to, if any. */ +pragma[nomagic] +ItemNode resolvePath(PathExt path) { + result = resolvePathIgnoreVariableShadowing(path) and + not path = any(VariableAccess va).(PathExpr).getPath() +} + +private predicate isUseTreeSubPath(UseTree tree, PathExt path) { path = tree.getPath() or - exists(RelevantPath mid | + exists(PathExt mid | isUseTreeSubPath(tree, mid) and path = mid.getQualifier() ) } pragma[nomagic] -private predicate isUseTreeSubPathUnqualified(UseTree tree, RelevantPath path, string name) { +private predicate isUseTreeSubPathUnqualified(UseTree tree, PathExt path, string name) { isUseTreeSubPath(tree, path) and not exists(path.getQualifier()) and name = path.getText() } pragma[nomagic] -private ItemNode resolveUseTreeListItem(Use use, UseTree tree, RelevantPath path, SuccessorKind kind) { +private ItemNode resolveUseTreeListItem(Use use, UseTree tree, PathExt path, SuccessorKind kind) { exists(UseOption useOpt | checkQualifiedVisibility(use, result, kind, useOpt) | exists(UseTree midTree, ItemNode mid, string name | mid = resolveUseTreeListItem(use, midTree) and @@ -2003,9 +2064,7 @@ private ItemNode resolveUseTreeListItem(Use use, UseTree tree, RelevantPath path } pragma[nomagic] -private ItemNode resolveUseTreeListItemQualifier( - Use use, UseTree tree, RelevantPath path, string name -) { +private ItemNode resolveUseTreeListItemQualifier(Use use, UseTree tree, PathExt path, string name) { result = resolveUseTreeListItem(use, tree, path.getQualifier(), _) and name = path.getText() } @@ -2156,7 +2215,7 @@ private module Debug { } predicate debugUnqualifiedPathLookup( - RelevantPath p, string name, Namespace ns, ItemNode ancestor, string path + PathExt p, string name, Namespace ns, ItemNode ancestor, string path ) { p = getRelevantLocatable() and exists(ItemNode encl | @@ -2166,14 +2225,19 @@ private module Debug { path = p.toStringDebug() } + ItemNode debugUnqualifiedPathLookup(PathExt p, Namespace ns, SuccessorKind kind) { + p = getRelevantLocatable() and + result = unqualifiedPathLookup(p, ns, kind) + } + predicate debugItemNode(ItemNode item) { item = getRelevantLocatable() } - ItemNode debugResolvePath(RelevantPath path) { + ItemNode debugResolvePath(PathExt path) { path = getRelevantLocatable() and result = resolvePath(path) } - ItemNode debugResolveUseTreeListItem(Use use, UseTree tree, RelevantPath path, SuccessorKind kind) { + ItemNode debugResolveUseTreeListItem(Use use, UseTree tree, PathExt path, SuccessorKind kind) { use = getRelevantLocatable() and result = resolveUseTreeListItem(use, tree, path, kind) } diff --git a/rust/ql/test/extractor-tests/macro-expansion/PrintAst.expected b/rust/ql/test/extractor-tests/macro-expansion/PrintAst.expected index 1a0ded6950d3..5174e0bd6186 100644 --- a/rust/ql/test/extractor-tests/macro-expansion/PrintAst.expected +++ b/rust/ql/test/extractor-tests/macro-expansion/PrintAst.expected @@ -660,7 +660,7 @@ macro_expansion.rs: # 71| getSegment(): [PathSegment] i32 # 71| getIdentifier(): [NameRef] i32 # 72| getTailExpr(): [CastExpr] a as ... -# 72| getExpr(): [PathExpr,VariableAccess] a +# 72| getExpr(): [VariableAccess] a # 72| getPath(): [Path] a # 72| getSegment(): [PathSegment] a # 72| getIdentifier(): [NameRef] a @@ -738,7 +738,7 @@ macro_expansion.rs: # 84| getFunctionBody(): [BlockExpr] { ... } # 84| getStmtList(): [StmtList] StmtList # 84| getTailExpr(): [MatchExpr] match self { ... } -# 83| getScrutinee(): [PathExpr,VariableAccess] self +# 83| getScrutinee(): [VariableAccess] self # 83| getPath(): [Path] self # 83| getSegment(): [PathSegment] self # 83| getIdentifier(): [NameRef] self @@ -751,7 +751,7 @@ macro_expansion.rs: # 85| getArgList(): [ArgList] ArgList # 83| getArg(0): [StringLiteralExpr] "field" # 85| getArg(1): [RefExpr] &field -# 85| getExpr(): [PathExpr,VariableAccess] field +# 85| getExpr(): [VariableAccess] field # 85| getPath(): [Path] field # 85| getSegment(): [PathSegment] field # 85| getIdentifier(): [NameRef] field @@ -760,7 +760,7 @@ macro_expansion.rs: # 83| getArgList(): [ArgList] ArgList # 83| getArg(0): [StringLiteralExpr] "MyDerive" # 83| getIdentifier(): [NameRef] debug_struct -# 83| getReceiver(): [PathExpr,VariableAccess] f +# 83| getReceiver(): [VariableAccess] f # 83| getPath(): [Path] f # 83| getSegment(): [PathSegment] f # 83| getIdentifier(): [NameRef] f @@ -836,11 +836,11 @@ macro_expansion.rs: # 89| getStmtList(): [StmtList] StmtList # 89| getTailExpr(): [MatchExpr] match ... { ... } # 88| getScrutinee(): [TupleExpr] TupleExpr -# 88| getField(0): [PathExpr,VariableAccess] self +# 88| getField(0): [VariableAccess] self # 88| getPath(): [Path] self # 88| getSegment(): [PathSegment] self # 88| getIdentifier(): [NameRef] self -# 88| getField(1): [PathExpr,VariableAccess] other +# 88| getField(1): [VariableAccess] other # 88| getPath(): [Path] other # 88| getSegment(): [PathSegment] other # 88| getIdentifier(): [NameRef] other @@ -1076,7 +1076,7 @@ proc_macro.rs: # 6| getMacroCallExpansion(): [MatchExpr] match ... { ... } # 6| getScrutinee(): [CallExpr] ...::parse::<...>(...) # 6| getArgList(): [ArgList] ArgList -# 6| getArg(0): [PathExpr,VariableAccess] attr +# 6| getArg(0): [VariableAccess] attr # 6| getPath(): [Path] attr # 6| getSegment(): [PathSegment] attr # 6| getIdentifier(): [NameRef] attr @@ -1098,7 +1098,7 @@ proc_macro.rs: # 6| getIdentifier(): [NameRef] parse # 6| getMatchArmList(): [MatchArmList] MatchArmList # 6| getArm(0): [MatchArm] ... => data -# 6| getExpr(): [PathExpr,VariableAccess] data +# 6| getExpr(): [VariableAccess] data # 6| getPath(): [Path] data # 6| getSegment(): [PathSegment] data # 6| getIdentifier(): [NameRef] data @@ -1124,7 +1124,7 @@ proc_macro.rs: # 6| getArg(0): [MethodCallExpr] err.to_compile_error() # 6| getArgList(): [ArgList] ArgList # 6| getIdentifier(): [NameRef] to_compile_error -# 6| getReceiver(): [PathExpr,VariableAccess] err +# 6| getReceiver(): [VariableAccess] err # 6| getPath(): [Path] err # 6| getSegment(): [PathSegment] err # 6| getIdentifier(): [NameRef] err @@ -1168,7 +1168,7 @@ proc_macro.rs: # 7| getMacroCallExpansion(): [MatchExpr] match ... { ... } # 7| getScrutinee(): [CallExpr] ...::parse::<...>(...) # 7| getArgList(): [ArgList] ArgList -# 7| getArg(0): [PathExpr,VariableAccess] item +# 7| getArg(0): [VariableAccess] item # 7| getPath(): [Path] item # 7| getSegment(): [PathSegment] item # 7| getIdentifier(): [NameRef] item @@ -1190,7 +1190,7 @@ proc_macro.rs: # 7| getIdentifier(): [NameRef] parse # 7| getMatchArmList(): [MatchArmList] MatchArmList # 7| getArm(0): [MatchArm] ... => data -# 7| getExpr(): [PathExpr,VariableAccess] data +# 7| getExpr(): [VariableAccess] data # 7| getPath(): [Path] data # 7| getSegment(): [PathSegment] data # 7| getIdentifier(): [NameRef] data @@ -1216,7 +1216,7 @@ proc_macro.rs: # 7| getArg(0): [MethodCallExpr] err.to_compile_error() # 7| getArgList(): [ArgList] ArgList # 7| getIdentifier(): [NameRef] to_compile_error -# 7| getReceiver(): [PathExpr,VariableAccess] err +# 7| getReceiver(): [VariableAccess] err # 7| getPath(): [Path] err # 7| getSegment(): [PathSegment] err # 7| getIdentifier(): [NameRef] err @@ -1273,7 +1273,7 @@ proc_macro.rs: # 10| getInitializer(): [MethodCallExpr] ast.clone() # 10| getArgList(): [ArgList] ArgList # 10| getIdentifier(): [NameRef] clone -# 10| getReceiver(): [PathExpr,VariableAccess] ast +# 10| getReceiver(): [VariableAccess] ast # 10| getPath(): [Path] ast # 10| getSegment(): [PathSegment] ast # 10| getIdentifier(): [NameRef] ast @@ -1283,7 +1283,7 @@ proc_macro.rs: # 11| getExpr(): [AssignmentExpr] ... = ... # 11| getLhs(): [FieldExpr] ... .ident # 11| getContainer(): [FieldExpr] new_ast.sig -# 11| getContainer(): [PathExpr,VariableAccess] new_ast +# 11| getContainer(): [VariableAccess] new_ast # 11| getPath(): [Path] new_ast # 11| getSegment(): [PathSegment] new_ast # 11| getIdentifier(): [NameRef] new_ast @@ -1320,14 +1320,14 @@ proc_macro.rs: # 11| getArg(0): [FormatArgsArg] FormatArgsArg # 11| getExpr(): [FieldExpr] ... .ident # 11| getContainer(): [FieldExpr] ast.sig -# 11| getContainer(): [PathExpr,VariableAccess] ast +# 11| getContainer(): [VariableAccess] ast # 11| getPath(): [Path] ast # 11| getSegment(): [PathSegment] ast # 11| getIdentifier(): [NameRef] ast # 11| getIdentifier(): [NameRef] sig # 11| getIdentifier(): [NameRef] ident # 11| getArg(1): [FormatArgsArg] FormatArgsArg -# 11| getExpr(): [PathExpr,VariableAccess] i +# 11| getExpr(): [VariableAccess] i # 11| getPath(): [Path] i # 11| getSegment(): [PathSegment] i # 11| getIdentifier(): [NameRef] i @@ -1359,7 +1359,7 @@ proc_macro.rs: # 11| getIdentifier(): [NameRef] span # 11| getReceiver(): [FieldExpr] ... .ident # 11| getContainer(): [FieldExpr] ast.sig -# 11| getContainer(): [PathExpr,VariableAccess] ast +# 11| getContainer(): [VariableAccess] ast # 11| getPath(): [Path] ast # 11| getSegment(): [PathSegment] ast # 11| getIdentifier(): [NameRef] ast @@ -1375,14 +1375,14 @@ proc_macro.rs: # 11| getIdentifier(): [NameRef] Ident # 11| getSegment(): [PathSegment] new # 11| getIdentifier(): [NameRef] new -# 12| getTailExpr(): [PathExpr,VariableAccess] new_ast +# 12| getTailExpr(): [VariableAccess] new_ast # 12| getPath(): [Path] new_ast # 12| getSegment(): [PathSegment] new_ast # 12| getIdentifier(): [NameRef] new_ast # 9| getIdentifier(): [NameRef] map # 8| getReceiver(): [ParenExpr] (...) # 8| getExpr(): [RangeExpr] 0..number -# 8| getEnd(): [PathExpr,VariableAccess] number +# 8| getEnd(): [VariableAccess] number # 8| getPath(): [Path] number # 8| getSegment(): [PathSegment] number # 8| getIdentifier(): [NameRef] number @@ -1614,7 +1614,7 @@ proc_macro.rs: # 16| getInitializer(): [MethodCallExpr] items.quote_into_iter() # 15| getArgList(): [ArgList] ArgList # 15| getIdentifier(): [NameRef] quote_into_iter -# 16| getReceiver(): [PathExpr,VariableAccess] items +# 16| getReceiver(): [VariableAccess] items # 16| getPath(): [Path] items # 16| getSegment(): [PathSegment] items # 16| getIdentifier(): [NameRef] items @@ -1625,11 +1625,11 @@ proc_macro.rs: # 15| getName(): [Name] i # 15| getStatement(1): [LetStmt] let ... = ... # 15| getInitializer(): [BinaryExpr] ... | ... -# 15| getLhs(): [PathExpr,VariableAccess] has_iter +# 15| getLhs(): [VariableAccess] has_iter # 15| getPath(): [Path] has_iter # 15| getSegment(): [PathSegment] has_iter # 15| getIdentifier(): [NameRef] has_iter -# 15| getRhs(): [PathExpr,VariableAccess] i +# 15| getRhs(): [VariableAccess] i # 15| getPath(): [Path] i # 15| getSegment(): [PathSegment] i # 15| getIdentifier(): [NameRef] i @@ -1646,7 +1646,7 @@ proc_macro.rs: # 16| getTokenTree(): [TokenTree] TokenTree # 15| getMacroCallExpansion(): [MacroBlockExpr] MacroBlockExpr # 15| getStatement(3): [LetStmt] let _ = has_iter -# 15| getInitializer(): [PathExpr,VariableAccess] has_iter +# 15| getInitializer(): [VariableAccess] has_iter # 15| getPath(): [Path] has_iter # 15| getSegment(): [PathSegment] has_iter # 15| getIdentifier(): [NameRef] has_iter @@ -1764,7 +1764,7 @@ proc_macro.rs: # 16| getScrutinee(): [MethodCallExpr] items.next() # 15| getArgList(): [ArgList] ArgList # 15| getIdentifier(): [NameRef] next -# 16| getReceiver(): [PathExpr,VariableAccess] items +# 16| getReceiver(): [VariableAccess] items # 16| getPath(): [Path] items # 16| getSegment(): [PathSegment] items # 16| getIdentifier(): [NameRef] items @@ -1772,7 +1772,7 @@ proc_macro.rs: # 15| getArm(0): [MatchArm] ... => ... # 15| getExpr(): [CallExpr] ...::RepInterp(...) # 15| getArgList(): [ArgList] ArgList -# 15| getArg(0): [PathExpr] _x +# 15| getArg(0): [VariableAccess] _x # 15| getPath(): [Path] _x # 15| getSegment(): [PathSegment] _x # 15| getIdentifier(): [NameRef] _x @@ -1876,12 +1876,12 @@ proc_macro.rs: # 16| getExpr(): [CallExpr] ...::to_tokens(...) # 16| getArgList(): [ArgList] ArgList # 16| getArg(0): [RefExpr] &items -# 16| getExpr(): [PathExpr,VariableAccess] items +# 16| getExpr(): [VariableAccess] items # 16| getPath(): [Path] items # 16| getSegment(): [PathSegment] items # 16| getIdentifier(): [NameRef] items # 15| getArg(1): [RefExpr] &mut _s -# 15| getExpr(): [PathExpr] _s +# 15| getExpr(): [VariableAccess] _s # 15| getPath(): [Path] _s # 15| getSegment(): [PathSegment] _s # 15| getIdentifier(): [NameRef] _s @@ -1993,7 +1993,7 @@ proc_macro.rs: # 15| getIdentifier(): [NameRef] quote_token_with_context # 16| getTokenTree(): [TokenTree] TokenTree # 15| getMacroCallExpansion(): [MacroBlockExpr] MacroBlockExpr -# 15| getTailExpr(): [PathExpr] _s +# 15| getTailExpr(): [VariableAccess] _s # 15| getPath(): [Path] _s # 15| getSegment(): [PathSegment] _s # 15| getIdentifier(): [NameRef] _s @@ -2040,7 +2040,7 @@ proc_macro.rs: # 22| getMacroCallExpansion(): [MatchExpr] match ... { ... } # 22| getScrutinee(): [CallExpr] ...::parse::<...>(...) # 22| getArgList(): [ArgList] ArgList -# 22| getArg(0): [PathExpr,VariableAccess] item +# 22| getArg(0): [VariableAccess] item # 22| getPath(): [Path] item # 22| getSegment(): [PathSegment] item # 22| getIdentifier(): [NameRef] item @@ -2062,7 +2062,7 @@ proc_macro.rs: # 22| getIdentifier(): [NameRef] parse # 22| getMatchArmList(): [MatchArmList] MatchArmList # 22| getArm(0): [MatchArm] ... => data -# 22| getExpr(): [PathExpr,VariableAccess] data +# 22| getExpr(): [VariableAccess] data # 22| getPath(): [Path] data # 22| getSegment(): [PathSegment] data # 22| getIdentifier(): [NameRef] data @@ -2088,7 +2088,7 @@ proc_macro.rs: # 22| getArg(0): [MethodCallExpr] err.to_compile_error() # 22| getArgList(): [ArgList] ArgList # 22| getIdentifier(): [NameRef] to_compile_error -# 22| getReceiver(): [PathExpr,VariableAccess] err +# 22| getReceiver(): [VariableAccess] err # 22| getPath(): [Path] err # 22| getSegment(): [PathSegment] err # 22| getIdentifier(): [NameRef] err @@ -2123,7 +2123,7 @@ proc_macro.rs: # 23| getInitializer(): [MethodCallExpr] ast.clone() # 23| getArgList(): [ArgList] ArgList # 23| getIdentifier(): [NameRef] clone -# 23| getReceiver(): [PathExpr,VariableAccess] ast +# 23| getReceiver(): [VariableAccess] ast # 23| getPath(): [Path] ast # 23| getSegment(): [PathSegment] ast # 23| getIdentifier(): [NameRef] ast @@ -2133,7 +2133,7 @@ proc_macro.rs: # 24| getExpr(): [AssignmentExpr] ... = ... # 24| getLhs(): [FieldExpr] ... .ident # 24| getContainer(): [FieldExpr] new_ast.sig -# 24| getContainer(): [PathExpr,VariableAccess] new_ast +# 24| getContainer(): [VariableAccess] new_ast # 24| getPath(): [Path] new_ast # 24| getSegment(): [PathSegment] new_ast # 24| getIdentifier(): [NameRef] new_ast @@ -2170,7 +2170,7 @@ proc_macro.rs: # 24| getArg(0): [FormatArgsArg] FormatArgsArg # 24| getExpr(): [FieldExpr] ... .ident # 24| getContainer(): [FieldExpr] ast.sig -# 24| getContainer(): [PathExpr,VariableAccess] ast +# 24| getContainer(): [VariableAccess] ast # 24| getPath(): [Path] ast # 24| getSegment(): [PathSegment] ast # 24| getIdentifier(): [NameRef] ast @@ -2203,7 +2203,7 @@ proc_macro.rs: # 24| getIdentifier(): [NameRef] span # 24| getReceiver(): [FieldExpr] ... .ident # 24| getContainer(): [FieldExpr] ast.sig -# 24| getContainer(): [PathExpr,VariableAccess] ast +# 24| getContainer(): [VariableAccess] ast # 24| getPath(): [Path] ast # 24| getSegment(): [PathSegment] ast # 24| getIdentifier(): [NameRef] ast @@ -2317,12 +2317,12 @@ proc_macro.rs: # 26| getExpr(): [CallExpr] ...::to_tokens(...) # 26| getArgList(): [ArgList] ArgList # 26| getArg(0): [RefExpr] &ast -# 26| getExpr(): [PathExpr,VariableAccess] ast +# 26| getExpr(): [VariableAccess] ast # 26| getPath(): [Path] ast # 26| getSegment(): [PathSegment] ast # 26| getIdentifier(): [NameRef] ast # 25| getArg(1): [RefExpr] &mut _s -# 25| getExpr(): [PathExpr] _s +# 25| getExpr(): [VariableAccess] _s # 25| getPath(): [Path] _s # 25| getSegment(): [PathSegment] _s # 25| getIdentifier(): [NameRef] _s @@ -2362,12 +2362,12 @@ proc_macro.rs: # 27| getExpr(): [CallExpr] ...::to_tokens(...) # 27| getArgList(): [ArgList] ArgList # 27| getArg(0): [RefExpr] &new_ast -# 27| getExpr(): [PathExpr,VariableAccess] new_ast +# 27| getExpr(): [VariableAccess] new_ast # 27| getPath(): [Path] new_ast # 27| getSegment(): [PathSegment] new_ast # 27| getIdentifier(): [NameRef] new_ast # 25| getArg(1): [RefExpr] &mut _s -# 25| getExpr(): [PathExpr] _s +# 25| getExpr(): [VariableAccess] _s # 25| getPath(): [Path] _s # 25| getSegment(): [PathSegment] _s # 25| getIdentifier(): [NameRef] _s @@ -2424,7 +2424,7 @@ proc_macro.rs: # 25| getIdentifier(): [NameRef] quote_token_with_context # 27| getTokenTree(): [TokenTree] TokenTree # 25| getMacroCallExpansion(): [MacroBlockExpr] MacroBlockExpr -# 25| getTailExpr(): [PathExpr] _s +# 25| getTailExpr(): [VariableAccess] _s # 25| getPath(): [Path] _s # 25| getSegment(): [PathSegment] _s # 25| getIdentifier(): [NameRef] _s @@ -2504,7 +2504,7 @@ proc_macro.rs: # 38| getMacroCallExpansion(): [MatchExpr] match ... { ... } # 38| getScrutinee(): [CallExpr] ...::parse::<...>(...) # 38| getArgList(): [ArgList] ArgList -# 38| getArg(0): [PathExpr,VariableAccess] input +# 38| getArg(0): [VariableAccess] input # 38| getPath(): [Path] input # 38| getSegment(): [PathSegment] input # 38| getIdentifier(): [NameRef] input @@ -2526,7 +2526,7 @@ proc_macro.rs: # 38| getIdentifier(): [NameRef] parse # 38| getMatchArmList(): [MatchArmList] MatchArmList # 38| getArm(0): [MatchArm] ... => data -# 38| getExpr(): [PathExpr,VariableAccess] data +# 38| getExpr(): [VariableAccess] data # 38| getPath(): [Path] data # 38| getSegment(): [PathSegment] data # 38| getIdentifier(): [NameRef] data @@ -2552,7 +2552,7 @@ proc_macro.rs: # 38| getArg(0): [MethodCallExpr] err.to_compile_error() # 38| getArgList(): [ArgList] ArgList # 38| getIdentifier(): [NameRef] to_compile_error -# 38| getReceiver(): [PathExpr,VariableAccess] err +# 38| getReceiver(): [VariableAccess] err # 38| getPath(): [Path] err # 38| getSegment(): [PathSegment] err # 38| getIdentifier(): [NameRef] err @@ -2586,7 +2586,7 @@ proc_macro.rs: # 39| getStatement(1): [LetStmt] let ... = ... # 39| getInitializer(): [RefExpr] &... # 39| getExpr(): [FieldExpr] ast.ident -# 39| getContainer(): [PathExpr,VariableAccess] ast +# 39| getContainer(): [VariableAccess] ast # 39| getPath(): [Path] ast # 39| getSegment(): [PathSegment] ast # 39| getIdentifier(): [NameRef] ast @@ -2623,7 +2623,7 @@ proc_macro.rs: # 40| getTokenTree(): [TokenTree] TokenTree # 40| getMacroCallExpansion(): [FormatArgsExpr] FormatArgsExpr # 40| getArg(0): [FormatArgsArg] FormatArgsArg -# 40| getExpr(): [PathExpr,VariableAccess] name +# 40| getExpr(): [VariableAccess] name # 40| getPath(): [Path] name # 40| getSegment(): [PathSegment] name # 40| getIdentifier(): [NameRef] name @@ -2652,7 +2652,7 @@ proc_macro.rs: # 40| getArg(1): [MethodCallExpr] name.span() # 40| getArgList(): [ArgList] ArgList # 40| getIdentifier(): [NameRef] span -# 40| getReceiver(): [PathExpr,VariableAccess] name +# 40| getReceiver(): [VariableAccess] name # 40| getPath(): [Path] name # 40| getSegment(): [PathSegment] name # 40| getIdentifier(): [NameRef] name @@ -2776,7 +2776,7 @@ proc_macro.rs: # 42| getExpr(): [CallExpr] ...::push_ident(...) # 42| getArgList(): [ArgList] ArgList # 41| getArg(0): [RefExpr] &mut _s -# 41| getExpr(): [PathExpr] _s +# 41| getExpr(): [VariableAccess] _s # 41| getPath(): [Path] _s # 41| getSegment(): [PathSegment] _s # 41| getIdentifier(): [NameRef] _s @@ -2812,12 +2812,12 @@ proc_macro.rs: # 42| getExpr(): [CallExpr] ...::to_tokens(...) # 42| getArgList(): [ArgList] ArgList # 42| getArg(0): [RefExpr] &const_ident -# 42| getExpr(): [PathExpr,VariableAccess] const_ident +# 42| getExpr(): [VariableAccess] const_ident # 42| getPath(): [Path] const_ident # 42| getSegment(): [PathSegment] const_ident # 42| getIdentifier(): [NameRef] const_ident # 41| getArg(1): [RefExpr] &mut _s -# 41| getExpr(): [PathExpr] _s +# 41| getExpr(): [VariableAccess] _s # 41| getPath(): [Path] _s # 41| getSegment(): [PathSegment] _s # 41| getIdentifier(): [NameRef] _s @@ -2867,7 +2867,7 @@ proc_macro.rs: # 41| getExpr(): [CallExpr] ...::push_colon(...) # 41| getArgList(): [ArgList] ArgList # 41| getArg(0): [RefExpr] &mut _s -# 41| getExpr(): [PathExpr] _s +# 41| getExpr(): [VariableAccess] _s # 41| getPath(): [Path] _s # 41| getSegment(): [PathSegment] _s # 41| getIdentifier(): [NameRef] _s @@ -2906,7 +2906,7 @@ proc_macro.rs: # 42| getExpr(): [CallExpr] ...::push_ident(...) # 42| getArgList(): [ArgList] ArgList # 41| getArg(0): [RefExpr] &mut _s -# 41| getExpr(): [PathExpr] _s +# 41| getExpr(): [VariableAccess] _s # 41| getPath(): [Path] _s # 41| getSegment(): [PathSegment] _s # 41| getIdentifier(): [NameRef] _s @@ -2952,7 +2952,7 @@ proc_macro.rs: # 41| getExpr(): [CallExpr] ...::push_eq(...) # 41| getArgList(): [ArgList] ArgList # 41| getArg(0): [RefExpr] &mut _s -# 41| getExpr(): [PathExpr] _s +# 41| getExpr(): [VariableAccess] _s # 41| getPath(): [Path] _s # 41| getSegment(): [PathSegment] _s # 41| getIdentifier(): [NameRef] _s @@ -2991,7 +2991,7 @@ proc_macro.rs: # 42| getExpr(): [CallExpr] ...::parse(...) # 42| getArgList(): [ArgList] ArgList # 41| getArg(0): [RefExpr] &mut _s -# 41| getExpr(): [PathExpr] _s +# 41| getExpr(): [VariableAccess] _s # 41| getPath(): [Path] _s # 41| getSegment(): [PathSegment] _s # 41| getIdentifier(): [NameRef] _s @@ -3037,7 +3037,7 @@ proc_macro.rs: # 41| getExpr(): [CallExpr] ...::push_semi(...) # 41| getArgList(): [ArgList] ArgList # 41| getArg(0): [RefExpr] &mut _s -# 41| getExpr(): [PathExpr] _s +# 41| getExpr(): [VariableAccess] _s # 41| getPath(): [Path] _s # 41| getSegment(): [PathSegment] _s # 41| getIdentifier(): [NameRef] _s @@ -3076,7 +3076,7 @@ proc_macro.rs: # 44| getExpr(): [CallExpr] ...::push_ident(...) # 44| getArgList(): [ArgList] ArgList # 41| getArg(0): [RefExpr] &mut _s -# 41| getExpr(): [PathExpr] _s +# 41| getExpr(): [VariableAccess] _s # 41| getPath(): [Path] _s # 41| getSegment(): [PathSegment] _s # 41| getIdentifier(): [NameRef] _s @@ -3122,7 +3122,7 @@ proc_macro.rs: # 44| getExpr(): [CallExpr] ...::push_ident(...) # 44| getArgList(): [ArgList] ArgList # 41| getArg(0): [RefExpr] &mut _s -# 41| getExpr(): [PathExpr] _s +# 41| getExpr(): [VariableAccess] _s # 41| getPath(): [Path] _s # 41| getSegment(): [PathSegment] _s # 41| getIdentifier(): [NameRef] _s @@ -3168,7 +3168,7 @@ proc_macro.rs: # 44| getExpr(): [CallExpr] ...::push_ident(...) # 44| getArgList(): [ArgList] ArgList # 41| getArg(0): [RefExpr] &mut _s -# 41| getExpr(): [PathExpr] _s +# 41| getExpr(): [VariableAccess] _s # 41| getPath(): [Path] _s # 41| getSegment(): [PathSegment] _s # 41| getIdentifier(): [NameRef] _s @@ -3204,12 +3204,12 @@ proc_macro.rs: # 44| getExpr(): [CallExpr] ...::to_tokens(...) # 44| getArgList(): [ArgList] ArgList # 44| getArg(0): [RefExpr] &name -# 44| getExpr(): [PathExpr,VariableAccess] name +# 44| getExpr(): [VariableAccess] name # 44| getPath(): [Path] name # 44| getSegment(): [PathSegment] name # 44| getIdentifier(): [NameRef] name # 41| getArg(1): [RefExpr] &mut _s -# 41| getExpr(): [PathExpr] _s +# 41| getExpr(): [VariableAccess] _s # 41| getPath(): [Path] _s # 41| getSegment(): [PathSegment] _s # 41| getIdentifier(): [NameRef] _s @@ -3259,7 +3259,7 @@ proc_macro.rs: # 45| getExpr(): [CallExpr] ...::push_group(...) # 45| getArgList(): [ArgList] ArgList # 41| getArg(0): [RefExpr] &mut _s -# 41| getExpr(): [PathExpr] _s +# 41| getExpr(): [VariableAccess] _s # 41| getPath(): [Path] _s # 41| getSegment(): [PathSegment] _s # 41| getIdentifier(): [NameRef] _s @@ -3384,7 +3384,7 @@ proc_macro.rs: # 45| getExpr(): [CallExpr] ...::push_ident(...) # 45| getArgList(): [ArgList] ArgList # 41| getArg(0): [RefExpr] &mut _s -# 41| getExpr(): [PathExpr] _s +# 41| getExpr(): [VariableAccess] _s # 41| getPath(): [Path] _s # 41| getSegment(): [PathSegment] _s # 41| getIdentifier(): [NameRef] _s @@ -3430,7 +3430,7 @@ proc_macro.rs: # 45| getExpr(): [CallExpr] ...::push_ident(...) # 45| getArgList(): [ArgList] ArgList # 41| getArg(0): [RefExpr] &mut _s -# 41| getExpr(): [PathExpr] _s +# 41| getExpr(): [VariableAccess] _s # 41| getPath(): [Path] _s # 41| getSegment(): [PathSegment] _s # 41| getIdentifier(): [NameRef] _s @@ -3476,7 +3476,7 @@ proc_macro.rs: # 41| getExpr(): [CallExpr] ...::push_group(...) # 41| getArgList(): [ArgList] ArgList # 41| getArg(0): [RefExpr] &mut _s -# 41| getExpr(): [PathExpr] _s +# 41| getExpr(): [VariableAccess] _s # 41| getPath(): [Path] _s # 41| getSegment(): [PathSegment] _s # 41| getIdentifier(): [NameRef] _s @@ -3552,7 +3552,7 @@ proc_macro.rs: # 41| getExpr(): [CallExpr] ...::push_rarrow(...) # 41| getArgList(): [ArgList] ArgList # 41| getArg(0): [RefExpr] &mut _s -# 41| getExpr(): [PathExpr] _s +# 41| getExpr(): [VariableAccess] _s # 41| getPath(): [Path] _s # 41| getSegment(): [PathSegment] _s # 41| getIdentifier(): [NameRef] _s @@ -3591,7 +3591,7 @@ proc_macro.rs: # 45| getExpr(): [CallExpr] ...::push_ident(...) # 45| getArgList(): [ArgList] ArgList # 41| getArg(0): [RefExpr] &mut _s -# 41| getExpr(): [PathExpr] _s +# 41| getExpr(): [VariableAccess] _s # 41| getPath(): [Path] _s # 41| getSegment(): [PathSegment] _s # 41| getIdentifier(): [NameRef] _s @@ -3637,7 +3637,7 @@ proc_macro.rs: # 46| getExpr(): [CallExpr] ...::push_group(...) # 46| getArgList(): [ArgList] ArgList # 41| getArg(0): [RefExpr] &mut _s -# 41| getExpr(): [PathExpr] _s +# 41| getExpr(): [VariableAccess] _s # 41| getPath(): [Path] _s # 41| getSegment(): [PathSegment] _s # 41| getIdentifier(): [NameRef] _s @@ -3687,12 +3687,12 @@ proc_macro.rs: # 46| getExpr(): [CallExpr] ...::to_tokens(...) # 46| getArgList(): [ArgList] ArgList # 46| getArg(0): [RefExpr] &const_ident -# 46| getExpr(): [PathExpr,VariableAccess] const_ident +# 46| getExpr(): [VariableAccess] const_ident # 46| getPath(): [Path] const_ident # 46| getSegment(): [PathSegment] const_ident # 46| getIdentifier(): [NameRef] const_ident # 41| getArg(1): [RefExpr] &mut _s -# 41| getExpr(): [PathExpr] _s +# 41| getExpr(): [VariableAccess] _s # 41| getPath(): [Path] _s # 41| getSegment(): [PathSegment] _s # 41| getIdentifier(): [NameRef] _s @@ -3706,7 +3706,7 @@ proc_macro.rs: # 41| getIdentifier(): [NameRef] ToTokens # 41| getSegment(): [PathSegment] to_tokens # 41| getIdentifier(): [NameRef] to_tokens -# 41| getTailExpr(): [PathExpr] _s +# 41| getTailExpr(): [VariableAccess] _s # 41| getPath(): [Path] _s # 41| getSegment(): [PathSegment] _s # 41| getIdentifier(): [NameRef] _s @@ -3752,7 +3752,7 @@ proc_macro.rs: # 41| getIdentifier(): [NameRef] quote_token_with_context # 45| getTokenTree(): [TokenTree] TokenTree # 41| getMacroCallExpansion(): [MacroBlockExpr] MacroBlockExpr -# 41| getTailExpr(): [PathExpr] _s +# 41| getTailExpr(): [VariableAccess] _s # 41| getPath(): [Path] _s # 41| getSegment(): [PathSegment] _s # 41| getIdentifier(): [NameRef] _s @@ -3798,7 +3798,7 @@ proc_macro.rs: # 41| getIdentifier(): [NameRef] quote_token_with_context # 44| getTokenTree(): [TokenTree] TokenTree # 41| getMacroCallExpansion(): [MacroBlockExpr] MacroBlockExpr -# 41| getTailExpr(): [PathExpr] _s +# 41| getTailExpr(): [VariableAccess] _s # 41| getPath(): [Path] _s # 41| getSegment(): [PathSegment] _s # 41| getIdentifier(): [NameRef] _s diff --git a/rust/ql/test/library-tests/path-resolution/main.rs b/rust/ql/test/library-tests/path-resolution/main.rs index 9e7ebf5fb173..c0f37bcd18eb 100644 --- a/rust/ql/test/library-tests/path-resolution/main.rs +++ b/rust/ql/test/library-tests/path-resolution/main.rs @@ -790,6 +790,49 @@ mod impl_with_attribute_macro { } // impl_with_attribute_macro::test } +mod patterns { + #[rustfmt::skip] + pub fn test() -> Option { // $ item=Option $ item=i32 + let x = Some(42); // $ item=Some + let y : Option = match x { // $ item=Option $ item=i32 + Some(y) => { // $ item=Some + None // $ item=None + } + None => // $ item=None + None // $ item=None + }; + match y { + N0ne => // local variable + N0ne + } + } // patterns::test + + #[rustfmt::skip] + fn test2() -> Option { // $ item=Option $ item=i32 + let test_alias = test; // $ item=patterns::test + let test = test_alias(); + test + } + + #[rustfmt::skip] + const z: i32 // $ item=i32 + = 0; // constz + + #[rustfmt::skip] + fn test3() { + let x = Some(0); // $ item=Some + match x { + Some(x) // $ item=Some + => x, + _ => 0 + }; + match x { + Some(z) => z, // $ item=Some item=constz + _ => 0 + }; + } +} + fn main() { my::nested::nested1::nested2::f(); // $ item=I4 my::f(); // $ item=I38 @@ -826,4 +869,5 @@ fn main() { AStruct::z_on_type(); // $ item=I124 AStruct {}.z_on_instance(); // $ item=I123 item=I125 impl_with_attribute_macro::test(); // $ item=impl_with_attribute_macro::test + patterns::test(); // $ item=patterns::test } diff --git a/rust/ql/test/library-tests/path-resolution/path-resolution.expected b/rust/ql/test/library-tests/path-resolution/path-resolution.expected index 0ff48d11e8db..20c7e7799be7 100644 --- a/rust/ql/test/library-tests/path-resolution/path-resolution.expected +++ b/rust/ql/test/library-tests/path-resolution/path-resolution.expected @@ -32,6 +32,7 @@ mod | main.rs:629:1:697:1 | mod m24 | | main.rs:714:1:766:1 | mod associated_types | | main.rs:772:1:791:1 | mod impl_with_attribute_macro | +| main.rs:793:1:834:1 | mod patterns | | my2/mod.rs:1:1:1:16 | mod nested2 | | my2/mod.rs:20:1:20:12 | mod my3 | | my2/mod.rs:22:1:23:10 | mod mymod | @@ -72,7 +73,7 @@ resolvePath | main.rs:37:17:37:24 | ...::f | main.rs:26:9:28:9 | fn f | | main.rs:39:17:39:23 | println | {EXTERNAL LOCATION} | MacroRules | | main.rs:40:17:40:17 | f | main.rs:26:9:28:9 | fn f | -| main.rs:47:9:47:13 | super | main.rs:1:1:829:2 | SourceFile | +| main.rs:47:9:47:13 | super | main.rs:1:1:873:2 | SourceFile | | main.rs:47:9:47:17 | ...::m1 | main.rs:20:1:44:1 | mod m1 | | main.rs:47:9:47:21 | ...::m2 | main.rs:25:5:43:5 | mod m2 | | main.rs:47:9:47:24 | ...::g | main.rs:30:9:34:9 | fn g | @@ -87,7 +88,7 @@ resolvePath | main.rs:68:17:68:19 | Foo | main.rs:66:9:66:21 | struct Foo | | main.rs:71:13:71:15 | Foo | main.rs:60:5:60:17 | struct Foo | | main.rs:73:5:73:5 | f | main.rs:62:5:69:5 | fn f | -| main.rs:75:5:75:8 | self | main.rs:1:1:829:2 | SourceFile | +| main.rs:75:5:75:8 | self | main.rs:1:1:873:2 | SourceFile | | main.rs:75:5:75:11 | ...::i | main.rs:78:1:90:1 | fn i | | main.rs:79:5:79:11 | println | {EXTERNAL LOCATION} | MacroRules | | main.rs:81:13:81:15 | Foo | main.rs:55:1:55:13 | struct Foo | @@ -109,7 +110,7 @@ resolvePath | main.rs:112:9:112:15 | println | {EXTERNAL LOCATION} | MacroRules | | main.rs:118:9:118:15 | println | {EXTERNAL LOCATION} | MacroRules | | main.rs:122:9:122:15 | println | {EXTERNAL LOCATION} | MacroRules | -| main.rs:125:13:125:17 | super | main.rs:1:1:829:2 | SourceFile | +| main.rs:125:13:125:17 | super | main.rs:1:1:873:2 | SourceFile | | main.rs:125:13:125:21 | ...::m5 | main.rs:110:1:114:1 | mod m5 | | main.rs:126:9:126:9 | f | main.rs:111:5:113:5 | fn f | | main.rs:126:9:126:9 | f | main.rs:117:5:119:5 | fn f | @@ -397,77 +398,97 @@ resolvePath | main.rs:781:21:781:23 | i64 | {EXTERNAL LOCATION} | struct i64 | | main.rs:783:11:783:13 | i64 | {EXTERNAL LOCATION} | struct i64 | | main.rs:789:17:789:19 | Foo | main.rs:774:5:774:15 | struct Foo | -| main.rs:794:5:794:6 | my | main.rs:1:1:1:7 | mod my | -| main.rs:794:5:794:14 | ...::nested | my.rs:1:1:1:15 | mod nested | -| main.rs:794:5:794:23 | ...::nested1 | my/nested.rs:1:1:17:1 | mod nested1 | -| main.rs:794:5:794:32 | ...::nested2 | my/nested.rs:2:5:11:5 | mod nested2 | -| main.rs:794:5:794:35 | ...::f | my/nested.rs:3:9:5:9 | fn f | -| main.rs:795:5:795:6 | my | main.rs:1:1:1:7 | mod my | -| main.rs:795:5:795:9 | ...::f | my.rs:5:1:7:1 | fn f | -| main.rs:796:5:796:11 | nested2 | my2/mod.rs:1:1:1:16 | mod nested2 | -| main.rs:796:5:796:20 | ...::nested3 | my2/nested2.rs:1:1:11:1 | mod nested3 | -| main.rs:796:5:796:29 | ...::nested4 | my2/nested2.rs:2:5:10:5 | mod nested4 | -| main.rs:796:5:796:32 | ...::f | my2/nested2.rs:3:9:5:9 | fn f | -| main.rs:797:5:797:5 | f | my2/nested2.rs:3:9:5:9 | fn f | -| main.rs:798:5:798:5 | g | my2/nested2.rs:7:9:9:9 | fn g | -| main.rs:799:5:799:9 | crate | main.rs:0:0:0:0 | Crate(main@0.0.1) | -| main.rs:799:5:799:12 | ...::h | main.rs:57:1:76:1 | fn h | -| main.rs:800:5:800:6 | m1 | main.rs:20:1:44:1 | mod m1 | -| main.rs:800:5:800:10 | ...::m2 | main.rs:25:5:43:5 | mod m2 | -| main.rs:800:5:800:13 | ...::g | main.rs:30:9:34:9 | fn g | -| main.rs:801:5:801:6 | m1 | main.rs:20:1:44:1 | mod m1 | -| main.rs:801:5:801:10 | ...::m2 | main.rs:25:5:43:5 | mod m2 | -| main.rs:801:5:801:14 | ...::m3 | main.rs:36:9:42:9 | mod m3 | -| main.rs:801:5:801:17 | ...::h | main.rs:37:27:41:13 | fn h | -| main.rs:802:5:802:6 | m4 | main.rs:46:1:53:1 | mod m4 | -| main.rs:802:5:802:9 | ...::i | main.rs:49:5:52:5 | fn i | -| main.rs:803:5:803:5 | h | main.rs:57:1:76:1 | fn h | -| main.rs:804:5:804:11 | f_alias | my2/nested2.rs:3:9:5:9 | fn f | -| main.rs:805:5:805:11 | g_alias | my2/nested2.rs:7:9:9:9 | fn g | -| main.rs:806:5:806:5 | j | main.rs:104:1:108:1 | fn j | -| main.rs:807:5:807:6 | m6 | main.rs:116:1:128:1 | mod m6 | -| main.rs:807:5:807:9 | ...::g | main.rs:121:5:127:5 | fn g | -| main.rs:808:5:808:6 | m7 | main.rs:130:1:149:1 | mod m7 | -| main.rs:808:5:808:9 | ...::f | main.rs:141:5:148:5 | fn f | -| main.rs:809:5:809:6 | m8 | main.rs:151:1:205:1 | mod m8 | -| main.rs:809:5:809:9 | ...::g | main.rs:189:5:204:5 | fn g | -| main.rs:810:5:810:6 | m9 | main.rs:207:1:215:1 | mod m9 | -| main.rs:810:5:810:9 | ...::f | main.rs:210:5:214:5 | fn f | -| main.rs:811:5:811:7 | m11 | main.rs:238:1:275:1 | mod m11 | -| main.rs:811:5:811:10 | ...::f | main.rs:243:5:246:5 | fn f | -| main.rs:812:5:812:7 | m15 | main.rs:306:1:375:1 | mod m15 | -| main.rs:812:5:812:10 | ...::f | main.rs:362:5:374:5 | fn f | -| main.rs:813:5:813:7 | m16 | main.rs:377:1:469:1 | mod m16 | -| main.rs:813:5:813:10 | ...::f | main.rs:444:5:468:5 | fn f | -| main.rs:814:5:814:20 | trait_visibility | main.rs:471:1:521:1 | mod trait_visibility | -| main.rs:814:5:814:23 | ...::f | main.rs:498:5:520:5 | fn f | -| main.rs:815:5:815:7 | m17 | main.rs:523:1:553:1 | mod m17 | -| main.rs:815:5:815:10 | ...::f | main.rs:547:5:552:5 | fn f | -| main.rs:816:5:816:11 | nested6 | my2/nested2.rs:14:5:18:5 | mod nested6 | -| main.rs:816:5:816:14 | ...::f | my2/nested2.rs:15:9:17:9 | fn f | -| main.rs:817:5:817:11 | nested8 | my2/nested2.rs:22:5:26:5 | mod nested8 | -| main.rs:817:5:817:14 | ...::f | my2/nested2.rs:23:9:25:9 | fn f | -| main.rs:818:5:818:7 | my3 | my2/mod.rs:20:1:20:12 | mod my3 | -| main.rs:818:5:818:10 | ...::f | my2/my3/mod.rs:1:1:5:1 | fn f | -| main.rs:819:5:819:12 | nested_f | my/my4/my5/mod.rs:1:1:3:1 | fn f | -| main.rs:820:5:820:12 | my_alias | main.rs:1:1:1:7 | mod my | -| main.rs:820:5:820:22 | ...::nested_f | my/my4/my5/mod.rs:1:1:3:1 | fn f | -| main.rs:821:5:821:7 | m18 | main.rs:555:1:573:1 | mod m18 | -| main.rs:821:5:821:12 | ...::m19 | main.rs:560:5:572:5 | mod m19 | -| main.rs:821:5:821:17 | ...::m20 | main.rs:565:9:571:9 | mod m20 | -| main.rs:821:5:821:20 | ...::g | main.rs:566:13:570:13 | fn g | -| main.rs:822:5:822:7 | m23 | main.rs:602:1:627:1 | mod m23 | -| main.rs:822:5:822:10 | ...::f | main.rs:622:5:626:5 | fn f | -| main.rs:823:5:823:7 | m24 | main.rs:629:1:697:1 | mod m24 | -| main.rs:823:5:823:10 | ...::f | main.rs:683:5:696:5 | fn f | -| main.rs:824:5:824:8 | zelf | main.rs:0:0:0:0 | Crate(main@0.0.1) | -| main.rs:824:5:824:11 | ...::h | main.rs:57:1:76:1 | fn h | -| main.rs:825:5:825:13 | z_changed | main.rs:702:1:702:9 | fn z_changed | -| main.rs:826:5:826:11 | AStruct | main.rs:704:1:704:17 | struct AStruct | -| main.rs:826:5:826:22 | ...::z_on_type | main.rs:708:5:708:17 | fn z_on_type | -| main.rs:827:5:827:11 | AStruct | main.rs:704:1:704:17 | struct AStruct | -| main.rs:828:5:828:29 | impl_with_attribute_macro | main.rs:772:1:791:1 | mod impl_with_attribute_macro | -| main.rs:828:5:828:35 | ...::test | main.rs:787:5:790:5 | fn test | +| main.rs:795:22:795:32 | Option::<...> | {EXTERNAL LOCATION} | enum Option | +| main.rs:795:29:795:31 | i32 | {EXTERNAL LOCATION} | struct i32 | +| main.rs:796:17:796:20 | Some | {EXTERNAL LOCATION} | Some | +| main.rs:797:17:797:27 | Option::<...> | {EXTERNAL LOCATION} | enum Option | +| main.rs:797:24:797:26 | i32 | {EXTERNAL LOCATION} | struct i32 | +| main.rs:798:13:798:16 | Some | {EXTERNAL LOCATION} | Some | +| main.rs:799:17:799:20 | None | {EXTERNAL LOCATION} | None | +| main.rs:801:13:801:16 | None | {EXTERNAL LOCATION} | None | +| main.rs:802:17:802:20 | None | {EXTERNAL LOCATION} | None | +| main.rs:811:19:811:29 | Option::<...> | {EXTERNAL LOCATION} | enum Option | +| main.rs:811:26:811:28 | i32 | {EXTERNAL LOCATION} | struct i32 | +| main.rs:812:26:812:29 | test | main.rs:794:5:808:5 | fn test | +| main.rs:818:14:818:16 | i32 | {EXTERNAL LOCATION} | struct i32 | +| main.rs:823:17:823:20 | Some | {EXTERNAL LOCATION} | Some | +| main.rs:825:13:825:16 | Some | {EXTERNAL LOCATION} | Some | +| main.rs:830:13:830:16 | Some | {EXTERNAL LOCATION} | Some | +| main.rs:830:18:830:18 | z | main.rs:817:5:819:12 | Const | +| main.rs:830:24:830:24 | z | main.rs:817:5:819:12 | Const | +| main.rs:837:5:837:6 | my | main.rs:1:1:1:7 | mod my | +| main.rs:837:5:837:14 | ...::nested | my.rs:1:1:1:15 | mod nested | +| main.rs:837:5:837:23 | ...::nested1 | my/nested.rs:1:1:17:1 | mod nested1 | +| main.rs:837:5:837:32 | ...::nested2 | my/nested.rs:2:5:11:5 | mod nested2 | +| main.rs:837:5:837:35 | ...::f | my/nested.rs:3:9:5:9 | fn f | +| main.rs:838:5:838:6 | my | main.rs:1:1:1:7 | mod my | +| main.rs:838:5:838:9 | ...::f | my.rs:5:1:7:1 | fn f | +| main.rs:839:5:839:11 | nested2 | my2/mod.rs:1:1:1:16 | mod nested2 | +| main.rs:839:5:839:20 | ...::nested3 | my2/nested2.rs:1:1:11:1 | mod nested3 | +| main.rs:839:5:839:29 | ...::nested4 | my2/nested2.rs:2:5:10:5 | mod nested4 | +| main.rs:839:5:839:32 | ...::f | my2/nested2.rs:3:9:5:9 | fn f | +| main.rs:840:5:840:5 | f | my2/nested2.rs:3:9:5:9 | fn f | +| main.rs:841:5:841:5 | g | my2/nested2.rs:7:9:9:9 | fn g | +| main.rs:842:5:842:9 | crate | main.rs:0:0:0:0 | Crate(main@0.0.1) | +| main.rs:842:5:842:12 | ...::h | main.rs:57:1:76:1 | fn h | +| main.rs:843:5:843:6 | m1 | main.rs:20:1:44:1 | mod m1 | +| main.rs:843:5:843:10 | ...::m2 | main.rs:25:5:43:5 | mod m2 | +| main.rs:843:5:843:13 | ...::g | main.rs:30:9:34:9 | fn g | +| main.rs:844:5:844:6 | m1 | main.rs:20:1:44:1 | mod m1 | +| main.rs:844:5:844:10 | ...::m2 | main.rs:25:5:43:5 | mod m2 | +| main.rs:844:5:844:14 | ...::m3 | main.rs:36:9:42:9 | mod m3 | +| main.rs:844:5:844:17 | ...::h | main.rs:37:27:41:13 | fn h | +| main.rs:845:5:845:6 | m4 | main.rs:46:1:53:1 | mod m4 | +| main.rs:845:5:845:9 | ...::i | main.rs:49:5:52:5 | fn i | +| main.rs:846:5:846:5 | h | main.rs:57:1:76:1 | fn h | +| main.rs:847:5:847:11 | f_alias | my2/nested2.rs:3:9:5:9 | fn f | +| main.rs:848:5:848:11 | g_alias | my2/nested2.rs:7:9:9:9 | fn g | +| main.rs:849:5:849:5 | j | main.rs:104:1:108:1 | fn j | +| main.rs:850:5:850:6 | m6 | main.rs:116:1:128:1 | mod m6 | +| main.rs:850:5:850:9 | ...::g | main.rs:121:5:127:5 | fn g | +| main.rs:851:5:851:6 | m7 | main.rs:130:1:149:1 | mod m7 | +| main.rs:851:5:851:9 | ...::f | main.rs:141:5:148:5 | fn f | +| main.rs:852:5:852:6 | m8 | main.rs:151:1:205:1 | mod m8 | +| main.rs:852:5:852:9 | ...::g | main.rs:189:5:204:5 | fn g | +| main.rs:853:5:853:6 | m9 | main.rs:207:1:215:1 | mod m9 | +| main.rs:853:5:853:9 | ...::f | main.rs:210:5:214:5 | fn f | +| main.rs:854:5:854:7 | m11 | main.rs:238:1:275:1 | mod m11 | +| main.rs:854:5:854:10 | ...::f | main.rs:243:5:246:5 | fn f | +| main.rs:855:5:855:7 | m15 | main.rs:306:1:375:1 | mod m15 | +| main.rs:855:5:855:10 | ...::f | main.rs:362:5:374:5 | fn f | +| main.rs:856:5:856:7 | m16 | main.rs:377:1:469:1 | mod m16 | +| main.rs:856:5:856:10 | ...::f | main.rs:444:5:468:5 | fn f | +| main.rs:857:5:857:20 | trait_visibility | main.rs:471:1:521:1 | mod trait_visibility | +| main.rs:857:5:857:23 | ...::f | main.rs:498:5:520:5 | fn f | +| main.rs:858:5:858:7 | m17 | main.rs:523:1:553:1 | mod m17 | +| main.rs:858:5:858:10 | ...::f | main.rs:547:5:552:5 | fn f | +| main.rs:859:5:859:11 | nested6 | my2/nested2.rs:14:5:18:5 | mod nested6 | +| main.rs:859:5:859:14 | ...::f | my2/nested2.rs:15:9:17:9 | fn f | +| main.rs:860:5:860:11 | nested8 | my2/nested2.rs:22:5:26:5 | mod nested8 | +| main.rs:860:5:860:14 | ...::f | my2/nested2.rs:23:9:25:9 | fn f | +| main.rs:861:5:861:7 | my3 | my2/mod.rs:20:1:20:12 | mod my3 | +| main.rs:861:5:861:10 | ...::f | my2/my3/mod.rs:1:1:5:1 | fn f | +| main.rs:862:5:862:12 | nested_f | my/my4/my5/mod.rs:1:1:3:1 | fn f | +| main.rs:863:5:863:12 | my_alias | main.rs:1:1:1:7 | mod my | +| main.rs:863:5:863:22 | ...::nested_f | my/my4/my5/mod.rs:1:1:3:1 | fn f | +| main.rs:864:5:864:7 | m18 | main.rs:555:1:573:1 | mod m18 | +| main.rs:864:5:864:12 | ...::m19 | main.rs:560:5:572:5 | mod m19 | +| main.rs:864:5:864:17 | ...::m20 | main.rs:565:9:571:9 | mod m20 | +| main.rs:864:5:864:20 | ...::g | main.rs:566:13:570:13 | fn g | +| main.rs:865:5:865:7 | m23 | main.rs:602:1:627:1 | mod m23 | +| main.rs:865:5:865:10 | ...::f | main.rs:622:5:626:5 | fn f | +| main.rs:866:5:866:7 | m24 | main.rs:629:1:697:1 | mod m24 | +| main.rs:866:5:866:10 | ...::f | main.rs:683:5:696:5 | fn f | +| main.rs:867:5:867:8 | zelf | main.rs:0:0:0:0 | Crate(main@0.0.1) | +| main.rs:867:5:867:11 | ...::h | main.rs:57:1:76:1 | fn h | +| main.rs:868:5:868:13 | z_changed | main.rs:702:1:702:9 | fn z_changed | +| main.rs:869:5:869:11 | AStruct | main.rs:704:1:704:17 | struct AStruct | +| main.rs:869:5:869:22 | ...::z_on_type | main.rs:708:5:708:17 | fn z_on_type | +| main.rs:870:5:870:11 | AStruct | main.rs:704:1:704:17 | struct AStruct | +| main.rs:871:5:871:29 | impl_with_attribute_macro | main.rs:772:1:791:1 | mod impl_with_attribute_macro | +| main.rs:871:5:871:35 | ...::test | main.rs:787:5:790:5 | fn test | +| main.rs:872:5:872:12 | patterns | main.rs:793:1:834:1 | mod patterns | +| main.rs:872:5:872:18 | ...::test | main.rs:794:5:808:5 | fn test | | my2/mod.rs:4:5:4:11 | println | {EXTERNAL LOCATION} | MacroRules | | my2/mod.rs:5:5:5:11 | nested2 | my2/mod.rs:1:1:1:16 | mod nested2 | | my2/mod.rs:5:5:5:20 | ...::nested3 | my2/nested2.rs:1:1:11:1 | mod nested3 | @@ -493,7 +514,7 @@ resolvePath | my2/my3/mod.rs:3:5:3:5 | g | my2/mod.rs:3:1:6:1 | fn g | | my2/my3/mod.rs:4:5:4:5 | h | main.rs:57:1:76:1 | fn h | | my2/my3/mod.rs:7:5:7:9 | super | my2/mod.rs:1:1:25:34 | SourceFile | -| my2/my3/mod.rs:7:5:7:16 | ...::super | main.rs:1:1:829:2 | SourceFile | +| my2/my3/mod.rs:7:5:7:16 | ...::super | main.rs:1:1:873:2 | SourceFile | | my2/my3/mod.rs:7:5:7:19 | ...::h | main.rs:57:1:76:1 | fn h | | my2/my3/mod.rs:8:5:8:9 | super | my2/mod.rs:1:1:25:34 | SourceFile | | my2/my3/mod.rs:8:5:8:12 | ...::g | my2/mod.rs:3:1:6:1 | fn g | diff --git a/rust/ql/test/library-tests/path-resolution/path-resolution.ql b/rust/ql/test/library-tests/path-resolution/path-resolution.ql index 0fe49a8e386b..f7955929b839 100644 --- a/rust/ql/test/library-tests/path-resolution/path-resolution.ql +++ b/rust/ql/test/library-tests/path-resolution/path-resolution.ql @@ -5,7 +5,7 @@ import TestUtils query predicate mod(Module m) { toBeTested(m) } -query predicate resolvePath(Path p, ItemNode i) { +query predicate resolvePath(PathExt p, ItemNode i) { toBeTested(p) and not p.isFromMacroExpansion() and i = resolvePath(p) diff --git a/rust/ql/test/library-tests/variables/Cfg.expected b/rust/ql/test/library-tests/variables/Cfg.expected index 7d8da915bfb5..f93586d373be 100644 --- a/rust/ql/test/library-tests/variables/Cfg.expected +++ b/rust/ql/test/library-tests/variables/Cfg.expected @@ -1798,145 +1798,216 @@ edges | main.rs:753:5:753:16 | print_i64(...) | main.rs:744:18:754:1 | { ... } | | | main.rs:753:5:753:17 | ExprStmt | main.rs:753:5:753:13 | print_i64 | | | main.rs:753:15:753:15 | x | main.rs:753:5:753:16 | print_i64(...) | | -| main.rs:756:1:800:1 | enter fn main | main.rs:757:5:757:25 | ExprStmt | | -| main.rs:756:1:800:1 | exit fn main (normal) | main.rs:756:1:800:1 | exit fn main | | -| main.rs:756:11:800:1 | { ... } | main.rs:756:1:800:1 | exit fn main (normal) | | -| main.rs:757:5:757:22 | immutable_variable | main.rs:757:5:757:24 | immutable_variable(...) | | -| main.rs:757:5:757:24 | immutable_variable(...) | main.rs:758:5:758:23 | ExprStmt | | -| main.rs:757:5:757:25 | ExprStmt | main.rs:757:5:757:22 | immutable_variable | | -| main.rs:758:5:758:20 | mutable_variable | main.rs:758:5:758:22 | mutable_variable(...) | | -| main.rs:758:5:758:22 | mutable_variable(...) | main.rs:759:5:759:40 | ExprStmt | | -| main.rs:758:5:758:23 | ExprStmt | main.rs:758:5:758:20 | mutable_variable | | -| main.rs:759:5:759:37 | mutable_variable_immutable_borrow | main.rs:759:5:759:39 | mutable_variable_immutable_borrow(...) | | -| main.rs:759:5:759:39 | mutable_variable_immutable_borrow(...) | main.rs:760:5:760:23 | ExprStmt | | -| main.rs:759:5:759:40 | ExprStmt | main.rs:759:5:759:37 | mutable_variable_immutable_borrow | | -| main.rs:760:5:760:20 | variable_shadow1 | main.rs:760:5:760:22 | variable_shadow1(...) | | -| main.rs:760:5:760:22 | variable_shadow1(...) | main.rs:761:5:761:23 | ExprStmt | | -| main.rs:760:5:760:23 | ExprStmt | main.rs:760:5:760:20 | variable_shadow1 | | -| main.rs:761:5:761:20 | variable_shadow2 | main.rs:761:5:761:22 | variable_shadow2(...) | | -| main.rs:761:5:761:22 | variable_shadow2(...) | main.rs:762:5:762:19 | ExprStmt | | -| main.rs:761:5:761:23 | ExprStmt | main.rs:761:5:761:20 | variable_shadow2 | | -| main.rs:762:5:762:16 | let_pattern1 | main.rs:762:5:762:18 | let_pattern1(...) | | -| main.rs:762:5:762:18 | let_pattern1(...) | main.rs:763:5:763:19 | ExprStmt | | -| main.rs:762:5:762:19 | ExprStmt | main.rs:762:5:762:16 | let_pattern1 | | -| main.rs:763:5:763:16 | let_pattern2 | main.rs:763:5:763:18 | let_pattern2(...) | | -| main.rs:763:5:763:18 | let_pattern2(...) | main.rs:764:5:764:19 | ExprStmt | | -| main.rs:763:5:763:19 | ExprStmt | main.rs:763:5:763:16 | let_pattern2 | | -| main.rs:764:5:764:16 | let_pattern3 | main.rs:764:5:764:18 | let_pattern3(...) | | -| main.rs:764:5:764:18 | let_pattern3(...) | main.rs:765:5:765:19 | ExprStmt | | -| main.rs:764:5:764:19 | ExprStmt | main.rs:764:5:764:16 | let_pattern3 | | -| main.rs:765:5:765:16 | let_pattern4 | main.rs:765:5:765:18 | let_pattern4(...) | | -| main.rs:765:5:765:18 | let_pattern4(...) | main.rs:766:5:766:21 | ExprStmt | | -| main.rs:765:5:765:19 | ExprStmt | main.rs:765:5:765:16 | let_pattern4 | | -| main.rs:766:5:766:18 | match_pattern1 | main.rs:766:5:766:20 | match_pattern1(...) | | -| main.rs:766:5:766:20 | match_pattern1(...) | main.rs:767:5:767:21 | ExprStmt | | -| main.rs:766:5:766:21 | ExprStmt | main.rs:766:5:766:18 | match_pattern1 | | -| main.rs:767:5:767:18 | match_pattern2 | main.rs:767:5:767:20 | match_pattern2(...) | | -| main.rs:767:5:767:20 | match_pattern2(...) | main.rs:768:5:768:21 | ExprStmt | | -| main.rs:767:5:767:21 | ExprStmt | main.rs:767:5:767:18 | match_pattern2 | | -| main.rs:768:5:768:18 | match_pattern3 | main.rs:768:5:768:20 | match_pattern3(...) | | -| main.rs:768:5:768:20 | match_pattern3(...) | main.rs:769:5:769:21 | ExprStmt | | -| main.rs:768:5:768:21 | ExprStmt | main.rs:768:5:768:18 | match_pattern3 | | -| main.rs:769:5:769:18 | match_pattern4 | main.rs:769:5:769:20 | match_pattern4(...) | | -| main.rs:769:5:769:20 | match_pattern4(...) | main.rs:770:5:770:21 | ExprStmt | | -| main.rs:769:5:769:21 | ExprStmt | main.rs:769:5:769:18 | match_pattern4 | | -| main.rs:770:5:770:18 | match_pattern5 | main.rs:770:5:770:20 | match_pattern5(...) | | -| main.rs:770:5:770:20 | match_pattern5(...) | main.rs:771:5:771:21 | ExprStmt | | -| main.rs:770:5:770:21 | ExprStmt | main.rs:770:5:770:18 | match_pattern5 | | -| main.rs:771:5:771:18 | match_pattern6 | main.rs:771:5:771:20 | match_pattern6(...) | | -| main.rs:771:5:771:20 | match_pattern6(...) | main.rs:772:5:772:21 | ExprStmt | | -| main.rs:771:5:771:21 | ExprStmt | main.rs:771:5:771:18 | match_pattern6 | | -| main.rs:772:5:772:18 | match_pattern7 | main.rs:772:5:772:20 | match_pattern7(...) | | -| main.rs:772:5:772:20 | match_pattern7(...) | main.rs:773:5:773:21 | ExprStmt | | -| main.rs:772:5:772:21 | ExprStmt | main.rs:772:5:772:18 | match_pattern7 | | -| main.rs:773:5:773:18 | match_pattern8 | main.rs:773:5:773:20 | match_pattern8(...) | | -| main.rs:773:5:773:20 | match_pattern8(...) | main.rs:774:5:774:21 | ExprStmt | | -| main.rs:773:5:773:21 | ExprStmt | main.rs:773:5:773:18 | match_pattern8 | | -| main.rs:774:5:774:18 | match_pattern9 | main.rs:774:5:774:20 | match_pattern9(...) | | -| main.rs:774:5:774:20 | match_pattern9(...) | main.rs:775:5:775:22 | ExprStmt | | -| main.rs:774:5:774:21 | ExprStmt | main.rs:774:5:774:18 | match_pattern9 | | -| main.rs:775:5:775:19 | match_pattern10 | main.rs:775:5:775:21 | match_pattern10(...) | | -| main.rs:775:5:775:21 | match_pattern10(...) | main.rs:776:5:776:22 | ExprStmt | | -| main.rs:775:5:775:22 | ExprStmt | main.rs:775:5:775:19 | match_pattern10 | | -| main.rs:776:5:776:19 | match_pattern11 | main.rs:776:5:776:21 | match_pattern11(...) | | -| main.rs:776:5:776:21 | match_pattern11(...) | main.rs:777:5:777:22 | ExprStmt | | -| main.rs:776:5:776:22 | ExprStmt | main.rs:776:5:776:19 | match_pattern11 | | -| main.rs:777:5:777:19 | match_pattern12 | main.rs:777:5:777:21 | match_pattern12(...) | | -| main.rs:777:5:777:21 | match_pattern12(...) | main.rs:778:5:778:22 | ExprStmt | | -| main.rs:777:5:777:22 | ExprStmt | main.rs:777:5:777:19 | match_pattern12 | | -| main.rs:778:5:778:19 | match_pattern13 | main.rs:778:5:778:21 | match_pattern13(...) | | -| main.rs:778:5:778:21 | match_pattern13(...) | main.rs:779:5:779:22 | ExprStmt | | -| main.rs:778:5:778:22 | ExprStmt | main.rs:778:5:778:19 | match_pattern13 | | -| main.rs:779:5:779:19 | match_pattern14 | main.rs:779:5:779:21 | match_pattern14(...) | | -| main.rs:779:5:779:21 | match_pattern14(...) | main.rs:780:5:780:22 | ExprStmt | | -| main.rs:779:5:779:22 | ExprStmt | main.rs:779:5:779:19 | match_pattern14 | | -| main.rs:780:5:780:19 | match_pattern15 | main.rs:780:5:780:21 | match_pattern15(...) | | -| main.rs:780:5:780:21 | match_pattern15(...) | main.rs:781:5:781:22 | ExprStmt | | -| main.rs:780:5:780:22 | ExprStmt | main.rs:780:5:780:19 | match_pattern15 | | -| main.rs:781:5:781:19 | match_pattern16 | main.rs:781:5:781:21 | match_pattern16(...) | | -| main.rs:781:5:781:21 | match_pattern16(...) | main.rs:782:5:782:36 | ExprStmt | | -| main.rs:781:5:781:22 | ExprStmt | main.rs:781:5:781:19 | match_pattern16 | | -| main.rs:782:5:782:18 | param_pattern1 | main.rs:782:20:782:22 | "a" | | -| main.rs:782:5:782:35 | param_pattern1(...) | main.rs:783:5:783:37 | ExprStmt | | -| main.rs:782:5:782:36 | ExprStmt | main.rs:782:5:782:18 | param_pattern1 | | -| main.rs:782:20:782:22 | "a" | main.rs:782:26:782:28 | "b" | | -| main.rs:782:25:782:34 | TupleExpr | main.rs:782:5:782:35 | param_pattern1(...) | | -| main.rs:782:26:782:28 | "b" | main.rs:782:31:782:33 | "c" | | -| main.rs:782:31:782:33 | "c" | main.rs:782:25:782:34 | TupleExpr | | -| main.rs:783:5:783:18 | param_pattern2 | main.rs:783:20:783:31 | ...::Left | | -| main.rs:783:5:783:36 | param_pattern2(...) | main.rs:784:5:784:26 | ExprStmt | | -| main.rs:783:5:783:37 | ExprStmt | main.rs:783:5:783:18 | param_pattern2 | | -| main.rs:783:20:783:31 | ...::Left | main.rs:783:33:783:34 | 45 | | -| main.rs:783:20:783:35 | ...::Left(...) | main.rs:783:5:783:36 | param_pattern2(...) | | -| main.rs:783:33:783:34 | 45 | main.rs:783:20:783:35 | ...::Left(...) | | -| main.rs:784:5:784:23 | destruct_assignment | main.rs:784:5:784:25 | destruct_assignment(...) | | -| main.rs:784:5:784:25 | destruct_assignment(...) | main.rs:785:5:785:23 | ExprStmt | | -| main.rs:784:5:784:26 | ExprStmt | main.rs:784:5:784:23 | destruct_assignment | | -| main.rs:785:5:785:20 | closure_variable | main.rs:785:5:785:22 | closure_variable(...) | | -| main.rs:785:5:785:22 | closure_variable(...) | main.rs:786:5:786:22 | ExprStmt | | -| main.rs:785:5:785:23 | ExprStmt | main.rs:785:5:785:20 | closure_variable | | -| main.rs:786:5:786:19 | nested_function | main.rs:786:5:786:21 | nested_function(...) | | -| main.rs:786:5:786:21 | nested_function(...) | main.rs:787:5:787:19 | ExprStmt | | -| main.rs:786:5:786:22 | ExprStmt | main.rs:786:5:786:19 | nested_function | | -| main.rs:787:5:787:16 | for_variable | main.rs:787:5:787:18 | for_variable(...) | | -| main.rs:787:5:787:18 | for_variable(...) | main.rs:788:5:788:17 | ExprStmt | | -| main.rs:787:5:787:19 | ExprStmt | main.rs:787:5:787:16 | for_variable | | -| main.rs:788:5:788:14 | add_assign | main.rs:788:5:788:16 | add_assign(...) | | -| main.rs:788:5:788:16 | add_assign(...) | main.rs:789:5:789:13 | ExprStmt | | -| main.rs:788:5:788:17 | ExprStmt | main.rs:788:5:788:14 | add_assign | | -| main.rs:789:5:789:10 | mutate | main.rs:789:5:789:12 | mutate(...) | | -| main.rs:789:5:789:12 | mutate(...) | main.rs:790:5:790:17 | ExprStmt | | -| main.rs:789:5:789:13 | ExprStmt | main.rs:789:5:789:10 | mutate | | -| main.rs:790:5:790:14 | mutate_arg | main.rs:790:5:790:16 | mutate_arg(...) | | -| main.rs:790:5:790:16 | mutate_arg(...) | main.rs:791:5:791:12 | ExprStmt | | -| main.rs:790:5:790:17 | ExprStmt | main.rs:790:5:790:14 | mutate_arg | | -| main.rs:791:5:791:9 | alias | main.rs:791:5:791:11 | alias(...) | | -| main.rs:791:5:791:11 | alias(...) | main.rs:792:5:792:18 | ExprStmt | | -| main.rs:791:5:791:12 | ExprStmt | main.rs:791:5:791:9 | alias | | -| main.rs:792:5:792:15 | capture_mut | main.rs:792:5:792:17 | capture_mut(...) | | -| main.rs:792:5:792:17 | capture_mut(...) | main.rs:793:5:793:20 | ExprStmt | | -| main.rs:792:5:792:18 | ExprStmt | main.rs:792:5:792:15 | capture_mut | | -| main.rs:793:5:793:17 | capture_immut | main.rs:793:5:793:19 | capture_immut(...) | | -| main.rs:793:5:793:19 | capture_immut(...) | main.rs:794:5:794:26 | ExprStmt | | -| main.rs:793:5:793:20 | ExprStmt | main.rs:793:5:793:17 | capture_immut | | -| main.rs:794:5:794:23 | async_block_capture | main.rs:794:5:794:25 | async_block_capture(...) | | -| main.rs:794:5:794:25 | async_block_capture(...) | main.rs:795:5:795:14 | ExprStmt | | -| main.rs:794:5:794:26 | ExprStmt | main.rs:794:5:794:23 | async_block_capture | | -| main.rs:795:5:795:11 | structs | main.rs:795:5:795:13 | structs(...) | | -| main.rs:795:5:795:13 | structs(...) | main.rs:796:5:796:14 | ExprStmt | | -| main.rs:795:5:795:14 | ExprStmt | main.rs:795:5:795:11 | structs | | -| main.rs:796:5:796:11 | ref_arg | main.rs:796:5:796:13 | ref_arg(...) | | -| main.rs:796:5:796:13 | ref_arg(...) | main.rs:797:5:797:30 | ExprStmt | | -| main.rs:796:5:796:14 | ExprStmt | main.rs:796:5:796:11 | ref_arg | | -| main.rs:797:5:797:27 | ref_methodcall_receiver | main.rs:797:5:797:29 | ref_methodcall_receiver(...) | | -| main.rs:797:5:797:29 | ref_methodcall_receiver(...) | main.rs:798:5:798:23 | ExprStmt | | -| main.rs:797:5:797:30 | ExprStmt | main.rs:797:5:797:27 | ref_methodcall_receiver | | -| main.rs:798:5:798:20 | macro_invocation | main.rs:798:5:798:22 | macro_invocation(...) | | -| main.rs:798:5:798:22 | macro_invocation(...) | main.rs:799:5:799:18 | ExprStmt | | -| main.rs:798:5:798:23 | ExprStmt | main.rs:798:5:798:20 | macro_invocation | | -| main.rs:799:5:799:15 | capture_phi | main.rs:799:5:799:17 | capture_phi(...) | | -| main.rs:799:5:799:17 | capture_phi(...) | main.rs:756:11:800:1 | { ... } | | -| main.rs:799:5:799:18 | ExprStmt | main.rs:799:5:799:15 | capture_phi | | +| main.rs:757:5:772:5 | enter fn test | main.rs:759:9:759:25 | let ... = ... | | +| main.rs:757:5:772:5 | exit fn test (normal) | main.rs:757:5:772:5 | exit fn test | | +| main.rs:758:34:772:5 | { ... } | main.rs:757:5:772:5 | exit fn test (normal) | | +| main.rs:759:9:759:25 | let ... = ... | main.rs:759:17:759:20 | Some | | +| main.rs:759:13:759:13 | x | main.rs:759:13:759:13 | x | | +| main.rs:759:13:759:13 | x | main.rs:760:9:767:10 | let ... = ... | match | +| main.rs:759:17:759:20 | Some | main.rs:759:22:759:23 | 42 | | +| main.rs:759:17:759:24 | Some(...) | main.rs:759:13:759:13 | x | | +| main.rs:759:22:759:23 | 42 | main.rs:759:17:759:24 | Some(...) | | +| main.rs:760:9:767:10 | let ... = ... | main.rs:761:19:761:19 | x | | +| main.rs:760:13:760:13 | y | main.rs:760:13:760:13 | y | | +| main.rs:760:13:760:13 | y | main.rs:768:15:768:15 | y | match | +| main.rs:761:13:767:9 | match x { ... } | main.rs:760:13:760:13 | y | | +| main.rs:761:19:761:19 | x | main.rs:762:13:762:19 | Some(...) | | +| main.rs:762:13:762:19 | Some(...) | main.rs:762:18:762:18 | y | match | +| main.rs:762:13:762:19 | Some(...) | main.rs:765:13:765:16 | None | no-match | +| main.rs:762:18:762:18 | y | main.rs:762:18:762:18 | y | | +| main.rs:762:18:762:18 | y | main.rs:763:17:763:20 | None | match | +| main.rs:762:24:764:13 | { ... } | main.rs:761:13:767:9 | match x { ... } | | +| main.rs:763:17:763:20 | None | main.rs:762:24:764:13 | { ... } | | +| main.rs:765:13:765:16 | None | main.rs:765:13:765:16 | None | | +| main.rs:765:13:765:16 | None | main.rs:766:17:766:20 | None | match | +| main.rs:766:17:766:20 | None | main.rs:761:13:767:9 | match x { ... } | | +| main.rs:768:9:771:9 | match y { ... } | main.rs:758:34:772:5 | { ... } | | +| main.rs:768:15:768:15 | y | main.rs:769:13:769:16 | N0ne | | +| main.rs:769:13:769:16 | N0ne | main.rs:769:13:769:16 | N0ne | | +| main.rs:769:13:769:16 | N0ne | main.rs:770:17:770:20 | N0ne | match | +| main.rs:770:17:770:20 | N0ne | main.rs:768:9:771:9 | match y { ... } | | +| main.rs:774:5:781:5 | enter fn test2 | main.rs:776:9:777:17 | let ... = test | | +| main.rs:774:5:781:5 | exit fn test2 (normal) | main.rs:774:5:781:5 | exit fn test2 | | +| main.rs:775:31:781:5 | { ... } | main.rs:774:5:781:5 | exit fn test2 (normal) | | +| main.rs:776:9:777:17 | let ... = test | main.rs:777:13:777:16 | test | | +| main.rs:776:13:776:22 | test_alias | main.rs:776:13:776:22 | test_alias | | +| main.rs:776:13:776:22 | test_alias | main.rs:778:9:779:25 | let ... = ... | match | +| main.rs:777:13:777:16 | test | main.rs:776:13:776:22 | test_alias | | +| main.rs:778:9:779:25 | let ... = ... | main.rs:779:13:779:22 | test_alias | | +| main.rs:778:13:778:16 | test | main.rs:778:13:778:16 | test | | +| main.rs:778:13:778:16 | test | main.rs:780:9:780:12 | test | match | +| main.rs:779:13:779:22 | test_alias | main.rs:779:13:779:24 | test_alias(...) | | +| main.rs:779:13:779:24 | test_alias(...) | main.rs:778:13:778:16 | test | | +| main.rs:780:9:780:12 | test | main.rs:775:31:781:5 | { ... } | | +| main.rs:785:5:798:5 | enter fn test3 | main.rs:787:9:787:24 | let ... = ... | | +| main.rs:785:5:798:5 | exit fn test3 (normal) | main.rs:785:5:798:5 | exit fn test3 | | +| main.rs:786:16:798:5 | { ... } | main.rs:785:5:798:5 | exit fn test3 (normal) | | +| main.rs:787:9:787:24 | let ... = ... | main.rs:787:17:787:20 | Some | | +| main.rs:787:13:787:13 | x | main.rs:787:13:787:13 | x | | +| main.rs:787:13:787:13 | x | main.rs:788:9:792:10 | ExprStmt | match | +| main.rs:787:17:787:20 | Some | main.rs:787:22:787:22 | 0 | | +| main.rs:787:17:787:23 | Some(...) | main.rs:787:13:787:13 | x | | +| main.rs:787:22:787:22 | 0 | main.rs:787:17:787:23 | Some(...) | | +| main.rs:788:9:792:9 | match x { ... } | main.rs:793:9:797:10 | ExprStmt | | +| main.rs:788:9:792:10 | ExprStmt | main.rs:788:15:788:15 | x | | +| main.rs:788:15:788:15 | x | main.rs:789:13:789:19 | Some(...) | | +| main.rs:789:13:789:19 | Some(...) | main.rs:789:18:789:18 | x | match | +| main.rs:789:13:789:19 | Some(...) | main.rs:791:13:791:13 | _ | no-match | +| main.rs:789:18:789:18 | x | main.rs:789:18:789:18 | x | | +| main.rs:789:18:789:18 | x | main.rs:790:20:790:20 | x | match | +| main.rs:790:20:790:20 | x | main.rs:788:9:792:9 | match x { ... } | | +| main.rs:791:13:791:13 | _ | main.rs:791:18:791:18 | 0 | match | +| main.rs:791:18:791:18 | 0 | main.rs:788:9:792:9 | match x { ... } | | +| main.rs:793:9:797:9 | match x { ... } | main.rs:786:16:798:5 | { ... } | | +| main.rs:793:9:797:10 | ExprStmt | main.rs:793:15:793:15 | x | | +| main.rs:793:15:793:15 | x | main.rs:794:13:794:19 | Some(...) | | +| main.rs:794:13:794:19 | Some(...) | main.rs:794:18:794:18 | z | match | +| main.rs:794:13:794:19 | Some(...) | main.rs:796:13:796:13 | _ | no-match | +| main.rs:794:18:794:18 | z | main.rs:794:18:794:18 | z | | +| main.rs:794:18:794:18 | z | main.rs:795:17:795:17 | z | match | +| main.rs:794:18:794:18 | z | main.rs:796:13:796:13 | _ | no-match | +| main.rs:795:17:795:17 | z | main.rs:793:9:797:9 | match x { ... } | | +| main.rs:796:13:796:13 | _ | main.rs:796:18:796:18 | 0 | match | +| main.rs:796:18:796:18 | 0 | main.rs:793:9:797:9 | match x { ... } | | +| main.rs:801:1:845:1 | enter fn main | main.rs:802:5:802:25 | ExprStmt | | +| main.rs:801:1:845:1 | exit fn main (normal) | main.rs:801:1:845:1 | exit fn main | | +| main.rs:801:11:845:1 | { ... } | main.rs:801:1:845:1 | exit fn main (normal) | | +| main.rs:802:5:802:22 | immutable_variable | main.rs:802:5:802:24 | immutable_variable(...) | | +| main.rs:802:5:802:24 | immutable_variable(...) | main.rs:803:5:803:23 | ExprStmt | | +| main.rs:802:5:802:25 | ExprStmt | main.rs:802:5:802:22 | immutable_variable | | +| main.rs:803:5:803:20 | mutable_variable | main.rs:803:5:803:22 | mutable_variable(...) | | +| main.rs:803:5:803:22 | mutable_variable(...) | main.rs:804:5:804:40 | ExprStmt | | +| main.rs:803:5:803:23 | ExprStmt | main.rs:803:5:803:20 | mutable_variable | | +| main.rs:804:5:804:37 | mutable_variable_immutable_borrow | main.rs:804:5:804:39 | mutable_variable_immutable_borrow(...) | | +| main.rs:804:5:804:39 | mutable_variable_immutable_borrow(...) | main.rs:805:5:805:23 | ExprStmt | | +| main.rs:804:5:804:40 | ExprStmt | main.rs:804:5:804:37 | mutable_variable_immutable_borrow | | +| main.rs:805:5:805:20 | variable_shadow1 | main.rs:805:5:805:22 | variable_shadow1(...) | | +| main.rs:805:5:805:22 | variable_shadow1(...) | main.rs:806:5:806:23 | ExprStmt | | +| main.rs:805:5:805:23 | ExprStmt | main.rs:805:5:805:20 | variable_shadow1 | | +| main.rs:806:5:806:20 | variable_shadow2 | main.rs:806:5:806:22 | variable_shadow2(...) | | +| main.rs:806:5:806:22 | variable_shadow2(...) | main.rs:807:5:807:19 | ExprStmt | | +| main.rs:806:5:806:23 | ExprStmt | main.rs:806:5:806:20 | variable_shadow2 | | +| main.rs:807:5:807:16 | let_pattern1 | main.rs:807:5:807:18 | let_pattern1(...) | | +| main.rs:807:5:807:18 | let_pattern1(...) | main.rs:808:5:808:19 | ExprStmt | | +| main.rs:807:5:807:19 | ExprStmt | main.rs:807:5:807:16 | let_pattern1 | | +| main.rs:808:5:808:16 | let_pattern2 | main.rs:808:5:808:18 | let_pattern2(...) | | +| main.rs:808:5:808:18 | let_pattern2(...) | main.rs:809:5:809:19 | ExprStmt | | +| main.rs:808:5:808:19 | ExprStmt | main.rs:808:5:808:16 | let_pattern2 | | +| main.rs:809:5:809:16 | let_pattern3 | main.rs:809:5:809:18 | let_pattern3(...) | | +| main.rs:809:5:809:18 | let_pattern3(...) | main.rs:810:5:810:19 | ExprStmt | | +| main.rs:809:5:809:19 | ExprStmt | main.rs:809:5:809:16 | let_pattern3 | | +| main.rs:810:5:810:16 | let_pattern4 | main.rs:810:5:810:18 | let_pattern4(...) | | +| main.rs:810:5:810:18 | let_pattern4(...) | main.rs:811:5:811:21 | ExprStmt | | +| main.rs:810:5:810:19 | ExprStmt | main.rs:810:5:810:16 | let_pattern4 | | +| main.rs:811:5:811:18 | match_pattern1 | main.rs:811:5:811:20 | match_pattern1(...) | | +| main.rs:811:5:811:20 | match_pattern1(...) | main.rs:812:5:812:21 | ExprStmt | | +| main.rs:811:5:811:21 | ExprStmt | main.rs:811:5:811:18 | match_pattern1 | | +| main.rs:812:5:812:18 | match_pattern2 | main.rs:812:5:812:20 | match_pattern2(...) | | +| main.rs:812:5:812:20 | match_pattern2(...) | main.rs:813:5:813:21 | ExprStmt | | +| main.rs:812:5:812:21 | ExprStmt | main.rs:812:5:812:18 | match_pattern2 | | +| main.rs:813:5:813:18 | match_pattern3 | main.rs:813:5:813:20 | match_pattern3(...) | | +| main.rs:813:5:813:20 | match_pattern3(...) | main.rs:814:5:814:21 | ExprStmt | | +| main.rs:813:5:813:21 | ExprStmt | main.rs:813:5:813:18 | match_pattern3 | | +| main.rs:814:5:814:18 | match_pattern4 | main.rs:814:5:814:20 | match_pattern4(...) | | +| main.rs:814:5:814:20 | match_pattern4(...) | main.rs:815:5:815:21 | ExprStmt | | +| main.rs:814:5:814:21 | ExprStmt | main.rs:814:5:814:18 | match_pattern4 | | +| main.rs:815:5:815:18 | match_pattern5 | main.rs:815:5:815:20 | match_pattern5(...) | | +| main.rs:815:5:815:20 | match_pattern5(...) | main.rs:816:5:816:21 | ExprStmt | | +| main.rs:815:5:815:21 | ExprStmt | main.rs:815:5:815:18 | match_pattern5 | | +| main.rs:816:5:816:18 | match_pattern6 | main.rs:816:5:816:20 | match_pattern6(...) | | +| main.rs:816:5:816:20 | match_pattern6(...) | main.rs:817:5:817:21 | ExprStmt | | +| main.rs:816:5:816:21 | ExprStmt | main.rs:816:5:816:18 | match_pattern6 | | +| main.rs:817:5:817:18 | match_pattern7 | main.rs:817:5:817:20 | match_pattern7(...) | | +| main.rs:817:5:817:20 | match_pattern7(...) | main.rs:818:5:818:21 | ExprStmt | | +| main.rs:817:5:817:21 | ExprStmt | main.rs:817:5:817:18 | match_pattern7 | | +| main.rs:818:5:818:18 | match_pattern8 | main.rs:818:5:818:20 | match_pattern8(...) | | +| main.rs:818:5:818:20 | match_pattern8(...) | main.rs:819:5:819:21 | ExprStmt | | +| main.rs:818:5:818:21 | ExprStmt | main.rs:818:5:818:18 | match_pattern8 | | +| main.rs:819:5:819:18 | match_pattern9 | main.rs:819:5:819:20 | match_pattern9(...) | | +| main.rs:819:5:819:20 | match_pattern9(...) | main.rs:820:5:820:22 | ExprStmt | | +| main.rs:819:5:819:21 | ExprStmt | main.rs:819:5:819:18 | match_pattern9 | | +| main.rs:820:5:820:19 | match_pattern10 | main.rs:820:5:820:21 | match_pattern10(...) | | +| main.rs:820:5:820:21 | match_pattern10(...) | main.rs:821:5:821:22 | ExprStmt | | +| main.rs:820:5:820:22 | ExprStmt | main.rs:820:5:820:19 | match_pattern10 | | +| main.rs:821:5:821:19 | match_pattern11 | main.rs:821:5:821:21 | match_pattern11(...) | | +| main.rs:821:5:821:21 | match_pattern11(...) | main.rs:822:5:822:22 | ExprStmt | | +| main.rs:821:5:821:22 | ExprStmt | main.rs:821:5:821:19 | match_pattern11 | | +| main.rs:822:5:822:19 | match_pattern12 | main.rs:822:5:822:21 | match_pattern12(...) | | +| main.rs:822:5:822:21 | match_pattern12(...) | main.rs:823:5:823:22 | ExprStmt | | +| main.rs:822:5:822:22 | ExprStmt | main.rs:822:5:822:19 | match_pattern12 | | +| main.rs:823:5:823:19 | match_pattern13 | main.rs:823:5:823:21 | match_pattern13(...) | | +| main.rs:823:5:823:21 | match_pattern13(...) | main.rs:824:5:824:22 | ExprStmt | | +| main.rs:823:5:823:22 | ExprStmt | main.rs:823:5:823:19 | match_pattern13 | | +| main.rs:824:5:824:19 | match_pattern14 | main.rs:824:5:824:21 | match_pattern14(...) | | +| main.rs:824:5:824:21 | match_pattern14(...) | main.rs:825:5:825:22 | ExprStmt | | +| main.rs:824:5:824:22 | ExprStmt | main.rs:824:5:824:19 | match_pattern14 | | +| main.rs:825:5:825:19 | match_pattern15 | main.rs:825:5:825:21 | match_pattern15(...) | | +| main.rs:825:5:825:21 | match_pattern15(...) | main.rs:826:5:826:22 | ExprStmt | | +| main.rs:825:5:825:22 | ExprStmt | main.rs:825:5:825:19 | match_pattern15 | | +| main.rs:826:5:826:19 | match_pattern16 | main.rs:826:5:826:21 | match_pattern16(...) | | +| main.rs:826:5:826:21 | match_pattern16(...) | main.rs:827:5:827:36 | ExprStmt | | +| main.rs:826:5:826:22 | ExprStmt | main.rs:826:5:826:19 | match_pattern16 | | +| main.rs:827:5:827:18 | param_pattern1 | main.rs:827:20:827:22 | "a" | | +| main.rs:827:5:827:35 | param_pattern1(...) | main.rs:828:5:828:37 | ExprStmt | | +| main.rs:827:5:827:36 | ExprStmt | main.rs:827:5:827:18 | param_pattern1 | | +| main.rs:827:20:827:22 | "a" | main.rs:827:26:827:28 | "b" | | +| main.rs:827:25:827:34 | TupleExpr | main.rs:827:5:827:35 | param_pattern1(...) | | +| main.rs:827:26:827:28 | "b" | main.rs:827:31:827:33 | "c" | | +| main.rs:827:31:827:33 | "c" | main.rs:827:25:827:34 | TupleExpr | | +| main.rs:828:5:828:18 | param_pattern2 | main.rs:828:20:828:31 | ...::Left | | +| main.rs:828:5:828:36 | param_pattern2(...) | main.rs:829:5:829:26 | ExprStmt | | +| main.rs:828:5:828:37 | ExprStmt | main.rs:828:5:828:18 | param_pattern2 | | +| main.rs:828:20:828:31 | ...::Left | main.rs:828:33:828:34 | 45 | | +| main.rs:828:20:828:35 | ...::Left(...) | main.rs:828:5:828:36 | param_pattern2(...) | | +| main.rs:828:33:828:34 | 45 | main.rs:828:20:828:35 | ...::Left(...) | | +| main.rs:829:5:829:23 | destruct_assignment | main.rs:829:5:829:25 | destruct_assignment(...) | | +| main.rs:829:5:829:25 | destruct_assignment(...) | main.rs:830:5:830:23 | ExprStmt | | +| main.rs:829:5:829:26 | ExprStmt | main.rs:829:5:829:23 | destruct_assignment | | +| main.rs:830:5:830:20 | closure_variable | main.rs:830:5:830:22 | closure_variable(...) | | +| main.rs:830:5:830:22 | closure_variable(...) | main.rs:831:5:831:22 | ExprStmt | | +| main.rs:830:5:830:23 | ExprStmt | main.rs:830:5:830:20 | closure_variable | | +| main.rs:831:5:831:19 | nested_function | main.rs:831:5:831:21 | nested_function(...) | | +| main.rs:831:5:831:21 | nested_function(...) | main.rs:832:5:832:19 | ExprStmt | | +| main.rs:831:5:831:22 | ExprStmt | main.rs:831:5:831:19 | nested_function | | +| main.rs:832:5:832:16 | for_variable | main.rs:832:5:832:18 | for_variable(...) | | +| main.rs:832:5:832:18 | for_variable(...) | main.rs:833:5:833:17 | ExprStmt | | +| main.rs:832:5:832:19 | ExprStmt | main.rs:832:5:832:16 | for_variable | | +| main.rs:833:5:833:14 | add_assign | main.rs:833:5:833:16 | add_assign(...) | | +| main.rs:833:5:833:16 | add_assign(...) | main.rs:834:5:834:13 | ExprStmt | | +| main.rs:833:5:833:17 | ExprStmt | main.rs:833:5:833:14 | add_assign | | +| main.rs:834:5:834:10 | mutate | main.rs:834:5:834:12 | mutate(...) | | +| main.rs:834:5:834:12 | mutate(...) | main.rs:835:5:835:17 | ExprStmt | | +| main.rs:834:5:834:13 | ExprStmt | main.rs:834:5:834:10 | mutate | | +| main.rs:835:5:835:14 | mutate_arg | main.rs:835:5:835:16 | mutate_arg(...) | | +| main.rs:835:5:835:16 | mutate_arg(...) | main.rs:836:5:836:12 | ExprStmt | | +| main.rs:835:5:835:17 | ExprStmt | main.rs:835:5:835:14 | mutate_arg | | +| main.rs:836:5:836:9 | alias | main.rs:836:5:836:11 | alias(...) | | +| main.rs:836:5:836:11 | alias(...) | main.rs:837:5:837:18 | ExprStmt | | +| main.rs:836:5:836:12 | ExprStmt | main.rs:836:5:836:9 | alias | | +| main.rs:837:5:837:15 | capture_mut | main.rs:837:5:837:17 | capture_mut(...) | | +| main.rs:837:5:837:17 | capture_mut(...) | main.rs:838:5:838:20 | ExprStmt | | +| main.rs:837:5:837:18 | ExprStmt | main.rs:837:5:837:15 | capture_mut | | +| main.rs:838:5:838:17 | capture_immut | main.rs:838:5:838:19 | capture_immut(...) | | +| main.rs:838:5:838:19 | capture_immut(...) | main.rs:839:5:839:26 | ExprStmt | | +| main.rs:838:5:838:20 | ExprStmt | main.rs:838:5:838:17 | capture_immut | | +| main.rs:839:5:839:23 | async_block_capture | main.rs:839:5:839:25 | async_block_capture(...) | | +| main.rs:839:5:839:25 | async_block_capture(...) | main.rs:840:5:840:14 | ExprStmt | | +| main.rs:839:5:839:26 | ExprStmt | main.rs:839:5:839:23 | async_block_capture | | +| main.rs:840:5:840:11 | structs | main.rs:840:5:840:13 | structs(...) | | +| main.rs:840:5:840:13 | structs(...) | main.rs:841:5:841:14 | ExprStmt | | +| main.rs:840:5:840:14 | ExprStmt | main.rs:840:5:840:11 | structs | | +| main.rs:841:5:841:11 | ref_arg | main.rs:841:5:841:13 | ref_arg(...) | | +| main.rs:841:5:841:13 | ref_arg(...) | main.rs:842:5:842:30 | ExprStmt | | +| main.rs:841:5:841:14 | ExprStmt | main.rs:841:5:841:11 | ref_arg | | +| main.rs:842:5:842:27 | ref_methodcall_receiver | main.rs:842:5:842:29 | ref_methodcall_receiver(...) | | +| main.rs:842:5:842:29 | ref_methodcall_receiver(...) | main.rs:843:5:843:23 | ExprStmt | | +| main.rs:842:5:842:30 | ExprStmt | main.rs:842:5:842:27 | ref_methodcall_receiver | | +| main.rs:843:5:843:20 | macro_invocation | main.rs:843:5:843:22 | macro_invocation(...) | | +| main.rs:843:5:843:22 | macro_invocation(...) | main.rs:844:5:844:18 | ExprStmt | | +| main.rs:843:5:843:23 | ExprStmt | main.rs:843:5:843:20 | macro_invocation | | +| main.rs:844:5:844:15 | capture_phi | main.rs:844:5:844:17 | capture_phi(...) | | +| main.rs:844:5:844:17 | capture_phi(...) | main.rs:801:11:845:1 | { ... } | | +| main.rs:844:5:844:18 | ExprStmt | main.rs:844:5:844:15 | capture_phi | | breakTarget | main.rs:326:9:326:13 | break | main.rs:317:5:327:5 | while ... { ... } | continueTarget diff --git a/rust/ql/test/library-tests/variables/Ssa.expected b/rust/ql/test/library-tests/variables/Ssa.expected index 35adac478023..0acf3e94c5b5 100644 --- a/rust/ql/test/library-tests/variables/Ssa.expected +++ b/rust/ql/test/library-tests/variables/Ssa.expected @@ -196,6 +196,13 @@ definition | main.rs:748:17:750:9 | SSA phi(x) | main.rs:745:13:745:13 | x | | main.rs:749:13:749:13 | x | main.rs:745:13:745:13 | x | | main.rs:752:5:752:13 | x | main.rs:745:13:745:13 | x | +| main.rs:759:13:759:13 | x | main.rs:759:13:759:13 | x | +| main.rs:760:13:760:13 | y | main.rs:760:13:760:13 | y | +| main.rs:769:13:769:16 | N0ne | main.rs:769:13:769:16 | N0ne | +| main.rs:776:13:776:22 | test_alias | main.rs:776:13:776:22 | test_alias | +| main.rs:778:13:778:16 | test | main.rs:778:13:778:16 | test | +| main.rs:787:13:787:13 | x | main.rs:787:13:787:13 | x | +| main.rs:789:18:789:18 | x | main.rs:789:18:789:18 | x | read | main.rs:5:14:5:14 | s | main.rs:5:14:5:14 | s | main.rs:7:20:7:20 | s | | main.rs:10:14:10:14 | i | main.rs:10:14:10:14 | i | main.rs:12:20:12:20 | i | @@ -404,6 +411,14 @@ read | main.rs:746:13:746:15 | cap | main.rs:746:13:746:15 | cap | main.rs:752:5:752:7 | cap | | main.rs:746:20:746:20 | b | main.rs:746:20:746:20 | b | main.rs:748:20:748:20 | b | | main.rs:752:5:752:13 | x | main.rs:745:13:745:13 | x | main.rs:753:15:753:15 | x | +| main.rs:759:13:759:13 | x | main.rs:759:13:759:13 | x | main.rs:761:19:761:19 | x | +| main.rs:760:13:760:13 | y | main.rs:760:13:760:13 | y | main.rs:768:15:768:15 | y | +| main.rs:769:13:769:16 | N0ne | main.rs:769:13:769:16 | N0ne | main.rs:770:17:770:20 | N0ne | +| main.rs:776:13:776:22 | test_alias | main.rs:776:13:776:22 | test_alias | main.rs:779:13:779:22 | test_alias | +| main.rs:778:13:778:16 | test | main.rs:778:13:778:16 | test | main.rs:780:9:780:12 | test | +| main.rs:787:13:787:13 | x | main.rs:787:13:787:13 | x | main.rs:788:15:788:15 | x | +| main.rs:787:13:787:13 | x | main.rs:787:13:787:13 | x | main.rs:793:15:793:15 | x | +| main.rs:789:18:789:18 | x | main.rs:789:18:789:18 | x | main.rs:790:20:790:20 | x | firstRead | main.rs:5:14:5:14 | s | main.rs:5:14:5:14 | s | main.rs:7:20:7:20 | s | | main.rs:10:14:10:14 | i | main.rs:10:14:10:14 | i | main.rs:12:20:12:20 | i | @@ -570,6 +585,13 @@ firstRead | main.rs:746:13:746:15 | cap | main.rs:746:13:746:15 | cap | main.rs:752:5:752:7 | cap | | main.rs:746:20:746:20 | b | main.rs:746:20:746:20 | b | main.rs:748:20:748:20 | b | | main.rs:752:5:752:13 | x | main.rs:745:13:745:13 | x | main.rs:753:15:753:15 | x | +| main.rs:759:13:759:13 | x | main.rs:759:13:759:13 | x | main.rs:761:19:761:19 | x | +| main.rs:760:13:760:13 | y | main.rs:760:13:760:13 | y | main.rs:768:15:768:15 | y | +| main.rs:769:13:769:16 | N0ne | main.rs:769:13:769:16 | N0ne | main.rs:770:17:770:20 | N0ne | +| main.rs:776:13:776:22 | test_alias | main.rs:776:13:776:22 | test_alias | main.rs:779:13:779:22 | test_alias | +| main.rs:778:13:778:16 | test | main.rs:778:13:778:16 | test | main.rs:780:9:780:12 | test | +| main.rs:787:13:787:13 | x | main.rs:787:13:787:13 | x | main.rs:788:15:788:15 | x | +| main.rs:789:18:789:18 | x | main.rs:789:18:789:18 | x | main.rs:790:20:790:20 | x | adjacentReads | main.rs:27:5:27:6 | x2 | main.rs:25:13:25:14 | x2 | main.rs:28:15:28:16 | x2 | main.rs:29:10:29:11 | x2 | | main.rs:41:9:41:10 | x3 | main.rs:41:9:41:10 | x3 | main.rs:42:15:42:16 | x3 | main.rs:44:9:44:10 | x3 | @@ -616,6 +638,7 @@ adjacentReads | main.rs:676:13:676:13 | a | main.rs:676:13:676:13 | a | main.rs:677:15:677:15 | a | main.rs:678:5:678:5 | a | | main.rs:676:13:676:13 | a | main.rs:676:13:676:13 | a | main.rs:678:5:678:5 | a | main.rs:679:15:679:15 | a | | main.rs:685:9:685:9 | x | main.rs:685:9:685:9 | x | main.rs:686:20:686:20 | x | main.rs:687:15:687:15 | x | +| main.rs:787:13:787:13 | x | main.rs:787:13:787:13 | x | main.rs:788:15:788:15 | x | main.rs:793:15:793:15 | x | phi | main.rs:210:9:210:44 | SSA phi(a3) | main.rs:210:9:210:44 | a3 | main.rs:210:22:210:23 | a3 | | main.rs:210:9:210:44 | SSA phi(a3) | main.rs:210:9:210:44 | a3 | main.rs:210:42:210:43 | a3 | @@ -773,3 +796,8 @@ assigns | main.rs:745:13:745:13 | x | main.rs:745:17:745:19 | 100 | | main.rs:746:13:746:15 | cap | main.rs:746:19:751:5 | \|...\| ... | | main.rs:749:13:749:13 | x | main.rs:749:17:749:19 | 200 | +| main.rs:759:13:759:13 | x | main.rs:759:17:759:24 | Some(...) | +| main.rs:760:13:760:13 | y | main.rs:761:13:767:9 | match x { ... } | +| main.rs:776:13:776:22 | test_alias | main.rs:777:13:777:16 | test | +| main.rs:778:13:778:16 | test | main.rs:779:13:779:24 | test_alias(...) | +| main.rs:787:13:787:13 | x | main.rs:787:17:787:23 | Some(...) | diff --git a/rust/ql/test/library-tests/variables/main.rs b/rust/ql/test/library-tests/variables/main.rs index cdfe1091ee39..fe13f89b1775 100644 --- a/rust/ql/test/library-tests/variables/main.rs +++ b/rust/ql/test/library-tests/variables/main.rs @@ -753,6 +753,51 @@ fn capture_phi() { print_i64(x); // $ read_access=x } +mod patterns { + #[rustfmt::skip] + pub fn test() -> Option { + let x = Some(42); // x + let y : Option = // y1 + match x { // $ read_access=x + Some(y) => { // y2 + None + } + None => + None + }; + match y { // $ read_access=y1 + N0ne => // n0ne + N0ne // $ read_access=n0ne + } + } + + #[rustfmt::skip] + fn test2() -> Option { + let test_alias = // test_alias + test; + let test = // test + test_alias(); // $ read_access=test_alias + test // $ read_access=test + } + + const z: i32 = 0; + + #[rustfmt::skip] + fn test3() { + let x = Some(0); // x1 + match x { // $ read_access=x1 + Some(x) // x2 + => x, // $ read_access=x2 + _ => 0 + }; + match x { // $ read_access=x1 + Some(z) => + z, + _ => 0 + }; + } +} + fn main() { immutable_variable(); mutable_variable(); diff --git a/rust/ql/test/library-tests/variables/variables.expected b/rust/ql/test/library-tests/variables/variables.expected index 64431803e6d0..ea360357d970 100644 --- a/rust/ql/test/library-tests/variables/variables.expected +++ b/rust/ql/test/library-tests/variables/variables.expected @@ -142,6 +142,14 @@ variable | main.rs:745:13:745:13 | x | | main.rs:746:13:746:15 | cap | | main.rs:746:20:746:20 | b | +| main.rs:759:13:759:13 | x | +| main.rs:760:13:760:13 | y | +| main.rs:762:18:762:18 | y | +| main.rs:769:13:769:16 | N0ne | +| main.rs:776:13:776:22 | test_alias | +| main.rs:778:13:778:16 | test | +| main.rs:787:13:787:13 | x | +| main.rs:789:18:789:18 | x | variableAccess | main.rs:7:20:7:20 | s | main.rs:5:14:5:14 | s | | main.rs:12:20:12:20 | i | main.rs:10:14:10:14 | i | @@ -364,6 +372,14 @@ variableAccess | main.rs:749:13:749:13 | x | main.rs:745:13:745:13 | x | | main.rs:752:5:752:7 | cap | main.rs:746:13:746:15 | cap | | main.rs:753:15:753:15 | x | main.rs:745:13:745:13 | x | +| main.rs:761:19:761:19 | x | main.rs:759:13:759:13 | x | +| main.rs:768:15:768:15 | y | main.rs:760:13:760:13 | y | +| main.rs:770:17:770:20 | N0ne | main.rs:769:13:769:16 | N0ne | +| main.rs:779:13:779:22 | test_alias | main.rs:776:13:776:22 | test_alias | +| main.rs:780:9:780:12 | test | main.rs:778:13:778:16 | test | +| main.rs:788:15:788:15 | x | main.rs:787:13:787:13 | x | +| main.rs:790:20:790:20 | x | main.rs:789:18:789:18 | x | +| main.rs:793:15:793:15 | x | main.rs:787:13:787:13 | x | variableWriteAccess | main.rs:27:5:27:6 | x2 | main.rs:25:13:25:14 | x2 | | main.rs:29:5:29:6 | x2 | main.rs:25:13:25:14 | x2 | @@ -576,6 +592,14 @@ variableReadAccess | main.rs:748:20:748:20 | b | main.rs:746:20:746:20 | b | | main.rs:752:5:752:7 | cap | main.rs:746:13:746:15 | cap | | main.rs:753:15:753:15 | x | main.rs:745:13:745:13 | x | +| main.rs:761:19:761:19 | x | main.rs:759:13:759:13 | x | +| main.rs:768:15:768:15 | y | main.rs:760:13:760:13 | y | +| main.rs:770:17:770:20 | N0ne | main.rs:769:13:769:16 | N0ne | +| main.rs:779:13:779:22 | test_alias | main.rs:776:13:776:22 | test_alias | +| main.rs:780:9:780:12 | test | main.rs:778:13:778:16 | test | +| main.rs:788:15:788:15 | x | main.rs:787:13:787:13 | x | +| main.rs:790:20:790:20 | x | main.rs:789:18:789:18 | x | +| main.rs:793:15:793:15 | x | main.rs:787:13:787:13 | x | variableInitializer | main.rs:20:9:20:10 | x1 | main.rs:20:14:20:16 | "a" | | main.rs:25:13:25:14 | x2 | main.rs:25:18:25:18 | 4 | @@ -649,6 +673,11 @@ variableInitializer | main.rs:734:15:734:28 | var_in_macro | main.rs:734:15:734:28 | 0 | | main.rs:745:13:745:13 | x | main.rs:745:17:745:19 | 100 | | main.rs:746:13:746:15 | cap | main.rs:746:19:751:5 | \|...\| ... | +| main.rs:759:13:759:13 | x | main.rs:759:17:759:24 | Some(...) | +| main.rs:760:13:760:13 | y | main.rs:761:13:767:9 | match x { ... } | +| main.rs:776:13:776:22 | test_alias | main.rs:777:13:777:16 | test | +| main.rs:778:13:778:16 | test | main.rs:779:13:779:24 | test_alias(...) | +| main.rs:787:13:787:13 | x | main.rs:787:17:787:23 | Some(...) | capturedVariable | main.rs:557:9:557:9 | x | | main.rs:568:13:568:13 | x |