@@ -2,7 +2,7 @@ use crate::utils::{differing_macro_contexts, in_macro_or_desugar, snippet_opt, s
2
2
use if_chain:: if_chain;
3
3
use rustc:: lint:: { in_external_macro, EarlyContext , EarlyLintPass , LintArray , LintPass } ;
4
4
use rustc:: { declare_lint_pass, declare_tool_lint} ;
5
- use syntax:: ast;
5
+ use syntax:: ast:: * ;
6
6
use syntax:: ptr:: P ;
7
7
8
8
declare_clippy_lint ! {
@@ -86,33 +86,33 @@ declare_lint_pass!(Formatting => [
86
86
] ) ;
87
87
88
88
impl EarlyLintPass for Formatting {
89
- fn check_block ( & mut self , cx : & EarlyContext < ' _ > , block : & ast :: Block ) {
89
+ fn check_block ( & mut self , cx : & EarlyContext < ' _ > , block : & Block ) {
90
90
for w in block. stmts . windows ( 2 ) {
91
91
match ( & w[ 0 ] . node , & w[ 1 ] . node ) {
92
- ( & ast :: StmtKind :: Expr ( ref first) , & ast :: StmtKind :: Expr ( ref second) )
93
- | ( & ast :: StmtKind :: Expr ( ref first) , & ast :: StmtKind :: Semi ( ref second) ) => {
92
+ ( & StmtKind :: Expr ( ref first) , & StmtKind :: Expr ( ref second) )
93
+ | ( & StmtKind :: Expr ( ref first) , & StmtKind :: Semi ( ref second) ) => {
94
94
check_missing_else ( cx, first, second) ;
95
95
} ,
96
96
_ => ( ) ,
97
97
}
98
98
}
99
99
}
100
100
101
- fn check_expr ( & mut self , cx : & EarlyContext < ' _ > , expr : & ast :: Expr ) {
101
+ fn check_expr ( & mut self , cx : & EarlyContext < ' _ > , expr : & Expr ) {
102
102
check_assign ( cx, expr) ;
103
103
check_else ( cx, expr) ;
104
104
check_array ( cx, expr) ;
105
105
}
106
106
}
107
107
108
108
/// Implementation of the `SUSPICIOUS_ASSIGNMENT_FORMATTING` lint.
109
- fn check_assign ( cx : & EarlyContext < ' _ > , expr : & ast :: Expr ) {
110
- if let ast :: ExprKind :: Assign ( ref lhs, ref rhs) = expr. node {
109
+ fn check_assign ( cx : & EarlyContext < ' _ > , expr : & Expr ) {
110
+ if let ExprKind :: Assign ( ref lhs, ref rhs) = expr. node {
111
111
if !differing_macro_contexts ( lhs. span , rhs. span ) && !in_macro_or_desugar ( lhs. span ) {
112
112
let eq_span = lhs. span . between ( rhs. span ) ;
113
- if let ast :: ExprKind :: Unary ( op, ref sub_rhs) = rhs. node {
113
+ if let ExprKind :: Unary ( op, ref sub_rhs) = rhs. node {
114
114
if let Some ( eq_snippet) = snippet_opt ( cx, eq_span) {
115
- let op = ast :: UnOp :: to_string ( op) ;
115
+ let op = UnOp :: to_string ( op) ;
116
116
let eqop_span = lhs. span . between ( sub_rhs. span ) ;
117
117
if eq_snippet. ends_with ( '=' ) {
118
118
span_note_and_lint (
@@ -135,7 +135,7 @@ fn check_assign(cx: &EarlyContext<'_>, expr: &ast::Expr) {
135
135
}
136
136
137
137
/// Implementation of the `SUSPICIOUS_ELSE_FORMATTING` lint for weird `else`.
138
- fn check_else ( cx : & EarlyContext < ' _ > , expr : & ast :: Expr ) {
138
+ fn check_else ( cx : & EarlyContext < ' _ > , expr : & Expr ) {
139
139
if_chain ! {
140
140
if let Some ( ( then, & Some ( ref else_) ) ) = unsugar_if( expr) ;
141
141
if is_block( else_) || unsugar_if( else_) . is_some( ) ;
@@ -173,16 +173,16 @@ fn check_else(cx: &EarlyContext<'_>, expr: &ast::Expr) {
173
173
}
174
174
}
175
175
176
- fn has_unary_equivalent ( bin_op : ast :: BinOpKind ) -> bool {
176
+ fn has_unary_equivalent ( bin_op : BinOpKind ) -> bool {
177
177
// &, *, -
178
- bin_op == ast :: BinOpKind :: And || bin_op == ast :: BinOpKind :: Mul || bin_op == ast :: BinOpKind :: Sub
178
+ bin_op == BinOpKind :: And || bin_op == BinOpKind :: Mul || bin_op == BinOpKind :: Sub
179
179
}
180
180
181
181
/// Implementation of the `POSSIBLE_MISSING_COMMA` lint for array
182
- fn check_array ( cx : & EarlyContext < ' _ > , expr : & ast :: Expr ) {
183
- if let ast :: ExprKind :: Array ( ref array) = expr. node {
182
+ fn check_array ( cx : & EarlyContext < ' _ > , expr : & Expr ) {
183
+ if let ExprKind :: Array ( ref array) = expr. node {
184
184
for element in array {
185
- if let ast :: ExprKind :: Binary ( ref op, ref lhs, _) = element. node {
185
+ if let ExprKind :: Binary ( ref op, ref lhs, _) = element. node {
186
186
if has_unary_equivalent ( op. node ) && !differing_macro_contexts ( lhs. span , op. span ) {
187
187
let space_span = lhs. span . between ( op. span ) ;
188
188
if let Some ( space_snippet) = snippet_opt ( cx, space_span) {
@@ -204,7 +204,7 @@ fn check_array(cx: &EarlyContext<'_>, expr: &ast::Expr) {
204
204
}
205
205
}
206
206
207
- fn check_missing_else ( cx : & EarlyContext < ' _ > , first : & ast :: Expr , second : & ast :: Expr ) {
207
+ fn check_missing_else ( cx : & EarlyContext < ' _ > , first : & Expr , second : & Expr ) {
208
208
if !differing_macro_contexts ( first. span , second. span )
209
209
&& !in_macro_or_desugar ( first. span )
210
210
&& unsugar_if ( first) . is_some ( )
@@ -237,18 +237,18 @@ fn check_missing_else(cx: &EarlyContext<'_>, first: &ast::Expr, second: &ast::Ex
237
237
}
238
238
}
239
239
240
- fn is_block ( expr : & ast :: Expr ) -> bool {
241
- if let ast :: ExprKind :: Block ( ..) = expr. node {
240
+ fn is_block ( expr : & Expr ) -> bool {
241
+ if let ExprKind :: Block ( ..) = expr. node {
242
242
true
243
243
} else {
244
244
false
245
245
}
246
246
}
247
247
248
248
/// Match `if` or `if let` expressions and return the `then` and `else` block.
249
- fn unsugar_if ( expr : & ast :: Expr ) -> Option < ( & P < ast :: Block > , & Option < P < ast :: Expr > > ) > {
249
+ fn unsugar_if ( expr : & Expr ) -> Option < ( & P < Block > , & Option < P < Expr > > ) > {
250
250
match expr. node {
251
- ast :: ExprKind :: If ( _, ref then, ref else_) => Some ( ( then, else_) ) ,
251
+ ExprKind :: If ( _, ref then, ref else_) => Some ( ( then, else_) ) ,
252
252
_ => None ,
253
253
}
254
254
}
0 commit comments