@@ -3,7 +3,7 @@ use crate::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext}
3
3
use rustc_ast as ast;
4
4
use rustc_ast:: util:: { classify, parser} ;
5
5
use rustc_ast:: { ExprKind , StmtKind } ;
6
- use rustc_errors:: { pluralize, Applicability , MultiSpan } ;
6
+ use rustc_errors:: { fluent , pluralize, Applicability , MultiSpan } ;
7
7
use rustc_hir as hir;
8
8
use rustc_hir:: def:: { DefKind , Res } ;
9
9
use rustc_hir:: def_id:: DefId ;
@@ -155,22 +155,23 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
155
155
156
156
if let Some ( must_use_op) = must_use_op {
157
157
cx. struct_span_lint ( UNUSED_MUST_USE , expr. span , |lint| {
158
- let mut lint = lint. build ( & format ! ( "unused {} that must be used" , must_use_op) ) ;
159
- lint. span_label ( expr. span , & format ! ( "the {} produces a value" , must_use_op) ) ;
160
- lint. span_suggestion_verbose (
161
- expr. span . shrink_to_lo ( ) ,
162
- "use `let _ = ...` to ignore the resulting value" ,
163
- "let _ = " ,
164
- Applicability :: MachineApplicable ,
165
- ) ;
166
- lint. emit ( ) ;
158
+ lint. build ( fluent:: lint:: unused_op)
159
+ . set_arg ( "op" , must_use_op)
160
+ . span_label ( expr. span , fluent:: lint:: label)
161
+ . span_suggestion_verbose (
162
+ expr. span . shrink_to_lo ( ) ,
163
+ fluent:: lint:: suggestion,
164
+ "let _ = " ,
165
+ Applicability :: MachineApplicable ,
166
+ )
167
+ . emit ( ) ;
167
168
} ) ;
168
169
op_warned = true ;
169
170
}
170
171
171
172
if !( type_permits_lack_of_use || fn_warned || op_warned) {
172
173
cx. struct_span_lint ( UNUSED_RESULTS , s. span , |lint| {
173
- lint. build ( & format ! ( "unused result of type `{}` ", ty) ) . emit ( ) ;
174
+ lint. build ( fluent :: lint :: unused_result ) . set_arg ( "ty ", ty) . emit ( ) ;
174
175
} ) ;
175
176
}
176
177
@@ -267,23 +268,27 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
267
268
} ,
268
269
ty:: Closure ( ..) => {
269
270
cx. struct_span_lint ( UNUSED_MUST_USE , span, |lint| {
270
- let mut err = lint. build ( & format ! (
271
- "unused {}closure{}{} that must be used" ,
272
- descr_pre, plural_suffix, descr_post,
273
- ) ) ;
274
- err. note ( "closures are lazy and do nothing unless called" ) ;
275
- err. emit ( ) ;
271
+ // FIXME(davidtwco): this isn't properly translatable becauses of the
272
+ // pre/post strings
273
+ lint. build ( fluent:: lint:: unused_closure)
274
+ . set_arg ( "count" , plural_len)
275
+ . set_arg ( "pre" , descr_pre)
276
+ . set_arg ( "post" , descr_post)
277
+ . note ( fluent:: lint:: note)
278
+ . emit ( ) ;
276
279
} ) ;
277
280
true
278
281
}
279
282
ty:: Generator ( ..) => {
280
283
cx. struct_span_lint ( UNUSED_MUST_USE , span, |lint| {
281
- let mut err = lint. build ( & format ! (
282
- "unused {}generator{}{} that must be used" ,
283
- descr_pre, plural_suffix, descr_post,
284
- ) ) ;
285
- err. note ( "generators are lazy and do nothing unless resumed" ) ;
286
- err. emit ( ) ;
284
+ // FIXME(davidtwco): this isn't properly translatable becauses of the
285
+ // pre/post strings
286
+ lint. build ( fluent:: lint:: unused_generator)
287
+ . set_arg ( "count" , plural_len)
288
+ . set_arg ( "pre" , descr_pre)
289
+ . set_arg ( "post" , descr_post)
290
+ . note ( fluent:: lint:: note)
291
+ . emit ( ) ;
287
292
} ) ;
288
293
true
289
294
}
@@ -305,13 +310,12 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
305
310
) -> bool {
306
311
if let Some ( attr) = cx. tcx . get_attr ( def_id, sym:: must_use) {
307
312
cx. struct_span_lint ( UNUSED_MUST_USE , span, |lint| {
308
- let msg = format ! (
309
- "unused {}`{}`{} that must be used" ,
310
- descr_pre_path,
311
- cx. tcx. def_path_str( def_id) ,
312
- descr_post_path
313
- ) ;
314
- let mut err = lint. build ( & msg) ;
313
+ // FIXME(davidtwco): this isn't properly translatable becauses of the pre/post
314
+ // strings
315
+ let mut err = lint. build ( fluent:: lint:: unused_def) ;
316
+ err. set_arg ( "pre" , descr_pre_path) ;
317
+ err. set_arg ( "post" , descr_post_path) ;
318
+ err. set_arg ( "def" , cx. tcx . def_path_str ( def_id) ) ;
315
319
// check for #[must_use = "..."]
316
320
if let Some ( note) = attr. value_str ( ) {
317
321
err. note ( note. as_str ( ) ) ;
0 commit comments