@@ -20,7 +20,7 @@ use crate::errors;
2020use hir:: def:: DefKind ;
2121use rustc_data_structures:: captures:: Captures ;
2222use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
23- use rustc_errors:: { struct_span_err , Applicability , DiagnosticBuilder , ErrorGuaranteed , StashKey } ;
23+ use rustc_errors:: { Applicability , DiagnosticBuilder , ErrorGuaranteed , StashKey } ;
2424use rustc_hir as hir;
2525use rustc_hir:: def_id:: { DefId , LocalDefId } ;
2626use rustc_hir:: intravisit:: { self , Visitor } ;
@@ -333,17 +333,7 @@ fn bad_placeholder<'tcx>(
333333 let kind = if kind. ends_with ( 's' ) { format ! ( "{}es" , kind) } else { format ! ( "{}s" , kind) } ;
334334
335335 spans. sort ( ) ;
336- let mut err = struct_span_err ! (
337- tcx. sess,
338- spans. clone( ) ,
339- E0121 ,
340- "the placeholder `_` is not allowed within types on item signatures for {}" ,
341- kind
342- ) ;
343- for span in spans {
344- err. span_label ( span, "not allowed in type signatures" ) ;
345- }
346- err
336+ tcx. sess . create_err ( errors:: PlaceholderNotAllowedItemSignatures { spans, kind } )
347337}
348338
349339impl < ' tcx > ItemCtxt < ' tcx > {
@@ -419,13 +409,8 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> {
419409 self . tcx ( ) . mk_projection ( item_def_id, item_substs)
420410 } else {
421411 // There are no late-bound regions; we can just ignore the binder.
422- let mut err = struct_span_err ! (
423- self . tcx( ) . sess,
424- span,
425- E0212 ,
426- "cannot use the associated type of a trait \
427- with uninferred generic parameters"
428- ) ;
412+ let ( mut mpart_sugg, mut inferred_sugg) = ( None , None ) ;
413+ let mut bound = String :: new ( ) ;
429414
430415 match self . node ( ) {
431416 hir:: Node :: Field ( _) | hir:: Node :: Ctor ( _) | hir:: Node :: Variant ( _) => {
@@ -444,31 +429,25 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> {
444429 ( bound. span . shrink_to_lo ( ) , format ! ( "{}, " , lt_name) )
445430 }
446431 } ;
447- let suggestions = vec ! [
448- ( lt_sp, sugg) ,
449- (
450- span. with_hi( item_segment. ident. span. lo( ) ) ,
451- format!(
452- "{}::" ,
453- // Replace the existing lifetimes with a new named lifetime.
454- self . tcx. replace_late_bound_regions_uncached(
455- poly_trait_ref,
456- |_| {
457- self . tcx. mk_re_early_bound( ty:: EarlyBoundRegion {
458- def_id: item_def_id,
459- index: 0 ,
460- name: Symbol :: intern( & lt_name) ,
461- } )
462- }
463- ) ,
432+ mpart_sugg = Some ( errors:: AssociatedTypeTraitUninferredGenericParamsMultipartSuggestion {
433+ fspan : lt_sp,
434+ first : sugg,
435+ sspan : span. with_hi ( item_segment. ident . span . lo ( ) ) ,
436+ second : format ! (
437+ "{}::" ,
438+ // Replace the existing lifetimes with a new named lifetime.
439+ self . tcx. replace_late_bound_regions_uncached(
440+ poly_trait_ref,
441+ |_| {
442+ self . tcx. mk_re_early_bound( ty:: EarlyBoundRegion {
443+ def_id: item_def_id,
444+ index: 0 ,
445+ name: Symbol :: intern( & lt_name) ,
446+ } )
447+ }
464448 ) ,
465449 ) ,
466- ] ;
467- err. multipart_suggestion (
468- "use a fully qualified path with explicit lifetimes" ,
469- suggestions,
470- Applicability :: MaybeIncorrect ,
471- ) ;
450+ } ) ;
472451 }
473452 _ => { }
474453 }
@@ -482,20 +461,23 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> {
482461 | hir:: Node :: ForeignItem ( _)
483462 | hir:: Node :: TraitItem ( _)
484463 | hir:: Node :: ImplItem ( _) => {
485- err. span_suggestion_verbose (
486- span. with_hi ( item_segment. ident . span . lo ( ) ) ,
487- "use a fully qualified path with inferred lifetimes" ,
488- format ! (
489- "{}::" ,
490- // Erase named lt, we want `<A as B<'_>::C`, not `<A as B<'a>::C`.
491- self . tcx. anonymize_bound_vars( poly_trait_ref) . skip_binder( ) ,
492- ) ,
493- Applicability :: MaybeIncorrect ,
464+ inferred_sugg = Some ( span. with_hi ( item_segment. ident . span . lo ( ) ) ) ;
465+ bound = format ! (
466+ "{}::" ,
467+ // Erase named lt, we want `<A as B<'_>::C`, not `<A as B<'a>::C`.
468+ self . tcx. anonymize_bound_vars( poly_trait_ref) . skip_binder( ) ,
494469 ) ;
495470 }
496471 _ => { }
497472 }
498- self . tcx ( ) . ty_error ( err. emit ( ) )
473+ self . tcx ( ) . ty_error ( self . tcx ( ) . sess . emit_err (
474+ errors:: AssociatedTypeTraitUninferredGenericParams {
475+ span,
476+ inferred_sugg,
477+ bound,
478+ mpart_sugg,
479+ } ,
480+ ) )
499481 }
500482 }
501483
@@ -763,14 +745,12 @@ fn convert_enum_variant_types(tcx: TyCtxt<'_>, def_id: DefId) {
763745 Some ( discr)
764746 } else {
765747 let span = tcx. def_span ( variant. def_id ) ;
766- struct_span_err ! ( tcx. sess, span, E0370 , "enum discriminant overflowed" )
767- . span_label ( span, format ! ( "overflowed on value after {}" , prev_discr. unwrap( ) ) )
768- . note ( & format ! (
769- "explicitly set `{} = {}` if that is desired outcome" ,
770- tcx. item_name( variant. def_id) ,
771- wrapped_discr
772- ) )
773- . emit ( ) ;
748+ tcx. sess . emit_err ( errors:: EnumDiscriminantOverflowed {
749+ span,
750+ discr : prev_discr. unwrap ( ) . to_string ( ) ,
751+ item_name : tcx. item_name ( variant. def_id ) ,
752+ wrapped_discr : wrapped_discr. to_string ( ) ,
753+ } ) ;
774754 None
775755 }
776756 . unwrap_or ( wrapped_discr) ,
@@ -915,14 +895,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
915895
916896 let paren_sugar = tcx. has_attr ( def_id, sym:: rustc_paren_sugar) ;
917897 if paren_sugar && !tcx. features ( ) . unboxed_closures {
918- tcx. sess
919- . struct_span_err (
920- item. span ,
921- "the `#[rustc_paren_sugar]` attribute is a temporary means of controlling \
922- which traits can use parenthetical notation",
923- )
924- . help ( "add `#![feature(unboxed_closures)]` to the crate attributes to use it" )
925- . emit ( ) ;
898+ tcx. sess . emit_err ( errors:: ParenSugarAttribute { span : item. span } ) ;
926899 }
927900
928901 let is_marker = tcx. has_attr ( def_id, sym:: marker) ;
@@ -942,13 +915,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
942915 // and that they are all identifiers
943916 . and_then ( |attr| match attr. meta_item_list ( ) {
944917 Some ( items) if items. len ( ) < 2 => {
945- tcx. sess
946- . struct_span_err (
947- attr. span ,
948- "the `#[rustc_must_implement_one_of]` attribute must be \
949- used with at least 2 args",
950- )
951- . emit ( ) ;
918+ tcx. sess . emit_err ( errors:: MustImplementOneOfAttribute { span : attr. span } ) ;
952919
953920 None
954921 }
@@ -957,9 +924,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
957924 . map ( |item| item. ident ( ) . ok_or ( item. span ( ) ) )
958925 . collect :: < Result < Box < [ _ ] > , _ > > ( )
959926 . map_err ( |span| {
960- tcx. sess
961- . struct_span_err ( span, "must be a name of an associated function" )
962- . emit ( ) ;
927+ tcx. sess . emit_err ( errors:: MustBeNameOfAssociatedFunction { span } ) ;
963928 } )
964929 . ok ( )
965930 . zip ( Some ( attr. span ) ) ,
@@ -975,33 +940,25 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
975940 match item {
976941 Some ( item) if matches ! ( item. kind, hir:: AssocItemKind :: Fn { .. } ) => {
977942 if !tcx. impl_defaultness ( item. id . owner_id ) . has_value ( ) {
978- tcx. sess
979- . struct_span_err (
980- item. span ,
981- "function doesn't have a default implementation" ,
982- )
983- . span_note ( attr_span, "required by this annotation" )
984- . emit ( ) ;
943+ tcx. sess . emit_err ( errors:: FunctionNotHaveDefaultImplementation {
944+ span : item. span ,
945+ note_span : attr_span,
946+ } ) ;
985947
986948 return Some ( ( ) ) ;
987949 }
988950
989951 return None ;
990952 }
991953 Some ( item) => {
992- tcx. sess
993- . struct_span_err ( item. span , "not a function" )
994- . span_note ( attr_span, "required by this annotation" )
995- . note (
996- "all `#[rustc_must_implement_one_of]` arguments must be associated \
997- function names",
998- )
999- . emit ( ) ;
954+ tcx. sess . emit_err ( errors:: MustImplementNotFunction {
955+ span : item. span ,
956+ span_note : errors:: MustImplementNotFunctionSpanNote { span : attr_span } ,
957+ note : errors:: MustImplementNotFunctionNote { } ,
958+ } ) ;
1000959 }
1001960 None => {
1002- tcx. sess
1003- . struct_span_err ( ident. span , "function not found in this trait" )
1004- . emit ( ) ;
961+ tcx. sess . emit_err ( errors:: FunctionNotFoundInTrait { span : ident. span } ) ;
1005962 }
1006963 }
1007964
@@ -1018,9 +975,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
1018975 for ident in & * list {
1019976 if let Some ( dup) = set. insert ( ident. name , ident. span ) {
1020977 tcx. sess
1021- . struct_span_err ( vec ! [ dup, ident. span] , "functions names are duplicated" )
1022- . note ( "all `#[rustc_must_implement_one_of]` arguments must be unique" )
1023- . emit ( ) ;
978+ . emit_err ( errors:: FunctionNamesDuplicated { spans : vec ! [ dup, ident. span] } ) ;
1024979
1025980 no_dups = false ;
1026981 }
@@ -1485,17 +1440,7 @@ fn compute_sig_of_foreign_fn_decl<'tcx>(
14851440 . source_map ( )
14861441 . span_to_snippet ( ast_ty. span )
14871442 . map_or_else ( |_| String :: new ( ) , |s| format ! ( " `{}`" , s) ) ;
1488- tcx. sess
1489- . struct_span_err (
1490- ast_ty. span ,
1491- & format ! (
1492- "use of SIMD type{} in FFI is highly experimental and \
1493- may result in invalid code",
1494- snip
1495- ) ,
1496- )
1497- . help ( "add `#![feature(simd_ffi)]` to the crate attributes to enable" )
1498- . emit ( ) ;
1443+ tcx. sess . emit_err ( errors:: SIMDFFIHighlyExperimental { span : ast_ty. span , snip } ) ;
14991444 }
15001445 } ;
15011446 for ( input, ty) in iter:: zip ( decl. inputs , fty. inputs ( ) . skip_binder ( ) ) {
0 commit comments