@@ -2293,10 +2293,17 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
2293
2293
}
2294
2294
2295
2295
let tcx = self . tcx ;
2296
- let Some ( token_stream_def_id) = tcx. get_diagnostic_item ( sym:: TokenStream ) else {
2296
+
2297
+ let Some ( token_stream) = tcx
2298
+ . get_diagnostic_item ( sym:: TokenStream )
2299
+ . and_then ( |did| tcx. type_of ( did) . no_bound_vars ( ) )
2300
+ else {
2297
2301
return ;
2298
2302
} ;
2299
- let Some ( token_stream) = tcx. type_of ( token_stream_def_id) . no_bound_vars ( ) else {
2303
+ let Some ( derive_expansion_options) = tcx
2304
+ . get_diagnostic_item ( sym:: DeriveExpansionOptions )
2305
+ . and_then ( |did| tcx. type_of ( did) . no_bound_vars ( ) )
2306
+ else {
2300
2307
return ;
2301
2308
} ;
2302
2309
@@ -2332,8 +2339,24 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
2332
2339
Unsafety :: Normal ,
2333
2340
Abi :: Rust ,
2334
2341
) ;
2342
+ let expected_options_sig = tcx. mk_fn_sig (
2343
+ [ token_stream, derive_expansion_options] ,
2344
+ token_stream,
2345
+ false ,
2346
+ Unsafety :: Normal ,
2347
+ Abi :: Rust ,
2348
+ ) ;
2335
2349
2336
- if let Err ( terr) = ocx. eq ( & cause, param_env, expected_sig, sig) {
2350
+ let mut result = infcx. probe ( |_| ocx. eq ( & cause, param_env, expected_sig, sig) ) ;
2351
+ if result. is_err ( )
2352
+ && let ProcMacroKind :: Derive = kind
2353
+ {
2354
+ if infcx. probe ( |_| ocx. eq ( & cause, param_env, expected_options_sig, sig) ) . is_ok ( ) {
2355
+ result = Ok ( ( ) ) ;
2356
+ }
2357
+ }
2358
+
2359
+ if let Err ( terr) = result {
2337
2360
let mut diag = tcx. dcx ( ) . create_err ( errors:: ProcMacroBadSig { span, kind } ) ;
2338
2361
2339
2362
let hir_sig = tcx. hir ( ) . fn_sig_by_hir_id ( hir_id) ;
@@ -2368,18 +2391,33 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
2368
2391
}
2369
2392
}
2370
2393
2371
- infcx. err_ctxt ( ) . note_type_err (
2372
- & mut diag,
2373
- & cause,
2374
- None ,
2375
- Some ( ValuePairs :: PolySigs ( ExpectedFound {
2376
- expected : ty:: Binder :: dummy ( expected_sig) ,
2377
- found : ty:: Binder :: dummy ( sig) ,
2378
- } ) ) ,
2379
- terr,
2380
- false ,
2381
- false ,
2382
- ) ;
2394
+ let mut note_expected_found = |expected_sig| {
2395
+ infcx. err_ctxt ( ) . note_type_err (
2396
+ & mut diag,
2397
+ & cause,
2398
+ None ,
2399
+ Some ( ValuePairs :: PolySigs ( ExpectedFound {
2400
+ expected : ty:: Binder :: dummy ( expected_sig) ,
2401
+ found : ty:: Binder :: dummy ( sig) ,
2402
+ } ) ) ,
2403
+ terr,
2404
+ false ,
2405
+ false ,
2406
+ )
2407
+ } ;
2408
+
2409
+ note_expected_found ( expected_sig) ;
2410
+
2411
+ if let ProcMacroKind :: Derive = kind
2412
+ && tcx
2413
+ . features ( )
2414
+ . declared_lib_features
2415
+ . iter ( )
2416
+ . any ( |& ( feature, _) | feature == sym:: derive_const)
2417
+ {
2418
+ note_expected_found ( expected_options_sig) ;
2419
+ }
2420
+
2383
2421
diag. emit ( ) ;
2384
2422
self . abort . set ( true ) ;
2385
2423
}
0 commit comments