@@ -20,7 +20,7 @@ use crate::errors;
20
20
use hir:: def:: DefKind ;
21
21
use rustc_data_structures:: captures:: Captures ;
22
22
use 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 } ;
24
24
use rustc_hir as hir;
25
25
use rustc_hir:: def_id:: { DefId , LocalDefId } ;
26
26
use rustc_hir:: intravisit:: { self , Visitor } ;
@@ -333,17 +333,7 @@ fn bad_placeholder<'tcx>(
333
333
let kind = if kind. ends_with ( 's' ) { format ! ( "{}es" , kind) } else { format ! ( "{}s" , kind) } ;
334
334
335
335
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 } )
347
337
}
348
338
349
339
impl < ' tcx > ItemCtxt < ' tcx > {
@@ -419,13 +409,8 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> {
419
409
self . tcx ( ) . mk_projection ( item_def_id, item_substs)
420
410
} else {
421
411
// 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 ( ) ;
429
414
430
415
match self . node ( ) {
431
416
hir:: Node :: Field ( _) | hir:: Node :: Ctor ( _) | hir:: Node :: Variant ( _) => {
@@ -444,31 +429,25 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> {
444
429
( bound. span . shrink_to_lo ( ) , format ! ( "{}, " , lt_name) )
445
430
}
446
431
} ;
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
+ }
464
448
) ,
465
449
) ,
466
- ] ;
467
- err. multipart_suggestion (
468
- "use a fully qualified path with explicit lifetimes" ,
469
- suggestions,
470
- Applicability :: MaybeIncorrect ,
471
- ) ;
450
+ } ) ;
472
451
}
473
452
_ => { }
474
453
}
@@ -482,20 +461,23 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> {
482
461
| hir:: Node :: ForeignItem ( _)
483
462
| hir:: Node :: TraitItem ( _)
484
463
| 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( ) ,
494
469
) ;
495
470
}
496
471
_ => { }
497
472
}
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
+ ) )
499
481
}
500
482
}
501
483
@@ -763,14 +745,12 @@ fn convert_enum_variant_types(tcx: TyCtxt<'_>, def_id: DefId) {
763
745
Some ( discr)
764
746
} else {
765
747
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
+ } ) ;
774
754
None
775
755
}
776
756
. unwrap_or ( wrapped_discr) ,
@@ -915,14 +895,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
915
895
916
896
let paren_sugar = tcx. has_attr ( def_id, sym:: rustc_paren_sugar) ;
917
897
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 } ) ;
926
899
}
927
900
928
901
let is_marker = tcx. has_attr ( def_id, sym:: marker) ;
@@ -942,13 +915,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
942
915
// and that they are all identifiers
943
916
. and_then ( |attr| match attr. meta_item_list ( ) {
944
917
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 } ) ;
952
919
953
920
None
954
921
}
@@ -957,9 +924,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
957
924
. map ( |item| item. ident ( ) . ok_or ( item. span ( ) ) )
958
925
. collect :: < Result < Box < [ _ ] > , _ > > ( )
959
926
. 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 } ) ;
963
928
} )
964
929
. ok ( )
965
930
. zip ( Some ( attr. span ) ) ,
@@ -975,33 +940,25 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
975
940
match item {
976
941
Some ( item) if matches ! ( item. kind, hir:: AssocItemKind :: Fn { .. } ) => {
977
942
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
+ } ) ;
985
947
986
948
return Some ( ( ) ) ;
987
949
}
988
950
989
951
return None ;
990
952
}
991
953
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
+ } ) ;
1000
959
}
1001
960
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 } ) ;
1005
962
}
1006
963
}
1007
964
@@ -1018,9 +975,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
1018
975
for ident in & * list {
1019
976
if let Some ( dup) = set. insert ( ident. name , ident. span ) {
1020
977
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] } ) ;
1024
979
1025
980
no_dups = false ;
1026
981
}
@@ -1485,17 +1440,7 @@ fn compute_sig_of_foreign_fn_decl<'tcx>(
1485
1440
. source_map ( )
1486
1441
. span_to_snippet ( ast_ty. span )
1487
1442
. 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 } ) ;
1499
1444
}
1500
1445
} ;
1501
1446
for ( input, ty) in iter:: zip ( decl. inputs , fty. inputs ( ) . skip_binder ( ) ) {
0 commit comments