@@ -207,6 +207,8 @@ use std::iter;
207207use std:: ops:: Range ;
208208use std:: path:: PathBuf ;
209209
210+ use crate :: errors:: { LargeAssignmentsLint , RecursionLimit , RequiresLangItem , TypeLengthLimit } ;
211+
210212#[ derive( PartialEq ) ]
211213pub enum MonoItemCollectionMode {
212214 Eager ,
@@ -604,17 +606,24 @@ fn check_recursion_limit<'tcx>(
604606 // more than the recursion limit is assumed to be causing an
605607 // infinite expansion.
606608 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) ;
607611 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+ } ) ;
618627 }
619628
620629 recursion_depths. insert ( def_id, recursion_depth + 1 ) ;
@@ -642,16 +651,15 @@ fn check_type_length_limit<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) {
642651 // Bail out in these cases to avoid that bad user experience.
643652 if !tcx. type_length_limit ( ) . value_within_limit ( type_length) {
644653 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 } ) ;
655663 }
656664}
657665
@@ -914,17 +922,16 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
914922 // but correct span? This would make the lint at least accept crate-level lint attributes.
915923 return ;
916924 } ;
917- self . tcx . struct_span_lint_hir (
925+ self . tcx . emit_spanned_lint (
918926 LARGE_ASSIGNMENTS ,
919927 lint_root,
920928 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 ( ) ,
926933 } ,
927- ) ;
934+ )
928935 }
929936 }
930937 }
@@ -1321,7 +1328,11 @@ impl<'v> RootCollector<'_, 'v> {
13211328
13221329 let start_def_id = match self . tcx . lang_items ( ) . require ( LangItem :: Start ) {
13231330 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+ }
13251336 } ;
13261337 let main_ret_ty = self . tcx . fn_sig ( main_def_id) . output ( ) ;
13271338
0 commit comments