1+ mod let_unit_value;
12mod utils;
23
34use rustc_errors:: Applicability ;
45use rustc_hir as hir;
56use rustc_hir:: { BinOpKind , Block , Expr , ExprKind , MatchSource , Node , Stmt , StmtKind } ;
6- use rustc_lint:: { LateContext , LateLintPass , LintContext } ;
7- use rustc_middle:: lint:: in_external_macro;
7+ use rustc_lint:: { LateContext , LateLintPass } ;
88use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
99use rustc_span:: hygiene:: { ExpnKind , MacroKind } ;
1010
1111use if_chain:: if_chain;
1212
1313use crate :: utils:: diagnostics:: { span_lint, span_lint_and_then} ;
14- use crate :: utils:: higher;
15- use crate :: utils:: source:: { indent_of, reindent_multiline, snippet_opt, snippet_with_macro_callsite} ;
14+ use crate :: utils:: source:: { indent_of, reindent_multiline, snippet_opt} ;
1615
1716use utils:: { is_unit, is_unit_literal} ;
1817
@@ -35,37 +34,11 @@ declare_clippy_lint! {
3534 "creating a `let` binding to a value of unit type, which usually can't be used afterwards"
3635}
3736
38- declare_lint_pass ! ( LetUnitValue => [ LET_UNIT_VALUE ] ) ;
37+ declare_lint_pass ! ( UnitTypes => [ LET_UNIT_VALUE ] ) ;
3938
40- impl < ' tcx > LateLintPass < ' tcx > for LetUnitValue {
39+ impl < ' tcx > LateLintPass < ' tcx > for UnitTypes {
4140 fn check_stmt ( & mut self , cx : & LateContext < ' tcx > , stmt : & ' tcx Stmt < ' _ > ) {
42- if let StmtKind :: Local ( ref local) = stmt. kind {
43- if is_unit ( cx. typeck_results ( ) . pat_ty ( & local. pat ) ) {
44- if in_external_macro ( cx. sess ( ) , stmt. span ) || local. pat . span . from_expansion ( ) {
45- return ;
46- }
47- if higher:: is_from_for_desugar ( local) {
48- return ;
49- }
50- span_lint_and_then (
51- cx,
52- LET_UNIT_VALUE ,
53- stmt. span ,
54- "this let-binding has unit value" ,
55- |diag| {
56- if let Some ( expr) = & local. init {
57- let snip = snippet_with_macro_callsite ( cx, expr. span , "()" ) ;
58- diag. span_suggestion (
59- stmt. span ,
60- "omit the `let` binding" ,
61- format ! ( "{};" , snip) ,
62- Applicability :: MachineApplicable , // snippet
63- ) ;
64- }
65- } ,
66- ) ;
67- }
68- }
41+ let_unit_value:: check ( cx, stmt) ;
6942 }
7043}
7144
0 commit comments