From 216ce57fee1062feeaae74ba5a83c8890dda4fd4 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Mon, 24 Apr 2017 13:35:14 +0200 Subject: [PATCH] Update for changes in rustc --- clippy_lints/src/bit_mask.rs | 13 +++++++++++-- clippy_lints/src/consts.rs | 13 ++++++++++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/clippy_lints/src/bit_mask.rs b/clippy_lints/src/bit_mask.rs index 789de240d73..c1207095140 100644 --- a/clippy_lints/src/bit_mask.rs +++ b/clippy_lints/src/bit_mask.rs @@ -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 { 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 } diff --git a/clippy_lints/src/consts.rs b/clippy_lints/src/consts.rs index 316a7afdc3a..3e2cbff3d82 100644 --- a/clippy_lints/src/consts.rs +++ b/clippy_lints/src/consts.rs @@ -13,6 +13,7 @@ use std::mem; 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 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> { 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; }