@@ -199,7 +199,7 @@ impl Parse for Group {
199
199
200
200
struct QueryModifiers {
201
201
/// The description of the query.
202
- desc : Option < ( Option < Ident > , Punctuated < Expr , Token ! [ , ] > ) > ,
202
+ desc : ( Option < Ident > , Punctuated < Expr , Token ! [ , ] > ) ,
203
203
204
204
/// Use this type for the in-memory cache.
205
205
storage : Option < Type > ,
@@ -295,6 +295,9 @@ fn process_modifiers(query: &mut Query) -> QueryModifiers {
295
295
}
296
296
}
297
297
}
298
+ let desc = desc. unwrap_or_else ( || {
299
+ panic ! ( "no description provided for query `{}`" , query. name) ;
300
+ } ) ;
298
301
QueryModifiers {
299
302
load_cached,
300
303
storage,
@@ -319,7 +322,7 @@ fn add_query_description_impl(
319
322
let key = & query. key . 0 ;
320
323
321
324
// Find out if we should cache the query on disk
322
- let cache = modifiers . cache . as_ref ( ) . map ( | ( args, expr) | {
325
+ let cache = if let Some ( ( args, expr) ) = modifiers . cache . as_ref ( ) {
323
326
let try_load_from_disk = if let Some ( ( tcx, id, block) ) = modifiers. load_cached . as_ref ( ) {
324
327
// Use custom code to load the query from disk
325
328
quote ! {
@@ -373,36 +376,32 @@ fn add_query_description_impl(
373
376
374
377
#try_load_from_disk
375
378
}
376
- } ) ;
377
-
378
- if cache. is_none ( ) && modifiers. load_cached . is_some ( ) {
379
- panic ! ( "load_cached modifier on query `{}` without a cache modifier" , name) ;
380
- }
379
+ } else {
380
+ if modifiers. load_cached . is_some ( ) {
381
+ panic ! ( "load_cached modifier on query `{}` without a cache modifier" , name) ;
382
+ }
383
+ quote ! { }
384
+ } ;
385
+
386
+ let ( tcx, desc) = modifiers. desc ;
387
+ let tcx = tcx. as_ref ( ) . map ( |t| quote ! { #t } ) . unwrap_or ( quote ! { _ } ) ;
388
+
389
+ let desc = quote ! {
390
+ #[ allow( unused_variables) ]
391
+ fn describe(
392
+ #tcx: TyCtxt <' tcx>,
393
+ #key: #arg,
394
+ ) -> Cow <' static , str > {
395
+ format!( #desc) . into( )
396
+ }
397
+ } ;
381
398
382
- let desc = modifiers. desc . as_ref ( ) . map ( |( tcx, desc) | {
383
- let tcx = tcx. as_ref ( ) . map ( |t| quote ! { #t } ) . unwrap_or ( quote ! { _ } ) ;
384
- quote ! {
385
- #[ allow( unused_variables) ]
386
- fn describe(
387
- #tcx: TyCtxt <' tcx>,
388
- #key: #arg,
389
- ) -> Cow <' static , str > {
390
- format!( #desc) . into( )
391
- }
399
+ impls. extend ( quote ! {
400
+ impl <' tcx> QueryDescription <TyCtxt <' tcx>> for queries:: #name<' tcx> {
401
+ #desc
402
+ #cache
392
403
}
393
404
} ) ;
394
-
395
- if desc. is_some ( ) || cache. is_some ( ) {
396
- let cache = cache. unwrap_or ( quote ! { } ) ;
397
- let desc = desc. unwrap_or ( quote ! { } ) ;
398
-
399
- impls. extend ( quote ! {
400
- impl <' tcx> QueryDescription <TyCtxt <' tcx>> for queries:: #name<' tcx> {
401
- #desc
402
- #cache
403
- }
404
- } ) ;
405
- }
406
405
}
407
406
408
407
pub fn rustc_queries ( input : TokenStream ) -> TokenStream {
0 commit comments