Update for changes in rustc

This commit is contained in:
Oliver Schneider 2017-04-24 13:35:14 +02:00
parent 613bde6e40
commit 216ce57fee
2 changed files with 21 additions and 5 deletions

View File

@ -1,9 +1,10 @@
use rustc::hir::*; use rustc::hir::*;
use rustc::hir::def::Def; use rustc::hir::def::Def;
use rustc::lint::*; use rustc::lint::*;
use rustc::ty;
use rustc_const_eval::lookup_const_by_id; use rustc_const_eval::lookup_const_by_id;
use syntax::ast::LitKind; use syntax::ast::LitKind;
use syntax::codemap::Span; use syntax::codemap::{Span, DUMMY_SP};
use utils::span_lint; use utils::span_lint;
/// **What it does:** Checks for incompatible bit masks in comparisons. /// **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) => { ExprPath(ref qpath) => {
let def = cx.tables.qpath_def(qpath, lit.id); let def = cx.tables.qpath_def(qpath, lit.id);
if let Def::Const(def_id) = def { 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 { } else {
None None
} }

View File

@ -13,6 +13,7 @@ use std::mem;
use std::rc::Rc; use std::rc::Rc;
use syntax::ast::{FloatTy, LitKind, StrStyle, NodeId}; use syntax::ast::{FloatTy, LitKind, StrStyle, NodeId};
use syntax::ptr::P; use syntax::ptr::P;
use syntax::codemap::DUMMY_SP;
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
pub enum FloatWidth { pub enum FloatWidth {
@ -286,13 +287,19 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
let substs = self.tables let substs = self.tables
.node_id_item_substs(id) .node_id_item_substs(id)
.unwrap_or_else(|| self.tcx.intern_substs(&[])); .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 { let mut cx = ConstEvalLateContext {
tcx: self.tcx, tcx: self.tcx,
tables: tables, tables: self.tcx.item_tables(const_expr),
needed_resolution: false, 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() { if ret.is_some() {
self.needed_resolution = true; self.needed_resolution = true;
} }