@@ -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,24 @@ 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
+ ) ;
2327
2341
2328
- if let Err ( terr) = ocx. eq ( & cause, param_env, expected_sig, sig) {
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
+ if infcx. probe ( |_| ocx. eq ( & cause, param_env, expected_options_sig, sig) ) . is_ok ( ) {
2347
+ result = Ok ( ( ) ) ;
2348
+ }
2349
+ }
2350
+
2351
+ if let Err ( terr) = result {
2329
2352
let mut diag = tcx. sess . create_err ( errors:: ProcMacroBadSig { span, kind } ) ;
2330
2353
2331
2354
let hir_sig = tcx. hir ( ) . fn_sig_by_hir_id ( hir_id) ;
@@ -2360,18 +2383,33 @@ impl CheckAttrVisitor<'_> {
2360
2383
}
2361
2384
}
2362
2385
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
- ) ;
2386
+ let mut note_expected_found = |expected_sig| {
2387
+ infcx. err_ctxt ( ) . note_type_err (
2388
+ & mut diag,
2389
+ & cause,
2390
+ None ,
2391
+ Some ( ValuePairs :: PolySigs ( ExpectedFound {
2392
+ expected : ty:: Binder :: dummy ( expected_sig) ,
2393
+ found : ty:: Binder :: dummy ( sig) ,
2394
+ } ) ) ,
2395
+ terr,
2396
+ false ,
2397
+ false ,
2398
+ )
2399
+ } ;
2400
+
2401
+ note_expected_found ( expected_sig) ;
2402
+
2403
+ if let ProcMacroKind :: Derive = kind
2404
+ && tcx
2405
+ . features ( )
2406
+ . declared_lib_features
2407
+ . iter ( )
2408
+ . any ( |& ( feature, _) | feature == sym:: derive_const)
2409
+ {
2410
+ note_expected_found ( expected_options_sig) ;
2411
+ }
2412
+
2375
2413
diag. emit ( ) ;
2376
2414
self . abort . set ( true ) ;
2377
2415
}
0 commit comments