@@ -273,38 +273,6 @@ fn doc_comment_from_desc(list: &Punctuated<Expr, token::Comma>) -> Result<Attrib
273273 Ok ( parse_quote ! { #[ doc = #doc_string] } )
274274}
275275
276- /// Contains token streams that are used to accumulate per-query helper
277- /// functions, to be used by the final output of `rustc_queries!`.
278- ///
279- /// Helper items typically have the same name as the query they relate to,
280- /// and expect to be interpolated into a dedicated module.
281- #[ derive( Default ) ]
282- struct HelperTokenStreams {
283- cache_on_disk_if_fns_stream : proc_macro2:: TokenStream ,
284- }
285-
286- fn make_helpers_for_query ( query : & Query , streams : & mut HelperTokenStreams ) {
287- let Query { name, key_pat, key_ty, modifiers, .. } = & query;
288-
289- // Replace span for `name` to make rust-analyzer ignore it.
290- let mut erased_name = name. clone ( ) ;
291- erased_name. set_span ( Span :: call_site ( ) ) ;
292-
293- // Generate a function to check whether we should cache the query to disk, for some key.
294- if let Some ( CacheOnDiskIf { block, .. } ) = modifiers. cache_on_disk_if . as_ref ( ) {
295- // `pass_by_value`: some keys are marked with `rustc_pass_by_value`, but we take keys by
296- // reference here.
297- // FIXME: `pass_by_value` is badly named; `allow(rustc::pass_by_value)` actually means
298- // "allow pass by reference of `rustc_pass_by_value` types".
299- streams. cache_on_disk_if_fns_stream . extend ( quote ! {
300- #[ allow( unused_variables, rustc:: pass_by_value) ]
301- #[ inline]
302- pub fn #erased_name<' tcx>( tcx: TyCtxt <' tcx>, #key_pat: & #key_ty) -> bool
303- #block
304- } ) ;
305- }
306- }
307-
308276/// Add hints for rust-analyzer
309277fn add_to_analyzer_stream ( query : & Query , analyzer_stream : & mut proc_macro2:: TokenStream ) {
310278 // Add links to relevant modifiers
@@ -384,7 +352,6 @@ pub(super) fn rustc_queries(input: TokenStream) -> TokenStream {
384352 let queries = parse_macro_input ! ( input as List <Query >) ;
385353
386354 let mut query_stream = quote ! { } ;
387- let mut helpers = HelperTokenStreams :: default ( ) ;
388355 let mut analyzer_stream = quote ! { } ;
389356 let mut errors = quote ! { } ;
390357
@@ -435,11 +402,23 @@ pub(super) fn rustc_queries(input: TokenStream) -> TokenStream {
435402 return_result_from_ensure_ok,
436403 ) ;
437404
438- // If there was a `cache_on_disk_if` modifier in the real input, pass
439- // on a synthetic `(cache_on_disk)` modifier that can be inspected by
440- // macro-rules macros.
441- if modifiers. cache_on_disk_if . is_some ( ) {
442- modifiers_out. push ( quote ! { ( cache_on_disk) } ) ;
405+ // If there was a `cache_on_disk_if` modifier, put a closure inside it:
406+ // `(cache_on_disk { <closure > }`.
407+ if let Some ( CacheOnDiskIf { block, .. } ) = & modifiers. cache_on_disk_if {
408+ modifiers_out. push ( quote ! {
409+ ( cache_on_disk_if {
410+ // `pass_by_value`: some keys are marked with `rustc_pass_by_value`, but we
411+ // take keys by reference here.
412+ // FIXME: `pass_by_value` is badly named; `allow(rustc::pass_by_value)`
413+ // actually means "allow pass by reference of `rustc_pass_by_value` types".
414+ //
415+ // The type annotations are required to avoid compile errors, which is annoying
416+ // because it necessitates extra `use` items in the file using
417+ // `rustc_with_all_queries!`.
418+ #[ allow( rustc:: pass_by_value) ]
419+ |tcx: TyCtxt <' _>, #key_pat: & #key_ty| #block
420+ } )
421+ } ) ;
443422 }
444423
445424 // This uses the span of the query definition for the commas,
@@ -472,11 +451,8 @@ pub(super) fn rustc_queries(input: TokenStream) -> TokenStream {
472451 }
473452
474453 add_to_analyzer_stream ( & query, & mut analyzer_stream) ;
475- make_helpers_for_query ( & query, & mut helpers) ;
476454 }
477455
478- let HelperTokenStreams { cache_on_disk_if_fns_stream } = helpers;
479-
480456 TokenStream :: from ( quote ! {
481457 /// Higher-order macro that invokes the specified macro with a prepared
482458 /// list of all query signatures (including modifiers).
@@ -506,14 +482,6 @@ pub(super) fn rustc_queries(input: TokenStream) -> TokenStream {
506482 #analyzer_stream
507483 }
508484
509- // FIXME(Zalathar): Instead of declaring these functions directly, can
510- // we put them in a macro and then expand that macro downstream in
511- // `rustc_query_impl`, where the functions are actually used?
512- pub mod _cache_on_disk_if_fns {
513- use super :: * ;
514- #cache_on_disk_if_fns_stream
515- }
516-
517485 #errors
518486 } )
519487}
0 commit comments