]> git.lizzy.rs Git - rust.git/commitdiff
Update for changes in rustc
authorOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Mon, 24 Apr 2017 11:35:14 +0000 (13:35 +0200)
committerOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Mon, 24 Apr 2017 11:35:14 +0000 (13:35 +0200)
clippy_lints/src/bit_mask.rs
clippy_lints/src/consts.rs

index 789de240d732943b168a5dfab6b9013b22078d23..c1207095140eda46c015e80d0a0c9a950497f185 100644 (file)
@@ -1,9 +1,10 @@
 use rustc::hir::*;
 use rustc::hir::def::Def;
 use rustc::lint::*;
+use rustc::ty;
 use rustc_const_eval::lookup_const_by_id;
 use syntax::ast::LitKind;
-use syntax::codemap::Span;
+use syntax::codemap::{Span, DUMMY_SP};
 use utils::span_lint;
 
 /// **What it does:** Checks for incompatible bit masks in comparisons.
@@ -249,7 +250,15 @@ fn fetch_int_literal(cx: &LateContext, lit: &Expr) -> Option<u128> {
         ExprPath(ref qpath) => {
             let def = cx.tables.qpath_def(qpath, lit.id);
             if let Def::Const(def_id) = def {
-                lookup_const_by_id(cx.tcx, def_id, Substs::empty()).and_then(|(l, _ty)| fetch_int_literal(cx, l))
+                lookup_const_by_id(cx.tcx, def_id, Substs::empty()).and_then(|(l, _ty)| {
+                    let body = if let Some(id) = cx.tcx.hir.as_local_node_id(l) {
+                        ty::queries::mir_const_qualif::get(cx.tcx, DUMMY_SP, def_id);
+                        cx.tcx.hir.body(cx.tcx.hir.body_owned_by(id))
+                    } else {
+                        cx.tcx.sess.cstore.item_body(cx.tcx, def_id)
+                    };
+                    fetch_int_literal(cx, &body.value)
+                })
             } else {
                 None
             }
index 316a7afdc3afc838efb8f6862f12bf8bbc042533..3e2cbff3d82b5e8e8f0a566cb4c7befe0f9a438c 100644 (file)
@@ -13,6 +13,7 @@
 use std::rc::Rc;
 use syntax::ast::{FloatTy, LitKind, StrStyle, NodeId};
 use syntax::ptr::P;
+use syntax::codemap::DUMMY_SP;
 
 #[derive(Debug, Copy, Clone)]
 pub enum FloatWidth {
@@ -286,13 +287,19 @@ fn fetch_path(&mut self, qpath: &QPath, id: NodeId) -> Option<Constant> {
                 let substs = self.tables
                     .node_id_item_substs(id)
                     .unwrap_or_else(|| self.tcx.intern_substs(&[]));
-                if let Some((const_expr, tables)) = lookup_const_by_id(self.tcx, def_id, substs) {
+                if let Some((const_expr, _)) = lookup_const_by_id(self.tcx, def_id, substs) {
                     let mut cx = ConstEvalLateContext {
                         tcx: self.tcx,
-                        tables: tables,
+                        tables: self.tcx.item_tables(const_expr),
                         needed_resolution: false,
                     };
-                    let ret = cx.expr(const_expr);
+                    let body = if let Some(id) = self.tcx.hir.as_local_node_id(def_id) {
+                        ty::queries::mir_const_qualif::get(self.tcx, DUMMY_SP, def_id);
+                        self.tcx.hir.body(self.tcx.hir.body_owned_by(id))
+                    } else {
+                        self.tcx.sess.cstore.item_body(self.tcx, def_id)
+                    };
+                    let ret = cx.expr(&body.value);
                     if ret.is_some() {
                         self.needed_resolution = true;
                     }