@@ -30,6 +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:: {
34+ AddedMacroUse , ChangeImportBinding , ChangeImportBindingSuggestion , ConsiderAddingADerive ,
35+ ExplicitUnsafeTraits ,
36+ } ;
3337use crate :: imports:: { Import , ImportKind } ;
3438use crate :: late:: { PatternSource , Rib } ;
3539use crate :: path_names_to_string;
@@ -376,16 +380,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
376380 _ => unreachable ! ( ) ,
377381 }
378382
379- let rename_msg = "you can use `as` to change the binding name of the import" ;
380383 if let Some ( suggestion) = suggestion {
381- err. span_suggestion (
382- binding_span,
383- rename_msg,
384- suggestion,
385- Applicability :: MaybeIncorrect ,
386- ) ;
384+ err. subdiagnostic ( ChangeImportBindingSuggestion { span : binding_span, suggestion } ) ;
387385 } else {
388- err. span_label ( binding_span, rename_msg ) ;
386+ err. subdiagnostic ( ChangeImportBinding { span : binding_span } ) ;
389387 }
390388 }
391389
@@ -1382,12 +1380,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
13821380 ) ;
13831381
13841382 if macro_kind == MacroKind :: Derive && ( ident. name == sym:: Send || ident. name == sym:: Sync ) {
1385- let msg = format ! ( "unsafe traits like `{}` should be implemented explicitly" , ident) ;
1386- err. span_note ( ident. span , msg) ;
1383+ err. subdiagnostic ( ExplicitUnsafeTraits { span : ident. span , ident } ) ;
13871384 return ;
13881385 }
13891386 if self . macro_names . contains ( & ident. normalize_to_macros_2_0 ( ) ) {
1390- err. help ( "have you added the `#[macro_use]` on the module/import?" ) ;
1387+ err. subdiagnostic ( AddedMacroUse ) ;
13911388 return ;
13921389 }
13931390 if ident. name == kw:: Default
@@ -1396,14 +1393,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
13961393 let span = self . def_span ( def_id) ;
13971394 let source_map = self . tcx . sess . source_map ( ) ;
13981395 let head_span = source_map. guess_head_span ( span) ;
1399- if let Ok ( head) = source_map. span_to_snippet ( head_span) {
1400- err. span_suggestion ( head_span, "consider adding a derive" , format ! ( "#[derive(Default)]\n {head}" ) , Applicability :: MaybeIncorrect ) ;
1401- } else {
1402- err. span_help (
1403- head_span,
1404- "consider adding `#[derive(Default)]` to this enum" ,
1405- ) ;
1406- }
1396+ err. subdiagnostic ( ConsiderAddingADerive {
1397+ span : head_span. shrink_to_lo ( ) ,
1398+ suggestion : format ! ( "#[derive(Default)]\n " )
1399+ } ) ;
14071400 }
14081401 for ns in [ Namespace :: MacroNS , Namespace :: TypeNS , Namespace :: ValueNS ] {
14091402 if let Ok ( binding) = self . early_resolve_ident_in_lexical_scope (
0 commit comments