@@ -2293,10 +2293,17 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
22932293 }
22942294
22952295 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 {
22972301 return ;
22982302 } ;
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 {
23002307 return ;
23012308 } ;
23022309
@@ -2332,8 +2339,24 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
23322339 Unsafety :: Normal ,
23332340 Abi :: Rust ,
23342341 ) ;
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+ ) ;
23352349
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 {
23372360 let mut diag = tcx. dcx ( ) . create_err ( errors:: ProcMacroBadSig { span, kind } ) ;
23382361
23392362 let hir_sig = tcx. hir ( ) . fn_sig_by_hir_id ( hir_id) ;
@@ -2368,18 +2391,33 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
23682391 }
23692392 }
23702393
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+
23832421 diag. emit ( ) ;
23842422 self . abort . set ( true ) ;
23852423 }
0 commit comments