44
55private import rust
66private import codeql.rust.elements.internal.generated.ParentChild
7+ private import codeql.rust.elements.internal.AstNodeImpl:: Impl as AstNodeImpl
78private import codeql.rust.elements.internal.CallExprImpl:: Impl as CallExprImpl
89private import codeql.rust.internal.CachedStages
910private import codeql.rust.frameworks.stdlib.Builtins as Builtins
@@ -90,24 +91,6 @@ private module UseOption = Option<Use>;
9091
9192private class UseOption = UseOption:: Option ;
9293
93- /**
94- * Holds if `n` is superseded by an attribute macro expansion. That is, `n` is
95- * an item or a transitive child of an item with an attribute macro expansion.
96- */
97- predicate supersededByAttributeMacroExpansion ( AstNode n ) {
98- n .( Item ) .hasAttributeMacroExpansion ( )
99- or
100- exists ( AstNode parent |
101- n .getParentNode ( ) = parent and
102- supersededByAttributeMacroExpansion ( parent ) and
103- // Don't exclude expansions themselves as they supercede other nodes.
104- not n = parent .( Item ) .getAttributeMacroExpansion ( ) and
105- // Don't consider attributes themselves to be superseded. E.g., in `#[a] fn
106- // f() {}` the macro expansion supercedes `fn f() {}` but not `#[a]`.
107- not n instanceof Attr
108- )
109- }
110-
11194/**
11295 * An item that may be referred to by a path, and which is a node in
11396 * the _item graph_.
@@ -188,7 +171,7 @@ predicate supersededByAttributeMacroExpansion(AstNode n) {
188171abstract class ItemNode extends Locatable {
189172 ItemNode ( ) {
190173 // Exclude items that are superseded by the expansion of an attribute macro.
191- not supersededByAttributeMacroExpansion ( this )
174+ not AstNodeImpl :: supersededByAttributeMacroExpansion ( this )
192175 }
193176
194177 /** Gets the (original) name of this item. */
@@ -1531,6 +1514,8 @@ private predicate declares(ItemNode item, Namespace ns, string name) {
15311514 * to constructors in patterns.
15321515 */
15331516abstract class PathExt extends AstNode {
1517+ PathExt ( ) { not AstNodeImpl:: supersededByAttributeMacroExpansion ( this ) }
1518+
15341519 abstract string getText ( ) ;
15351520
15361521 /** Holds if this is an unqualified path with the textual value `name`. */
@@ -1975,7 +1960,10 @@ private ItemNode resolvePathCand(PathExt path) {
19751960 then result instanceof TypeItemNode
19761961 else
19771962 if path instanceof IdentPat
1978- then result instanceof VariantItemNode or result instanceof StructItemNode
1963+ then
1964+ result instanceof VariantItemNode or
1965+ result instanceof StructItemNode or
1966+ result instanceof ConstItemNode
19791967 else any ( )
19801968 |
19811969 pathUsesNamespace ( path , ns )
@@ -2066,6 +2054,13 @@ private ItemNode resolveUseTreeListItem(Use use, UseTree tree, PathExt path, Suc
20662054 result = q .getASuccessor ( name , kind , useOpt )
20672055 )
20682056 )
2057+ // or
2058+ // // use {std::cmp::Ordering::*, AdjustmentHintsMode::*};
2059+ // tree = use.getUseTree() and
2060+ // not tree.hasPath() and
2061+ // isUseTreeSubPathUnqualified(tree, path, _) and
2062+ // result = resolvePathCand(path) and
2063+ // kind.isBoth() // todo
20692064}
20702065
20712066pragma [ nomagic]
@@ -2093,6 +2088,7 @@ private ItemNode resolveUseTreeListItem(Use use, UseTree tree) {
20932088 result = resolveUseTreeListItem ( use , tree , path , _)
20942089 )
20952090 or
2091+ // use foo::{bar, *}
20962092 exists ( UseTree midTree |
20972093 result = resolveUseTreeListItem ( use , midTree ) and
20982094 tree = getAUseTreeUseTree ( midTree ) and
@@ -2217,8 +2213,12 @@ private module Debug {
22172213 Locatable getRelevantLocatable ( ) {
22182214 exists ( string filepath , int startline , int startcolumn , int endline , int endcolumn |
22192215 result .getLocation ( ) .hasLocationInfo ( filepath , startline , startcolumn , endline , endcolumn ) and
2220- filepath .matches ( "%/main.rs" ) and
2221- startline = 800
2216+ // filepath.matches("%/src/tools/rust-analyzer/crates/ide/src/inlay_hints/adjustment.rs") and
2217+ // startline = [6, 227]
2218+ // filepath.matches("%/compiler/rustc_middle/src/ty/layout.rs") and
2219+ // startline = 36
2220+ filepath .matches ( "%/cranelift-codegen-943c3c0c33bda67e/out/isle_riscv64.rs" ) and
2221+ startline = 11
22222222 )
22232223 }
22242224
@@ -2233,9 +2233,14 @@ private module Debug {
22332233 path = p .toStringDebug ( )
22342234 }
22352235
2236+ ItemNode debugUnqualifiedPathLookup ( PathExt p , Namespace ns , SuccessorKind kind ) {
2237+ p = getRelevantLocatable ( ) and
2238+ result = unqualifiedPathLookup ( p , ns , kind )
2239+ }
2240+
22362241 predicate debugItemNode ( ItemNode item ) { item = getRelevantLocatable ( ) }
22372242
2238- ItemNode debugResolvePath ( PathExt path ) {
2243+ ItemNode debugResolvePath ( Path path ) {
22392244 path = getRelevantLocatable ( ) and
22402245 result = resolvePath ( path )
22412246 }
0 commit comments