about summary refs log tree commit diff
path: root/compiler/rustc_macros/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2025-05-17 16:28:16 +0000
committerbors <bors@rust-lang.org>2025-05-17 16:28:16 +0000
commitbf5a38d118a46fb5fdff90e3dc3cbb58fe618c46 (patch)
tree56a95707530044382d6802e830aad804ca1e16ee /compiler/rustc_macros/src
parent2c12b4a690c8201a3c79f404eec38614684c412c (diff)
parent339a46cb727842127eab6212ab13fbb620785312 (diff)
downloadrust-bf5a38d118a46fb5fdff90e3dc3cbb58fe618c46.tar.gz
rust-bf5a38d118a46fb5fdff90e3dc3cbb58fe618c46.zip
Auto merge of #141133 - matthiaskrgr:rollup-u8ndxyz, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #135808 (Implement Display for ``rustc_target::callconv::Conv``)
 - #137432 (Add as_ascii_unchecked() methods to char, u8, and str)
 - #139103 (deduplicate abort implementations)
 - #140917 (checktools.sh: fix bashism)
 - #141035 (turn lld warning on old gccs into info log)
 - #141118 (Enable rust-analyzer to go from query definition to the corresponding provider field)
 - #141121 (Only select true errors in `impossible_predicates`)
 - #141125 (check coroutines with `TypingMode::Borrowck` to avoid cyclic reasoning)
 - #141131 (Make some `match`es slightly more ergonomic in `librustdoc`)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_macros/src')
-rw-r--r--compiler/rustc_macros/src/query.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/compiler/rustc_macros/src/query.rs b/compiler/rustc_macros/src/query.rs
index 33fb13e23bf..ee377277017 100644
--- a/compiler/rustc_macros/src/query.rs
+++ b/compiler/rustc_macros/src/query.rs
@@ -267,6 +267,18 @@ fn add_query_desc_cached_impl(
 ) {
     let Query { name, key, modifiers, .. } = &query;
 
+    // This dead code exists to instruct rust-analyzer about the link between the `rustc_queries`
+    // query names and the corresponding produced provider. The issue is that by nature of this
+    // macro producing a higher order macro that has all its token in the macro declaration we lose
+    // any meaningful spans, resulting in rust-analyzer being unable to make the connection between
+    // the query name and the corresponding providers field. The trick to fix this is to have
+    // `rustc_queries` emit a field access with the given name's span which allows it to succesfully
+    // show references / go to definition to the correspondig provider assignment which is usually
+    // the more interesting place.
+    let ra_hint = quote! {
+        let crate::query::Providers { #name: _, .. };
+    };
+
     // Find out if we should cache the query on disk
     let cache = if let Some((args, expr)) = modifiers.cache.as_ref() {
         let tcx = args.as_ref().map(|t| quote! { #t }).unwrap_or_else(|| quote! { _ });
@@ -277,6 +289,7 @@ fn add_query_desc_cached_impl(
             #[allow(unused_variables, unused_braces, rustc::pass_by_value)]
             #[inline]
             pub fn #name<'tcx>(#tcx: TyCtxt<'tcx>, #key: &crate::query::queries::#name::Key<'tcx>) -> bool {
+                #ra_hint
                 #expr
             }
         }
@@ -286,6 +299,7 @@ fn add_query_desc_cached_impl(
             #[allow(rustc::pass_by_value)]
             #[inline]
             pub fn #name<'tcx>(_: TyCtxt<'tcx>, _: &crate::query::queries::#name::Key<'tcx>) -> bool {
+                #ra_hint
                 false
             }
         }