@@ -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,22 @@ 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+ ) ;
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+ }
23272348
2328- if let Err ( terr) = ocx . eq ( & cause , param_env , expected_sig , sig ) {
2349+ if let Err ( terr) = result {
23292350 let mut diag = tcx. sess . create_err ( errors:: ProcMacroBadSig { span, kind } ) ;
23302351
23312352 let hir_sig = tcx. hir ( ) . fn_sig_by_hir_id ( hir_id) ;
@@ -2360,18 +2381,33 @@ impl CheckAttrVisitor<'_> {
23602381 }
23612382 }
23622383
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+
23752411 diag. emit ( ) ;
23762412 self . abort . set ( true ) ;
23772413 }
0 commit comments