Commit f581aa7 1 parent 3d62676 commit f581aa7 Copy full SHA for f581aa7
File tree 2 files changed +50
-0
lines changed
2 files changed +50
-0
lines changed Original file line number Diff line number Diff line change
1
+ use rustc:: lint:: * ;
2
+ use syntax:: ast:: * ;
3
+ use syntax:: codemap:: Spanned ;
4
+ use utils:: { span_lint_and_sugg, snippet} ;
5
+
6
+
7
+ /// **What it does:** Checks for
8
+ /// - () being assigned to a variable
9
+ /// - () being passed to a function
10
+ ///
11
+ /// **Why is this bad?** It is extremely unlikely that a user intended to assign '()' to valiable. Instead,
12
+ /// Unit is what a block evaluates to when it returns nothing. This is typically caused by a trailing
13
+ /// unintended semicolon.
14
+ ///
15
+ /// **Known problems:** None.
16
+ ///
17
+ /// **Example:**
18
+ /// * `let x = {"foo" ;}` when the user almost certainly intended `let x ={"foo"}`
19
+
20
+ declare_lint ! {
21
+ pub UNIT_EXPR ,
22
+ Warn ,
23
+ "unintended assignment or use of a unit typed value"
24
+ }
25
+
26
+ #[ derive( Copy , Clone ) ]
27
+ pub struct UnitExpr ;
28
+
29
+ impl LintPass for UnitExpr {
30
+ fn get_lints ( & self ) -> LintArray {
31
+ lint_array ! ( UNIT_EXPR )
32
+ }
33
+ }
34
+
35
+ impl EarlyLintPass for UnitExpr {
36
+ fn check_expr ( & mut self , cx : & EarlyContext , expr : & Expr ) {
37
+ if let ExprKind :: Assign ( ref left, ref right) = expr. node {
38
+ unimplemented ! ( ) ;
39
+ }
40
+ if let ExprKind :: MethodCall ( ref path, ref args) = expr. node {
41
+ unimplemented ! ( ) ;
42
+ }
43
+ if let ExprKind :: Call ( ref path, ref args) = expr. node {
44
+ unimplemented ! ( ) ;
45
+ }
46
+ }
47
+ }
Original file line number Diff line number Diff line change @@ -91,6 +91,7 @@ pub mod functions;
91
91
pub mod identity_op;
92
92
pub mod if_let_redundant_pattern_matching;
93
93
pub mod if_not_else;
94
+ pub mod is_unit_expr;
94
95
pub mod infinite_iter;
95
96
pub mod items_after_statements;
96
97
pub mod large_enum_variant;
@@ -233,6 +234,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
233
234
reg. register_late_lint_pass ( box approx_const:: Pass ) ;
234
235
reg. register_late_lint_pass ( box misc:: Pass ) ;
235
236
reg. register_early_lint_pass ( box precedence:: Precedence ) ;
237
+ reg. register_early_lint_pass ( box is_unit_expr:: UnitExpr ) ;
236
238
reg. register_early_lint_pass ( box needless_continue:: NeedlessContinue ) ;
237
239
reg. register_late_lint_pass ( box eta_reduction:: EtaPass ) ;
238
240
reg. register_late_lint_pass ( box identity_op:: IdentityOp ) ;
@@ -504,6 +506,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
504
506
panic:: PANIC_PARAMS ,
505
507
partialeq_ne_impl:: PARTIALEQ_NE_IMPL ,
506
508
precedence:: PRECEDENCE ,
509
+ is_unit_expr:: UnitExpr ,
507
510
print:: PRINT_WITH_NEWLINE ,
508
511
ptr:: CMP_NULL ,
509
512
ptr:: MUT_FROM_REF ,
You can’t perform that action at this time.
0 commit comments