@@ -267,6 +267,18 @@ fn add_query_desc_cached_impl(
267
267
) {
268
268
let Query { name, key, modifiers, .. } = & query;
269
269
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
+
270
282
// Find out if we should cache the query on disk
271
283
let cache = if let Some ( ( args, expr) ) = modifiers. cache . as_ref ( ) {
272
284
let tcx = args. as_ref ( ) . map ( |t| quote ! { #t } ) . unwrap_or_else ( || quote ! { _ } ) ;
@@ -277,6 +289,7 @@ fn add_query_desc_cached_impl(
277
289
#[ allow( unused_variables, unused_braces, rustc:: pass_by_value) ]
278
290
#[ inline]
279
291
pub fn #name<' tcx>( #tcx: TyCtxt <' tcx>, #key: & crate :: query:: queries:: #name:: Key <' tcx>) -> bool {
292
+ #ra_hint
280
293
#expr
281
294
}
282
295
}
@@ -286,6 +299,7 @@ fn add_query_desc_cached_impl(
286
299
#[ allow( rustc:: pass_by_value) ]
287
300
#[ inline]
288
301
pub fn #name<' tcx>( _: TyCtxt <' tcx>, _: & crate :: query:: queries:: #name:: Key <' tcx>) -> bool {
302
+ #ra_hint
289
303
false
290
304
}
291
305
}
0 commit comments