@@ -2285,10 +2285,17 @@ impl CheckAttrVisitor<'_> {
22852285 }
22862286
22872287 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 {
22892293 return ;
22902294 } ;
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 {
22922299 return ;
22932300 } ;
22942301
@@ -2324,8 +2331,24 @@ impl CheckAttrVisitor<'_> {
23242331 Unsafety :: Normal ,
23252332 Abi :: Rust ,
23262333 ) ;
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+ ) ;
23272341
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 {
23292352 let mut diag = tcx. sess . create_err ( errors:: ProcMacroBadSig { span, kind } ) ;
23302353
23312354 let hir_sig = tcx. hir ( ) . fn_sig_by_hir_id ( hir_id) ;
@@ -2360,18 +2383,33 @@ impl CheckAttrVisitor<'_> {
23602383 }
23612384 }
23622385
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+
23752413 diag. emit ( ) ;
23762414 self . abort . set ( true ) ;
23772415 }
0 commit comments