@@ -30,6 +30,10 @@ use rustc_span::symbol::{kw, sym, Ident, Symbol};
30
30
use rustc_span:: { BytePos , Span , SyntaxContext } ;
31
31
use thin_vec:: ThinVec ;
32
32
33
+ use crate :: errors:: {
34
+ AddedMacroUse , ChangeImportBinding , ChangeImportBindingSuggestion , ConsiderAddingADerive ,
35
+ ExplicitUnsafeTraits ,
36
+ } ;
33
37
use crate :: imports:: { Import , ImportKind } ;
34
38
use crate :: late:: { PatternSource , Rib } ;
35
39
use crate :: path_names_to_string;
@@ -376,16 +380,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
376
380
_ => unreachable ! ( ) ,
377
381
}
378
382
379
- let rename_msg = "you can use `as` to change the binding name of the import" ;
380
383
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 } ) ;
387
385
} else {
388
- err. span_label ( binding_span, rename_msg ) ;
386
+ err. subdiagnostic ( ChangeImportBinding { span : binding_span } ) ;
389
387
}
390
388
}
391
389
@@ -1382,12 +1380,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1382
1380
) ;
1383
1381
1384
1382
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 } ) ;
1387
1384
return ;
1388
1385
}
1389
1386
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 ) ;
1391
1388
return ;
1392
1389
}
1393
1390
if ident. name == kw:: Default
@@ -1396,14 +1393,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1396
1393
let span = self . def_span ( def_id) ;
1397
1394
let source_map = self . tcx . sess . source_map ( ) ;
1398
1395
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
+ } ) ;
1407
1400
}
1408
1401
for ns in [ Namespace :: MacroNS , Namespace :: TypeNS , Namespace :: ValueNS ] {
1409
1402
if let Ok ( binding) = self . early_resolve_ident_in_lexical_scope (
0 commit comments