@@ -25,7 +25,7 @@ use crate::utils::paths;
2525use crate :: utils:: {
2626 clip, comparisons, differing_macro_contexts, higher, in_constant, in_macro_or_desugar, int_bits, last_path_segment,
2727 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,
2929} ;
3030
3131declare_clippy_lint ! {
@@ -467,15 +467,17 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetUnitValue {
467467 if higher:: is_from_for_desugar ( local) {
468468 return ;
469469 }
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+ } ) ;
479481 }
480482 }
481483 }
0 commit comments