@@ -207,6 +207,8 @@ use std::iter;
207
207
use std:: ops:: Range ;
208
208
use std:: path:: PathBuf ;
209
209
210
+ use crate :: errors:: { LargeAssignmentsLint , RecursionLimit , RequiresLangItem , TypeLengthLimit } ;
211
+
210
212
#[ derive( PartialEq ) ]
211
213
pub enum MonoItemCollectionMode {
212
214
Eager ,
@@ -604,17 +606,24 @@ fn check_recursion_limit<'tcx>(
604
606
// more than the recursion limit is assumed to be causing an
605
607
// infinite expansion.
606
608
if !recursion_limit. value_within_limit ( adjusted_recursion_depth) {
609
+ let def_span = tcx. def_span ( def_id) ;
610
+ let def_path_str = tcx. def_path_str ( def_id) ;
607
611
let ( shrunk, written_to_path) = shrunk_instance_name ( tcx, & instance, 32 , 32 ) ;
608
- let error = format ! ( "reached the recursion limit while instantiating `{}`" , shrunk) ;
609
- let mut err = tcx. sess . struct_span_fatal ( span, & error) ;
610
- err. span_note (
611
- tcx. def_span ( def_id) ,
612
- & format ! ( "`{}` defined here" , tcx. def_path_str( def_id) ) ,
613
- ) ;
614
- if let Some ( path) = written_to_path {
615
- err. note ( & format ! ( "the full type name has been written to '{}'" , path. display( ) ) ) ;
616
- }
617
- err. emit ( )
612
+ let mut path = PathBuf :: new ( ) ;
613
+ let was_written = if written_to_path. is_some ( ) {
614
+ path = written_to_path. unwrap ( ) ;
615
+ Some ( ( ) )
616
+ } else {
617
+ None
618
+ } ;
619
+ tcx. sess . emit_fatal ( RecursionLimit {
620
+ span,
621
+ shrunk,
622
+ def_span,
623
+ def_path_str,
624
+ was_written,
625
+ path,
626
+ } ) ;
618
627
}
619
628
620
629
recursion_depths. insert ( def_id, recursion_depth + 1 ) ;
@@ -642,16 +651,15 @@ fn check_type_length_limit<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) {
642
651
// Bail out in these cases to avoid that bad user experience.
643
652
if !tcx. type_length_limit ( ) . value_within_limit ( type_length) {
644
653
let ( shrunk, written_to_path) = shrunk_instance_name ( tcx, & instance, 32 , 32 ) ;
645
- let msg = format ! ( "reached the type-length limit while instantiating `{}`" , shrunk) ;
646
- let mut diag = tcx. sess . struct_span_fatal ( tcx. def_span ( instance. def_id ( ) ) , & msg) ;
647
- if let Some ( path) = written_to_path {
648
- diag. note ( & format ! ( "the full type name has been written to '{}'" , path. display( ) ) ) ;
649
- }
650
- diag. help ( & format ! (
651
- "consider adding a `#![type_length_limit=\" {}\" ]` attribute to your crate" ,
652
- type_length
653
- ) ) ;
654
- diag. emit ( )
654
+ let span = tcx. def_span ( instance. def_id ( ) ) ;
655
+ let mut path = PathBuf :: new ( ) ;
656
+ let was_written = if written_to_path. is_some ( ) {
657
+ path = written_to_path. unwrap ( ) ;
658
+ Some ( ( ) )
659
+ } else {
660
+ None
661
+ } ;
662
+ tcx. sess . emit_fatal ( TypeLengthLimit { span, shrunk, was_written, path, type_length } ) ;
655
663
}
656
664
}
657
665
@@ -914,17 +922,16 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
914
922
// but correct span? This would make the lint at least accept crate-level lint attributes.
915
923
return ;
916
924
} ;
917
- self . tcx . struct_span_lint_hir (
925
+ self . tcx . emit_spanned_lint (
918
926
LARGE_ASSIGNMENTS ,
919
927
lint_root,
920
928
source_info. span ,
921
- |lint| {
922
- let mut err = lint. build ( & format ! ( "moving {} bytes" , layout. size. bytes( ) ) ) ;
923
- err. span_label ( source_info. span , "value moved from here" ) ;
924
- err. note ( & format ! ( r#"The current maximum size is {}, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`"# , limit. bytes( ) ) ) ;
925
- err. emit ( ) ;
929
+ LargeAssignmentsLint {
930
+ span : source_info. span ,
931
+ size : layout. size . bytes ( ) ,
932
+ limit : limit. bytes ( ) ,
926
933
} ,
927
- ) ;
934
+ )
928
935
}
929
936
}
930
937
}
@@ -1321,7 +1328,11 @@ impl<'v> RootCollector<'_, 'v> {
1321
1328
1322
1329
let start_def_id = match self . tcx . lang_items ( ) . require ( LangItem :: Start ) {
1323
1330
Ok ( s) => s,
1324
- Err ( err) => self . tcx . sess . fatal ( & err) ,
1331
+ Err ( lang_item_err) => {
1332
+ self . tcx
1333
+ . sess
1334
+ . emit_fatal ( RequiresLangItem { lang_item : lang_item_err. 0 . name ( ) . to_string ( ) } ) ;
1335
+ }
1325
1336
} ;
1326
1337
let main_ret_ty = self . tcx . fn_sig ( main_def_id) . output ( ) ;
1327
1338
0 commit comments