11use clippy_utils:: diagnostics:: { span_lint_and_help, span_lint_and_note} ;
2- use clippy_utils:: differing_macro_contexts;
32use clippy_utils:: source:: snippet_opt;
43use if_chain:: if_chain;
54use rustc_ast:: ast:: { BinOpKind , Block , Expr , ExprKind , StmtKind , UnOp } ;
@@ -135,7 +134,7 @@ impl EarlyLintPass for Formatting {
135134/// Implementation of the `SUSPICIOUS_ASSIGNMENT_FORMATTING` lint.
136135fn check_assign ( cx : & EarlyContext < ' _ > , expr : & Expr ) {
137136 if let ExprKind :: Assign ( ref lhs, ref rhs, _) = expr. kind {
138- if !differing_macro_contexts ( lhs. span , rhs . span ) && !lhs . span . from_expansion ( ) {
137+ if !lhs. span . from_expansion ( ) && !rhs . span . from_expansion ( ) {
139138 let eq_span = lhs. span . between ( rhs. span ) ;
140139 if let ExprKind :: Unary ( op, ref sub_rhs) = rhs. kind {
141140 if let Some ( eq_snippet) = snippet_opt ( cx, eq_span) {
@@ -165,7 +164,7 @@ fn check_assign(cx: &EarlyContext<'_>, expr: &Expr) {
165164fn check_unop ( cx : & EarlyContext < ' _ > , expr : & Expr ) {
166165 if_chain ! {
167166 if let ExprKind :: Binary ( ref binop, ref lhs, ref rhs) = expr. kind;
168- if !differing_macro_contexts ( lhs. span, rhs . span ) && !lhs . span. from_expansion( ) ;
167+ if !lhs. span. from_expansion ( ) && !rhs . span. from_expansion( ) ;
169168 // span between BinOp LHS and RHS
170169 let binop_span = lhs. span. between( rhs. span) ;
171170 // if RHS is an UnOp
@@ -206,8 +205,8 @@ fn check_else(cx: &EarlyContext<'_>, expr: &Expr) {
206205 if_chain ! {
207206 if let ExprKind :: If ( _, then, Some ( else_) ) = & expr. kind;
208207 if is_block( else_) || is_if( else_) ;
209- if !differing_macro_contexts ( then. span, else_. span) ;
210- if !then . span . from_expansion ( ) && ! in_external_macro( cx. sess( ) , expr. span) ;
208+ if !then. span. from_expansion ( ) && ! else_. span. from_expansion ( ) ;
209+ if !in_external_macro( cx. sess( ) , expr. span) ;
211210
212211 // workaround for rust-lang/rust#43081
213212 if expr. span. lo( ) . 0 != 0 && expr. span. hi( ) . 0 != 0 ;
@@ -268,7 +267,7 @@ fn check_array(cx: &EarlyContext<'_>, expr: &Expr) {
268267 for element in array {
269268 if_chain ! {
270269 if let ExprKind :: Binary ( ref op, ref lhs, _) = element. kind;
271- if has_unary_equivalent( op. node) && !differing_macro_contexts ( lhs. span, op. span) ;
270+ if has_unary_equivalent( op. node) && lhs. span. ctxt ( ) == op. span. ctxt ( ) ;
272271 let space_span = lhs. span. between( op. span) ;
273272 if let Some ( space_snippet) = snippet_opt( cx, space_span) ;
274273 let lint_span = lhs. span. with_lo( lhs. span. hi( ) ) ;
@@ -291,8 +290,7 @@ fn check_array(cx: &EarlyContext<'_>, expr: &Expr) {
291290
292291fn check_missing_else ( cx : & EarlyContext < ' _ > , first : & Expr , second : & Expr ) {
293292 if_chain ! {
294- if !differing_macro_contexts( first. span, second. span) ;
295- if !first. span. from_expansion( ) ;
293+ if !first. span. from_expansion( ) && !second. span. from_expansion( ) ;
296294 if let ExprKind :: If ( cond_expr, ..) = & first. kind;
297295 if is_block( second) || is_if( second) ;
298296
0 commit comments