Rust: Use macro call location as fall back in macro expansions

This commit is contained in:
Tom Hvitved
2025-04-04 11:21:19 +02:00
parent 68f6f9f2e8
commit 5731fa91f3
4 changed files with 23 additions and 49 deletions

View File

@@ -46,11 +46,25 @@ module Impl {
predicate fromSource() { exists(this.getFile().getRelativePath()) }
}
/** Gets the non-synthesized location of `l`, if any. */
LocationImpl::LocationDefault getLocationDefault(Locatable l) {
exists(@location_default location |
result = LocationImpl::TLocationDefault(location) and
locatable_locations(Synth::convertLocatableToRaw(l), location)
private @location_default getDbLocation(Locatable l) {
locatable_locations(Synth::convertLocatableToRaw(l), result)
}
private MacroCall getImmediatelyEnclosingMacroCall(AstNode n) {
result = n.getParentNode()
or
exists(AstNode mid |
result = getImmediatelyEnclosingMacroCall(mid) and
n.getParentNode() = mid and
not mid instanceof MacroCall
)
}
/** Gets the non-synthesized location of `l`, if any. */
LocationImpl::LocationDefault getLocationDefault(Locatable l) {
result = LocationImpl::TLocationDefault(getDbLocation(l))
or
not exists(getDbLocation(l)) and
result = getLocationDefault(getImmediatelyEnclosingMacroCall(l))
}
}

View File

@@ -25,7 +25,8 @@ query predicate multipleLocations(Locatable e) { strictcount(e.getLocation()) >
* Holds if `e` does not have a `Location`.
*/
query predicate noLocation(Locatable e) {
not exists(e.getLocation()) and not e.(AstNode).getParentNode*() = any(Crate c).getModule()
not exists(e.getLocation()) and
not e.(AstNode).getParentNode*() = any(Crate c).getModule()
}
private predicate multiplePrimaryQlClasses(Element e) {

View File

@@ -1,41 +0,0 @@
noLocation
| file://:0:0:0:0 | ... .unwrap() |
| file://:0:0:0:0 | ...: ... |
| file://:0:0:0:0 | ...::Path |
| file://:0:0:0:0 | ...::Path |
| file://:0:0:0:0 | ...::path |
| file://:0:0:0:0 | ArgList |
| file://:0:0:0:0 | ArgList |
| file://:0:0:0:0 | ParamList |
| file://:0:0:0:0 | Path |
| file://:0:0:0:0 | Path |
| file://:0:0:0:0 | Path |
| file://:0:0:0:0 | Path |
| file://:0:0:0:0 | Path |
| file://:0:0:0:0 | Path |
| file://:0:0:0:0 | Path |
| file://:0:0:0:0 | Path |
| file://:0:0:0:0 | Path |
| file://:0:0:0:0 | Path |
| file://:0:0:0:0 | RefTypeRepr |
| file://:0:0:0:0 | RefTypeRepr |
| file://:0:0:0:0 | RetTypeRepr |
| file://:0:0:0:0 | StmtList |
| file://:0:0:0:0 | fn get_parent |
| file://:0:0:0:0 | get_parent |
| file://:0:0:0:0 | parent |
| file://:0:0:0:0 | path |
| file://:0:0:0:0 | path |
| file://:0:0:0:0 | path |
| file://:0:0:0:0 | path |
| file://:0:0:0:0 | path |
| file://:0:0:0:0 | path |
| file://:0:0:0:0 | path |
| file://:0:0:0:0 | path |
| file://:0:0:0:0 | path.parent() |
| file://:0:0:0:0 | std |
| file://:0:0:0:0 | std |
| file://:0:0:0:0 | std |
| file://:0:0:0:0 | unwrap |
| file://:0:0:0:0 | use ...::Path |
| file://:0:0:0:0 | { ... } |

View File

@@ -1,2 +1,2 @@
| gen_macro_items.rs:5:5:5:38 | MacroItems | 0 | file://:0:0:0:0 | use ...::Path |
| gen_macro_items.rs:5:5:5:38 | MacroItems | 1 | file://:0:0:0:0 | fn get_parent |
| gen_macro_items.rs:5:5:5:38 | MacroItems | 0 | gen_macro_items.rs:5:5:5:38 | use ...::Path |
| gen_macro_items.rs:5:5:5:38 | MacroItems | 1 | gen_macro_items.rs:5:5:5:38 | fn get_parent |