about summary refs log tree commit diff
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2019-05-10 19:37:37 -0700
committerManish Goregaokar <manishsmail@gmail.com>2019-05-10 23:40:42 -0700
commit26ebc3e9a10a6b8748dfe256c8f6d478c88d2ee4 (patch)
treecb9e82829fa1b3adadf2980284566e32b0114f96
parentc9ed92ce20fbb2871311d493148523814cca7f1d (diff)
downloadrust-26ebc3e9a10a6b8748dfe256c8f6d478c88d2ee4.tar.gz
rust-26ebc3e9a10a6b8748dfe256c8f6d478c88d2ee4.zip
Fix consts.rs
-rw-r--r--clippy_lints/src/consts.rs11
1 files changed, 6 insertions, 5 deletions
diff --git a/clippy_lints/src/consts.rs b/clippy_lints/src/consts.rs
index 3cdd0f727fb..c96c7e7e857 100644
--- a/clippy_lints/src/consts.rs
+++ b/clippy_lints/src/consts.rs
@@ -1,6 +1,6 @@
 #![allow(clippy::float_cmp)]
 
-use crate::utils::{clip, sext, unsext};
+use crate::utils::{clip, higher, sext, unsext};
 use if_chain::if_chain;
 use rustc::hir::def::{DefKind, Res};
 use rustc::hir::*;
@@ -15,7 +15,6 @@ use std::convert::TryFrom;
 use std::convert::TryInto;
 use std::hash::{Hash, Hasher};
 use syntax::ast::{FloatTy, LitKind};
-use syntax::ptr::P;
 use syntax_pos::symbol::{LocalInternedString, Symbol};
 
 /// A `LitKind`-like enum to fold constant `Expr`s into.
@@ -222,10 +221,12 @@ pub struct ConstEvalLateContext<'a, 'tcx: 'a> {
 impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
     /// Simple constant folding: Insert an expression, get a constant or none.
     pub fn expr(&mut self, e: &Expr) -> Option<Constant> {
+        if let Some((ref cond, ref then, otherwise)) = higher::if_block(&e) {
+            return self.ifthenelse(cond, then, otherwise);
+        }
         match e.node {
             ExprKind::Path(ref qpath) => self.fetch_path(qpath, e.hir_id),
             ExprKind::Block(ref block, _) => self.block(block),
-            ExprKind::If(ref cond, ref then, ref otherwise) => self.ifthenelse(cond, then, otherwise),
             ExprKind::Lit(ref lit) => Some(lit_to_constant(&lit.node, self.tables.expr_ty(e))),
             ExprKind::Array(ref vec) => self.multi(vec).map(Constant::Vec),
             ExprKind::Tup(ref tup) => self.multi(tup).map(Constant::Tuple),
@@ -358,10 +359,10 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
         }
     }
 
-    fn ifthenelse(&mut self, cond: &Expr, then: &P<Expr>, otherwise: &Option<P<Expr>>) -> Option<Constant> {
+    fn ifthenelse(&mut self, cond: &Expr, then: &Expr, otherwise: Option<&Expr>) -> Option<Constant> {
         if let Some(Constant::Bool(b)) = self.expr(cond) {
             if b {
-                self.expr(&**then)
+                self.expr(&*then)
             } else {
                 otherwise.as_ref().and_then(|expr| self.expr(expr))
             }