@@ -267,6 +267,18 @@ fn add_query_desc_cached_impl(
267267) {
268268 let Query { name, key, modifiers, .. } = & query;
269269
270+ // This dead code exists to instruct rust-analyzer about the link between the `rustc_queries`
271+ // query names and the corresponding produced provider. The issue is that by nature of this
272+ // macro producing a higher order macro that has all its token in the macro declaration we lose
273+ // any meaningful spans, resulting in rust-analyzer being unable to make the connection between
274+ // the query name and the corresponding providers field. The trick to fix this is to have
275+ // `rustc_queries` emit a field access with the given name's span which allows it to succesfully
276+ // show references / go to definition to the correspondig provider assignment which is usually
277+ // the more interesting place.
278+ let ra_hint = quote ! {
279+ let crate :: query:: Providers { #name: _, .. } ;
280+ } ;
281+
270282 // Find out if we should cache the query on disk
271283 let cache = if let Some ( ( args, expr) ) = modifiers. cache . as_ref ( ) {
272284 let tcx = args. as_ref ( ) . map ( |t| quote ! { #t } ) . unwrap_or_else ( || quote ! { _ } ) ;
@@ -277,6 +289,7 @@ fn add_query_desc_cached_impl(
277289 #[ allow( unused_variables, unused_braces, rustc:: pass_by_value) ]
278290 #[ inline]
279291 pub fn #name<' tcx>( #tcx: TyCtxt <' tcx>, #key: & crate :: query:: queries:: #name:: Key <' tcx>) -> bool {
292+ #ra_hint
280293 #expr
281294 }
282295 }
@@ -286,6 +299,7 @@ fn add_query_desc_cached_impl(
286299 #[ allow( rustc:: pass_by_value) ]
287300 #[ inline]
288301 pub fn #name<' tcx>( _: TyCtxt <' tcx>, _: & crate :: query:: queries:: #name:: Key <' tcx>) -> bool {
302+ #ra_hint
289303 false
290304 }
291305 }
0 commit comments