@@ -30,7 +30,10 @@ use rustc_span::symbol::{kw, sym, Ident, Symbol};
3030use rustc_span:: { BytePos , Span , SyntaxContext } ;
3131use thin_vec:: ThinVec ;
3232
33- use crate :: errors:: { ChangeImportBinding , ChangeImportBindingSuggestion } ;
33+ use crate :: errors:: {
34+ AddedMacroUse , ChangeImportBinding , ChangeImportBindingSuggestion , ConsiderAddingADerive ,
35+ ConsiderAddingADeriveEnum , ExplicitUnsafeTraits ,
36+ } ;
3437use crate :: imports:: { Import , ImportKind } ;
3538use crate :: late:: { PatternSource , Rib } ;
3639use crate :: path_names_to_string;
@@ -1377,12 +1380,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
13771380 ) ;
13781381
13791382 if macro_kind == MacroKind :: Derive && ( ident. name == sym:: Send || ident. name == sym:: Sync ) {
1380- let msg = format ! ( "unsafe traits like `{}` should be implemented explicitly" , ident) ;
1381- err. span_note ( ident. span , msg) ;
1383+ err. subdiagnostic ( ExplicitUnsafeTraits { span : ident. span , ident } ) ;
13821384 return ;
13831385 }
13841386 if self . macro_names . contains ( & ident. normalize_to_macros_2_0 ( ) ) {
1385- err. help ( "have you added the `#[macro_use]` on the module/import?" ) ;
1387+ err. subdiagnostic ( AddedMacroUse ) ;
13861388 return ;
13871389 }
13881390 if ident. name == kw:: Default
@@ -1392,12 +1394,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
13921394 let source_map = self . tcx . sess . source_map ( ) ;
13931395 let head_span = source_map. guess_head_span ( span) ;
13941396 if let Ok ( head) = source_map. span_to_snippet ( head_span) {
1395- err. span_suggestion ( head_span, "consider adding a derive" , format ! ( "#[derive(Default)]\n {head}" ) , Applicability :: MaybeIncorrect ) ;
1397+ err. subdiagnostic ( ConsiderAddingADerive {
1398+ span : head_span,
1399+ suggestion : format ! ( "#[derive(Default)]\n {head}" )
1400+ } ) ;
13961401 } else {
1397- err. span_help (
1398- head_span,
1399- "consider adding `#[derive(Default)]` to this enum" ,
1400- ) ;
1402+ err. subdiagnostic ( ConsiderAddingADeriveEnum { span : head_span } ) ;
14011403 }
14021404 }
14031405 for ns in [ Namespace :: MacroNS , Namespace :: TypeNS , Namespace :: ValueNS ] {
0 commit comments