@@ -3,7 +3,6 @@ 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
5
use syntax:: ast:: * ;
6
- use syntax:: ptr:: P ;
7
6
8
7
declare_clippy_lint ! {
9
8
/// **What it does:** Checks for use of the non-existent `=*`, `=!` and `=-`
@@ -137,8 +136,8 @@ fn check_assign(cx: &EarlyContext<'_>, expr: &Expr) {
137
136
/// Implementation of the `SUSPICIOUS_ELSE_FORMATTING` lint for weird `else`.
138
137
fn check_else ( cx : & EarlyContext < ' _ > , expr : & Expr ) {
139
138
if_chain ! {
140
- if let Some ( ( then, & Some ( ref else_) ) ) = unsugar_if ( expr) ;
141
- if is_block( else_) || unsugar_if ( else_) . is_some ( ) ;
139
+ if let ExprKind :: If ( _ , then, Some ( else_) ) = & expr. node ;
140
+ if is_block( else_) || is_if ( else_) ;
142
141
if !differing_macro_contexts( then. span, else_. span) ;
143
142
if !in_macro_or_desugar( then. span) && !in_external_macro( cx. sess, expr. span) ;
144
143
@@ -154,7 +153,7 @@ fn check_else(cx: &EarlyContext<'_>, expr: &Expr) {
154
153
if let Some ( else_snippet) = snippet_opt( cx, else_span) ;
155
154
if let Some ( else_pos) = else_snippet. find( "else" ) ;
156
155
if else_snippet[ else_pos..] . contains( '\n' ) ;
157
- let else_desc = if unsugar_if ( else_) . is_some ( ) { "if" } else { "{..}" } ;
156
+ let else_desc = if is_if ( else_) { "if" } else { "{..}" } ;
158
157
159
158
then {
160
159
span_note_and_lint(
@@ -207,15 +206,15 @@ fn check_array(cx: &EarlyContext<'_>, expr: &Expr) {
207
206
fn check_missing_else ( cx : & EarlyContext < ' _ > , first : & Expr , second : & Expr ) {
208
207
if !differing_macro_contexts ( first. span , second. span )
209
208
&& !in_macro_or_desugar ( first. span )
210
- && unsugar_if ( first) . is_some ( )
211
- && ( is_block ( second) || unsugar_if ( second) . is_some ( ) )
209
+ && is_if ( first)
210
+ && ( is_block ( second) || is_if ( second) )
212
211
{
213
212
// where the else would be
214
213
let else_span = first. span . between ( second. span ) ;
215
214
216
215
if let Some ( else_snippet) = snippet_opt ( cx, else_span) {
217
216
if !else_snippet. contains ( '\n' ) {
218
- let ( looks_like, next_thing) = if unsugar_if ( second) . is_some ( ) {
217
+ let ( looks_like, next_thing) = if is_if ( second) {
219
218
( "an `else if`" , "the second `if`" )
220
219
} else {
221
220
( "an `else {..}`" , "the next block" )
@@ -245,10 +244,11 @@ fn is_block(expr: &Expr) -> bool {
245
244
}
246
245
}
247
246
248
- /// Match `if` or `if let` expressions and return the `then` and `else` block.
249
- fn unsugar_if ( expr : & Expr ) -> Option < ( & P < Block > , & Option < P < Expr > > ) > {
250
- match expr. node {
251
- ExprKind :: If ( _, ref then, ref else_) => Some ( ( then, else_) ) ,
252
- _ => None ,
247
+ /// Check if the expression is an `if` or `if let`
248
+ fn is_if ( expr : & Expr ) -> bool {
249
+ if let ExprKind :: If ( ..) = expr. node {
250
+ true
251
+ } else {
252
+ false
253
253
}
254
254
}
0 commit comments