@@ -2285,10 +2285,17 @@ impl CheckAttrVisitor<'_> {
2285
2285
}
2286
2286
2287
2287
let tcx = self . tcx ;
2288
- let Some ( token_stream_def_id) = tcx. get_diagnostic_item ( sym:: TokenStream ) else {
2288
+
2289
+ let Some ( token_stream) = tcx
2290
+ . get_diagnostic_item ( sym:: TokenStream )
2291
+ . and_then ( |did| tcx. type_of ( did) . no_bound_vars ( ) )
2292
+ else {
2289
2293
return ;
2290
2294
} ;
2291
- let Some ( token_stream) = tcx. type_of ( token_stream_def_id) . no_bound_vars ( ) else {
2295
+ let Some ( derive_expansion_options) = tcx
2296
+ . get_diagnostic_item ( sym:: DeriveExpansionOptions )
2297
+ . and_then ( |did| tcx. type_of ( did) . no_bound_vars ( ) )
2298
+ else {
2292
2299
return ;
2293
2300
} ;
2294
2301
@@ -2324,8 +2331,22 @@ impl CheckAttrVisitor<'_> {
2324
2331
Unsafety :: Normal ,
2325
2332
Abi :: Rust ,
2326
2333
) ;
2334
+ let expected_options_sig = tcx. mk_fn_sig (
2335
+ [ token_stream, derive_expansion_options] ,
2336
+ token_stream,
2337
+ false ,
2338
+ Unsafety :: Normal ,
2339
+ Abi :: Rust ,
2340
+ ) ;
2341
+
2342
+ let mut result = infcx. probe ( |_| ocx. eq ( & cause, param_env, expected_sig, sig) ) ;
2343
+ if result. is_err ( )
2344
+ && let ProcMacroKind :: Derive = kind
2345
+ {
2346
+ result = infcx. probe ( |_| ocx. eq ( & cause, param_env, expected_options_sig, sig) ) ;
2347
+ }
2327
2348
2328
- if let Err ( terr) = ocx . eq ( & cause , param_env , expected_sig , sig ) {
2349
+ if let Err ( terr) = result {
2329
2350
let mut diag = tcx. sess . create_err ( errors:: ProcMacroBadSig { span, kind } ) ;
2330
2351
2331
2352
let hir_sig = tcx. hir ( ) . fn_sig_by_hir_id ( hir_id) ;
@@ -2360,18 +2381,33 @@ impl CheckAttrVisitor<'_> {
2360
2381
}
2361
2382
}
2362
2383
2363
- infcx. err_ctxt ( ) . note_type_err (
2364
- & mut diag,
2365
- & cause,
2366
- None ,
2367
- Some ( ValuePairs :: PolySigs ( ExpectedFound {
2368
- expected : ty:: Binder :: dummy ( expected_sig) ,
2369
- found : ty:: Binder :: dummy ( sig) ,
2370
- } ) ) ,
2371
- terr,
2372
- false ,
2373
- false ,
2374
- ) ;
2384
+ let mut note_expected_found = |expected_sig| {
2385
+ infcx. err_ctxt ( ) . note_type_err (
2386
+ & mut diag,
2387
+ & cause,
2388
+ None ,
2389
+ Some ( ValuePairs :: PolySigs ( ExpectedFound {
2390
+ expected : ty:: Binder :: dummy ( expected_sig) ,
2391
+ found : ty:: Binder :: dummy ( sig) ,
2392
+ } ) ) ,
2393
+ terr,
2394
+ false ,
2395
+ false ,
2396
+ )
2397
+ } ;
2398
+
2399
+ note_expected_found ( expected_sig) ;
2400
+
2401
+ if let ProcMacroKind :: Derive = kind
2402
+ && tcx
2403
+ . features ( )
2404
+ . declared_lib_features
2405
+ . iter ( )
2406
+ . any ( |& ( feature, _) | feature == sym:: derive_const)
2407
+ {
2408
+ note_expected_found ( expected_options_sig) ;
2409
+ }
2410
+
2375
2411
diag. emit ( ) ;
2376
2412
self . abort . set ( true ) ;
2377
2413
}
0 commit comments