@@ -2,7 +2,7 @@ use crate::utils::{differing_macro_contexts, in_macro_or_desugar, snippet_opt, s
22use if_chain:: if_chain;
33use rustc:: lint:: { in_external_macro, EarlyContext , EarlyLintPass , LintArray , LintPass } ;
44use rustc:: { declare_lint_pass, declare_tool_lint} ;
5- use syntax:: ast;
5+ use syntax:: ast:: * ;
66use syntax:: ptr:: P ;
77
88declare_clippy_lint ! {
@@ -86,33 +86,33 @@ declare_lint_pass!(Formatting => [
8686] ) ;
8787
8888impl EarlyLintPass for Formatting {
89- fn check_block ( & mut self , cx : & EarlyContext < ' _ > , block : & ast :: Block ) {
89+ fn check_block ( & mut self , cx : & EarlyContext < ' _ > , block : & Block ) {
9090 for w in block. stmts . windows ( 2 ) {
9191 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) ) => {
9494 check_missing_else ( cx, first, second) ;
9595 } ,
9696 _ => ( ) ,
9797 }
9898 }
9999 }
100100
101- fn check_expr ( & mut self , cx : & EarlyContext < ' _ > , expr : & ast :: Expr ) {
101+ fn check_expr ( & mut self , cx : & EarlyContext < ' _ > , expr : & Expr ) {
102102 check_assign ( cx, expr) ;
103103 check_else ( cx, expr) ;
104104 check_array ( cx, expr) ;
105105 }
106106}
107107
108108/// 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 {
111111 if !differing_macro_contexts ( lhs. span , rhs. span ) && !in_macro_or_desugar ( lhs. span ) {
112112 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 {
114114 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) ;
116116 let eqop_span = lhs. span . between ( sub_rhs. span ) ;
117117 if eq_snippet. ends_with ( '=' ) {
118118 span_note_and_lint (
@@ -135,7 +135,7 @@ fn check_assign(cx: &EarlyContext<'_>, expr: &ast::Expr) {
135135}
136136
137137/// 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 ) {
139139 if_chain ! {
140140 if let Some ( ( then, & Some ( ref else_) ) ) = unsugar_if( expr) ;
141141 if is_block( else_) || unsugar_if( else_) . is_some( ) ;
@@ -173,16 +173,16 @@ fn check_else(cx: &EarlyContext<'_>, expr: &ast::Expr) {
173173 }
174174}
175175
176- fn has_unary_equivalent ( bin_op : ast :: BinOpKind ) -> bool {
176+ fn has_unary_equivalent ( bin_op : BinOpKind ) -> bool {
177177 // &, *, -
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
179179}
180180
181181/// 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 {
184184 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 {
186186 if has_unary_equivalent ( op. node ) && !differing_macro_contexts ( lhs. span , op. span ) {
187187 let space_span = lhs. span . between ( op. span ) ;
188188 if let Some ( space_snippet) = snippet_opt ( cx, space_span) {
@@ -204,7 +204,7 @@ fn check_array(cx: &EarlyContext<'_>, expr: &ast::Expr) {
204204 }
205205}
206206
207- fn check_missing_else ( cx : & EarlyContext < ' _ > , first : & ast :: Expr , second : & ast :: Expr ) {
207+ fn check_missing_else ( cx : & EarlyContext < ' _ > , first : & Expr , second : & Expr ) {
208208 if !differing_macro_contexts ( first. span , second. span )
209209 && !in_macro_or_desugar ( first. span )
210210 && unsugar_if ( first) . is_some ( )
@@ -237,18 +237,18 @@ fn check_missing_else(cx: &EarlyContext<'_>, first: &ast::Expr, second: &ast::Ex
237237 }
238238}
239239
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 {
242242 true
243243 } else {
244244 false
245245 }
246246}
247247
248248/// 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 > > ) > {
250250 match expr. node {
251- ast :: ExprKind :: If ( _, ref then, ref else_) => Some ( ( then, else_) ) ,
251+ ExprKind :: If ( _, ref then, ref else_) => Some ( ( then, else_) ) ,
252252 _ => None ,
253253 }
254254}
0 commit comments