diff options
| author | Matthias Krüger <476013+matthiaskrgr@users.noreply.github.com> | 2025-05-17 15:45:21 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-17 15:45:21 +0200 |
| commit | 57a400d7c12a0c9dae6bc0d7b26ee67ebeeadae0 (patch) | |
| tree | 8693aa281e6ac909d5c043bb5ce9c6515b97adfe | |
| parent | 73ea8d7fdcad7e901a61e256b43dc1f8516984ff (diff) | |
| parent | 1c9f20f24c9363eedaf5ea16f7e8f8746c80e1e8 (diff) | |
| download | rust-57a400d7c12a0c9dae6bc0d7b26ee67ebeeadae0.tar.gz rust-57a400d7c12a0c9dae6bc0d7b26ee67ebeeadae0.zip | |
Rollup merge of #141118 - Veykril:lw-ymmtxytkrrqs, r=compiler-errors
Enable rust-analyzer to go from query definition to the corresponding provider field r? `@compiler-errors`
| -rw-r--r-- | compiler/rustc_macros/src/query.rs | 14 |
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 } } |
