1+ #![ deny( rustc:: untranslatable_diagnostic) ]
2+ #![ deny( rustc:: diagnostic_outside_of_impl) ]
3+
14use rustc_errors:: {
25 Applicability , Diagnostic , DiagnosticBuilder , EmissionGuarantee , ErrorGuaranteed ,
36} ;
@@ -19,6 +22,7 @@ use rustc_span::symbol::{kw, Symbol};
1922use rustc_span:: { sym, BytePos , Span } ;
2023
2124use crate :: diagnostics:: BorrowedContentSource ;
25+ use crate :: session_diagnostics:: { FnMutBumpFn , ShowMutatingUpvar } ;
2226use crate :: MirBorrowckCtxt ;
2327use rustc_const_eval:: util:: collect_writes:: FindAssignments ;
2428
@@ -864,14 +868,9 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
864868 } else {
865869 bug ! ( "not an upvar" )
866870 } ;
867- err. span_label (
868- * span,
869- format ! (
870- "calling `{}` requires mutable binding due to {}" ,
871- self . describe_place( the_place_err) . unwrap( ) ,
872- reason
873- ) ,
874- ) ;
871+ let place = self . describe_place ( the_place_err) . unwrap ( ) ;
872+ let sub_label = ShowMutatingUpvar :: RequireMutableBinding { place, reason, span : * span } ;
873+ err. subdiagnostic ( sub_label) ;
875874 }
876875 }
877876
@@ -969,7 +968,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
969968
970969 /// Targeted error when encountering an `FnMut` closure where an `Fn` closure was expected.
971970 fn expected_fn_found_fn_mut_call ( & self , err : & mut Diagnostic , sp : Span , act : & str ) {
972- err. span_label ( sp , format ! ( "cannot { act}" ) ) ;
971+ err. subdiagnostic ( FnMutBumpFn :: Cannot { act, sp } ) ;
973972
974973 let hir = self . infcx . tcx . hir ( ) ;
975974 let closure_id = self . mir_hir_id ( ) ;
@@ -1022,9 +1021,9 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
10221021 _ => None ,
10231022 } ;
10241023 if let Some ( span) = arg {
1025- err. span_label ( span , "change this to accept `FnMut` instead of `Fn`" ) ;
1026- err. span_label ( func. span , "expects `Fn` instead of `FnMut`" ) ;
1027- err. span_label ( self . body . span , "in this closure" ) ;
1024+ err. subdiagnostic ( FnMutBumpFn :: AcceptFnMut { span } ) ;
1025+ err. subdiagnostic ( FnMutBumpFn :: AcceptFn { span : func. span } ) ;
1026+ err. subdiagnostic ( FnMutBumpFn :: Here { span : self . body . span } ) ;
10281027 look_at_return = false ;
10291028 }
10301029 }
@@ -1045,12 +1044,9 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
10451044 kind : hir:: ImplItemKind :: Fn ( sig, _) ,
10461045 ..
10471046 } ) => {
1048- err. span_label ( ident. span , "" ) ;
1049- err. span_label (
1050- sig. decl . output . span ( ) ,
1051- "change this to return `FnMut` instead of `Fn`" ,
1052- ) ;
1053- err. span_label ( self . body . span , "in this closure" ) ;
1047+ err. subdiagnostic ( FnMutBumpFn :: EmptyLabel { span : ident. span } ) ;
1048+ err. subdiagnostic ( FnMutBumpFn :: ReturnFnMut { span : sig. decl . output . span ( ) } ) ;
1049+ err. subdiagnostic ( FnMutBumpFn :: Here { span : self . body . span } ) ;
10541050 }
10551051 _ => { }
10561052 }
0 commit comments