@@ -25,7 +25,7 @@ use crate::utils::paths;
25
25
use crate :: utils:: {
26
26
clip, comparisons, differing_macro_contexts, higher, in_constant, in_macro_or_desugar, int_bits, last_path_segment,
27
27
match_def_path, match_path, multispan_sugg, same_tys, sext, snippet, snippet_opt, snippet_with_applicability,
28
- span_help_and_lint, span_lint, span_lint_and_sugg, span_lint_and_then, unsext,
28
+ snippet_with_macro_callsite , span_help_and_lint, span_lint, span_lint_and_sugg, span_lint_and_then, unsext,
29
29
} ;
30
30
31
31
declare_clippy_lint ! {
@@ -467,15 +467,17 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetUnitValue {
467
467
if higher:: is_from_for_desugar ( local) {
468
468
return ;
469
469
}
470
- span_lint (
471
- cx,
472
- LET_UNIT_VALUE ,
473
- stmt. span ,
474
- & format ! (
475
- "this let-binding has unit value. Consider omitting `let {} =`" ,
476
- snippet( cx, local. pat. span, ".." )
477
- ) ,
478
- ) ;
470
+ span_lint_and_then ( cx, LET_UNIT_VALUE , stmt. span , "this let-binding has unit value" , |db| {
471
+ if let Some ( expr) = & local. init {
472
+ let snip = snippet_with_macro_callsite ( cx, expr. span , "()" ) ;
473
+ db. span_suggestion (
474
+ stmt. span ,
475
+ "omit the `let` binding" ,
476
+ format ! ( "{};" , snip) ,
477
+ Applicability :: MachineApplicable , // snippet
478
+ ) ;
479
+ }
480
+ } ) ;
479
481
}
480
482
}
481
483
}
0 commit comments