@@ -35,7 +35,7 @@ use crate::session_diagnostics::{
3535 LifetimeReturnCategoryErr , RequireStaticErr , VarHereDenote ,
3636} ;
3737use crate :: universal_regions:: DefiningTy ;
38- use crate :: { borrowck_errors, MirBorrowckCtxt } ;
38+ use crate :: { borrowck_errors, fluent_generated as fluent , MirBorrowckCtxt } ;
3939
4040impl < ' tcx > ConstraintDescription for ConstraintCategory < ' tcx > {
4141 fn description ( & self ) -> & ' static str {
@@ -198,7 +198,6 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
198198 // from higher-ranked trait bounds (HRTB). Try to locate span of the trait
199199 // and the span which bounded to the trait for adding 'static lifetime suggestion
200200 #[ allow( rustc:: diagnostic_outside_of_impl) ]
201- #[ allow( rustc:: untranslatable_diagnostic) ] // FIXME: make this translatable
202201 fn suggest_static_lifetime_for_gat_from_hrtb (
203202 & self ,
204203 diag : & mut Diag < ' _ > ,
@@ -251,23 +250,28 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
251250 debug ! ( ?hrtb_bounds) ;
252251
253252 hrtb_bounds. iter ( ) . for_each ( |bound| {
254- let Trait ( PolyTraitRef { trait_ref, span : trait_span, .. } , _) = bound else { return ; } ;
255- diag. span_note (
256- * trait_span,
257- "due to current limitations in the borrow checker, this implies a `'static` lifetime"
258- ) ;
259- let Some ( generics_fn) = hir. get_generics ( self . body . source . def_id ( ) . expect_local ( ) ) else { return ; } ;
260- let Def ( _, trait_res_defid) = trait_ref. path . res else { return ; } ;
253+ let Trait ( PolyTraitRef { trait_ref, span : trait_span, .. } , _) = bound else {
254+ return ;
255+ } ;
256+ diag. span_note ( * trait_span, fluent:: borrowck_limitations_implies_static) ;
257+ let Some ( generics_fn) = hir. get_generics ( self . body . source . def_id ( ) . expect_local ( ) )
258+ else {
259+ return ;
260+ } ;
261+ let Def ( _, trait_res_defid) = trait_ref. path . res else {
262+ return ;
263+ } ;
261264 debug ! ( ?generics_fn) ;
262265 generics_fn. predicates . iter ( ) . for_each ( |predicate| {
263- let BoundPredicate (
264- WhereBoundPredicate {
265- span : bounded_span,
266- bounded_ty,
267- bounds,
268- ..
269- }
270- ) = predicate else { return ; } ;
266+ let BoundPredicate ( WhereBoundPredicate {
267+ span : bounded_span,
268+ bounded_ty,
269+ bounds,
270+ ..
271+ } ) = predicate
272+ else {
273+ return ;
274+ } ;
271275 bounds. iter ( ) . for_each ( |bd| {
272276 if let Trait ( PolyTraitRef { trait_ref : tr_ref, .. } , _) = bd
273277 && let Def ( _, res_defid) = tr_ref. path . res
@@ -277,16 +281,17 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
277281 && generics_fn. params
278282 . iter ( )
279283 . rfind ( |param| param. def_id . to_def_id ( ) == defid)
280- . is_some ( ) {
281- suggestions. push ( ( bounded_span. shrink_to_hi ( ) , " + 'static" . to_string ( ) ) ) ;
282- }
284+ . is_some ( )
285+ {
286+ suggestions. push ( ( bounded_span. shrink_to_hi ( ) , " + 'static" . to_string ( ) ) ) ;
287+ }
283288 } ) ;
284289 } ) ;
285290 } ) ;
286291 if suggestions. len ( ) > 0 {
287292 suggestions. dedup ( ) ;
288293 diag. multipart_suggestion_verbose (
289- "consider restricting the type parameter to the `'static` lifetime" ,
294+ fluent :: borrowck_restrict_to_static ,
290295 suggestions,
291296 Applicability :: MaybeIncorrect ,
292297 ) ;
@@ -976,7 +981,6 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
976981 }
977982
978983 #[ allow( rustc:: diagnostic_outside_of_impl) ]
979- #[ allow( rustc:: untranslatable_diagnostic) ] // FIXME: make this translatable
980984 #[ instrument( skip( self , err) , level = "debug" ) ]
981985 fn suggest_constrain_dyn_trait_in_impl (
982986 & self ,
@@ -994,16 +998,12 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
994998 debug ! ( "trait spans found: {:?}" , traits) ;
995999 for span in & traits {
9961000 let mut multi_span: MultiSpan = vec ! [ * span] . into ( ) ;
997- multi_span
998- . push_span_label ( * span, "this has an implicit `'static` lifetime requirement" ) ;
999- multi_span. push_span_label (
1000- ident. span ,
1001- "calling this method introduces the `impl`'s `'static` requirement" ,
1002- ) ;
1001+ multi_span. push_span_label ( * span, fluent:: borrowck_implicit_static) ;
1002+ multi_span. push_span_label ( ident. span , fluent:: borrowck_implicit_static_introduced) ;
10031003 err. subdiagnostic ( RequireStaticErr :: UsedImpl { multi_span } ) ;
10041004 err. span_suggestion_verbose (
10051005 span. shrink_to_hi ( ) ,
1006- "consider relaxing the implicit `'static` requirement" ,
1006+ fluent :: borrowck_implicit_static_relax ,
10071007 " + '_" ,
10081008 Applicability :: MaybeIncorrect ,
10091009 ) ;
@@ -1045,7 +1045,6 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
10451045 }
10461046
10471047 #[ allow( rustc:: diagnostic_outside_of_impl) ]
1048- #[ allow( rustc:: untranslatable_diagnostic) ] // FIXME: make this translatable
10491048 /// When encountering a lifetime error caused by the return type of a closure, check the
10501049 /// corresponding trait bound and see if dereferencing the closure return value would satisfy
10511050 /// them. If so, we produce a structured suggestion.
@@ -1166,15 +1165,14 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
11661165 if ocx. select_all_or_error ( ) . is_empty ( ) && count > 0 {
11671166 diag. span_suggestion_verbose (
11681167 tcx. hir ( ) . body ( * body) . value . peel_blocks ( ) . span . shrink_to_lo ( ) ,
1169- "dereference the return value" ,
1168+ fluent :: borrowck_dereference_suggestion ,
11701169 "*" . repeat ( count) ,
11711170 Applicability :: MachineApplicable ,
11721171 ) ;
11731172 }
11741173 }
11751174
11761175 #[ allow( rustc:: diagnostic_outside_of_impl) ]
1177- #[ allow( rustc:: untranslatable_diagnostic) ] // FIXME: make this translatable
11781176 fn suggest_move_on_borrowing_closure ( & self , diag : & mut Diag < ' _ > ) {
11791177 let map = self . infcx . tcx . hir ( ) ;
11801178 let body = map. body_owned_by ( self . mir_def_id ( ) ) ;
@@ -1213,7 +1211,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
12131211 if let Some ( closure_span) = closure_span {
12141212 diag. span_suggestion_verbose (
12151213 closure_span,
1216- "consider adding 'move' keyword before the nested closure" ,
1214+ fluent :: borrowck_move_closure_suggestion ,
12171215 "move " ,
12181216 Applicability :: MaybeIncorrect ,
12191217 ) ;
0 commit comments