1
+ mod let_unit_value;
1
2
mod utils;
2
3
3
4
use rustc_errors:: Applicability ;
4
5
use rustc_hir as hir;
5
6
use 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 } ;
8
8
use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
9
9
use rustc_span:: hygiene:: { ExpnKind , MacroKind } ;
10
10
11
11
use if_chain:: if_chain;
12
12
13
13
use 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} ;
16
15
17
16
use utils:: { is_unit, is_unit_literal} ;
18
17
@@ -35,37 +34,11 @@ declare_clippy_lint! {
35
34
"creating a `let` binding to a value of unit type, which usually can't be used afterwards"
36
35
}
37
36
38
- declare_lint_pass ! ( LetUnitValue => [ LET_UNIT_VALUE ] ) ;
37
+ declare_lint_pass ! ( UnitTypes => [ LET_UNIT_VALUE ] ) ;
39
38
40
- impl < ' tcx > LateLintPass < ' tcx > for LetUnitValue {
39
+ impl < ' tcx > LateLintPass < ' tcx > for UnitTypes {
41
40
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) ;
69
42
}
70
43
}
71
44
0 commit comments