1
Fork 0

Update to latest rustc version

This commit is contained in:
Oliver Schneider 2017-04-27 14:00:35 +02:00
parent f2ecb7f33c
commit 3b73663506
13 changed files with 27 additions and 29 deletions

View file

@ -1,10 +1,9 @@
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, DUMMY_SP}; use syntax::codemap::Span;
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.
@ -252,7 +251,7 @@ fn fetch_int_literal(cx: &LateContext, lit: &Expr) -> Option<u128> {
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)| { 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) { 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.mir_const_qualif(def_id);
cx.tcx.hir.body(cx.tcx.hir.body_owned_by(id)) cx.tcx.hir.body(cx.tcx.hir.body_owned_by(id))
} else { } else {
cx.tcx.sess.cstore.item_body(cx.tcx, def_id) cx.tcx.sess.cstore.item_body(cx.tcx, def_id)

View file

@ -13,7 +13,6 @@ 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 {
@ -290,11 +289,11 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
if let Some((const_expr, _)) = 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: self.tcx.item_tables(const_expr), tables: self.tcx.typeck_tables_of(const_expr),
needed_resolution: false, needed_resolution: false,
}; };
let body = if let Some(id) = self.tcx.hir.as_local_node_id(def_id) { 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.mir_const_qualif(def_id);
self.tcx.hir.body(self.tcx.hir.body_owned_by(id)) self.tcx.hir.body(self.tcx.hir.body_owned_by(id))
} else { } else {
self.tcx.sess.cstore.item_body(self.tcx, def_id) self.tcx.sess.cstore.item_body(self.tcx, def_id)

View file

@ -73,7 +73,7 @@ impl LintPass for Derive {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Derive { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Derive {
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) { fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
if let ItemImpl(_, _, _, Some(ref trait_ref), _, _) = item.node { if let ItemImpl(_, _, _, Some(ref trait_ref), _, _) = item.node {
let ty = cx.tcx.item_type(cx.tcx.hir.local_def_id(item.id)); let ty = cx.tcx.type_of(cx.tcx.hir.local_def_id(item.id));
let is_automatically_derived = is_automatically_derived(&*item.attrs); let is_automatically_derived = is_automatically_derived(&*item.attrs);
check_hash_peq(cx, item.span, trait_ref, ty, is_automatically_derived); check_hash_peq(cx, item.span, trait_ref, ty, is_automatically_derived);
@ -97,7 +97,7 @@ fn check_hash_peq<'a, 'tcx>(
match_path_old(&trait_ref.path, &paths::HASH), match_path_old(&trait_ref.path, &paths::HASH),
let Some(peq_trait_def_id) = cx.tcx.lang_items.eq_trait() let Some(peq_trait_def_id) = cx.tcx.lang_items.eq_trait()
], { ], {
let peq_trait_def = cx.tcx.lookup_trait_def(peq_trait_def_id); let peq_trait_def = cx.tcx.trait_def(peq_trait_def_id);
// Look for the PartialEq implementations for `ty` // Look for the PartialEq implementations for `ty`
peq_trait_def.for_each_relevant_impl(cx.tcx, ty, |impl_id| { peq_trait_def.for_each_relevant_impl(cx.tcx, ty, |impl_id| {

View file

@ -34,7 +34,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EmptyEnum {
fn check_item(&mut self, cx: &LateContext, item: &Item) { fn check_item(&mut self, cx: &LateContext, item: &Item) {
let did = cx.tcx.hir.local_def_id(item.id); let did = cx.tcx.hir.local_def_id(item.id);
if let ItemEnum(..) = item.node { if let ItemEnum(..) = item.node {
let ty = cx.tcx.item_type(did); let ty = cx.tcx.type_of(did);
let adt = ty.ty_adt_def().expect("already checked whether this is an enum"); let adt = ty.ty_adt_def().expect("already checked whether this is an enum");
if adt.variants.is_empty() { if adt.variants.is_empty() {
span_lint_and_then(cx, EMPTY_ENUM, item.span, "enum with no variants", |db| { span_lint_and_then(cx, EMPTY_ENUM, item.span, "enum with no variants", |db| {

View file

@ -46,7 +46,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LargeEnumVariant {
fn check_item(&mut self, cx: &LateContext, item: &Item) { fn check_item(&mut self, cx: &LateContext, item: &Item) {
let did = cx.tcx.hir.local_def_id(item.id); let did = cx.tcx.hir.local_def_id(item.id);
if let ItemEnum(ref def, _) = item.node { if let ItemEnum(ref def, _) = item.node {
let ty = cx.tcx.item_type(did); let ty = cx.tcx.type_of(did);
let adt = ty.ty_adt_def().expect("already checked whether this is an enum"); let adt = ty.ty_adt_def().expect("already checked whether this is an enum");
let mut smallest_variant: Option<(_, _)> = None; let mut smallest_variant: Option<(_, _)> = None;
@ -56,7 +56,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LargeEnumVariant {
let size: u64 = variant.fields let size: u64 = variant.fields
.iter() .iter()
.map(|f| { .map(|f| {
let ty = cx.tcx.item_type(f.did); let ty = cx.tcx.type_of(f.did);
if ty.needs_subst() { if ty.needs_subst() {
0 // we can't reason about generics, so we treat them as zero sized 0 // we can't reason about generics, so we treat them as zero sized
} else { } else {

View file

@ -94,7 +94,7 @@ fn check_trait_items(cx: &LateContext, item: &Item, trait_items: &[TraitItemRef]
has_self && has_self &&
{ {
let did = cx.tcx.hir.local_def_id(item.id.node_id); let did = cx.tcx.hir.local_def_id(item.id.node_id);
let impl_ty = cx.tcx.item_type(did); let impl_ty = cx.tcx.type_of(did);
impl_ty.fn_args().skip_binder().len() == 1 impl_ty.fn_args().skip_binder().len() == 1
} }
} else { } else {
@ -121,7 +121,7 @@ fn check_impl_items(cx: &LateContext, item: &Item, impl_items: &[ImplItemRef]) {
has_self && has_self &&
{ {
let did = cx.tcx.hir.local_def_id(item.id.node_id); let did = cx.tcx.hir.local_def_id(item.id.node_id);
let impl_ty = cx.tcx.item_type(did); let impl_ty = cx.tcx.type_of(did);
impl_ty.fn_args().skip_binder().len() == 1 impl_ty.fn_args().skip_binder().len() == 1
} }
} else { } else {
@ -142,7 +142,7 @@ fn check_impl_items(cx: &LateContext, item: &Item, impl_items: &[ImplItemRef]) {
if let Some(i) = impl_items.iter().find(|i| is_named_self(cx, i, "len")) { if let Some(i) = impl_items.iter().find(|i| is_named_self(cx, i, "len")) {
if cx.access_levels.is_exported(i.id.node_id) { if cx.access_levels.is_exported(i.id.node_id) {
let def_id = cx.tcx.hir.local_def_id(item.id); let def_id = cx.tcx.hir.local_def_id(item.id);
let ty = cx.tcx.item_type(def_id); let ty = cx.tcx.type_of(def_id);
span_lint(cx, span_lint(cx,
LEN_WITHOUT_IS_EMPTY, LEN_WITHOUT_IS_EMPTY,
@ -186,7 +186,7 @@ fn has_is_empty(cx: &LateContext, expr: &Expr) -> bool {
fn is_is_empty(cx: &LateContext, item: &ty::AssociatedItem) -> bool { fn is_is_empty(cx: &LateContext, item: &ty::AssociatedItem) -> bool {
if let ty::AssociatedKind::Method = item.kind { if let ty::AssociatedKind::Method = item.kind {
if item.name == "is_empty" { if item.name == "is_empty" {
let sig = cx.tcx.item_type(item.def_id).fn_sig(); let sig = cx.tcx.type_of(item.def_id).fn_sig();
let ty = sig.skip_binder(); let ty = sig.skip_binder();
ty.inputs().len() == 1 ty.inputs().len() == 1
} else { } else {

View file

@ -281,14 +281,14 @@ impl<'v, 't> RefVisitor<'v, 't> {
match self.cx.tables.qpath_def(qpath, ty.id) { match self.cx.tables.qpath_def(qpath, ty.id) {
Def::TyAlias(def_id) | Def::TyAlias(def_id) |
Def::Struct(def_id) => { Def::Struct(def_id) => {
let generics = self.cx.tcx.item_generics(def_id); let generics = self.cx.tcx.generics_of(def_id);
for _ in generics.regions.as_slice() { for _ in generics.regions.as_slice() {
self.record(&None); self.record(&None);
} }
}, },
Def::Trait(def_id) => { Def::Trait(def_id) => {
let trait_def = self.cx.tcx.maps.trait_def.borrow()[&def_id]; let trait_def = self.cx.tcx.maps.trait_def.borrow()[&def_id];
for _ in &self.cx.tcx.item_generics(trait_def.def_id).regions { for _ in &self.cx.tcx.generics_of(trait_def.def_id).regions {
self.record(&None); self.record(&None);
} }
}, },

View file

@ -657,7 +657,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
} }
// check conventions w.r.t. conversion method names and predicates // check conventions w.r.t. conversion method names and predicates
let ty = cx.tcx.item_type(cx.tcx.hir.local_def_id(item.id)); let ty = cx.tcx.type_of(cx.tcx.hir.local_def_id(item.id));
let is_copy = is_copy(cx, ty, item.id); let is_copy = is_copy(cx, ty, item.id);
for &(ref conv, self_kinds) in &CONVENTIONS { for &(ref conv, self_kinds) in &CONVENTIONS {
if_let_chain! {[ if_let_chain! {[

View file

@ -99,7 +99,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
let fn_def_id = cx.tcx.hir.local_def_id(node_id); let fn_def_id = cx.tcx.hir.local_def_id(node_id);
let param_env = ty::ParameterEnvironment::for_item(cx.tcx, node_id); let param_env = ty::ParameterEnvironment::for_item(cx.tcx, node_id);
let fn_sig = cx.tcx.item_type(fn_def_id).fn_sig(); let fn_sig = cx.tcx.type_of(fn_def_id).fn_sig();
let fn_sig = cx.tcx.liberate_late_bound_regions(param_env.free_id_outlive, &fn_sig); let fn_sig = cx.tcx.liberate_late_bound_regions(param_env.free_id_outlive, &fn_sig);
for ((input, &ty), arg) in decl.inputs.iter().zip(fn_sig.inputs()).zip(&body.arguments) { for ((input, &ty), arg) in decl.inputs.iter().zip(fn_sig.inputs()).zip(&body.arguments) {

View file

@ -110,7 +110,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault {
} }
if decl.inputs.is_empty() && name == "new" && cx.access_levels.is_reachable(id) { if decl.inputs.is_empty() && name == "new" && cx.access_levels.is_reachable(id) {
let self_ty = cx.tcx let self_ty = cx.tcx
.item_type(cx.tcx.hir.local_def_id(cx.tcx.hir.get_parent(id))); .type_of(cx.tcx.hir.local_def_id(cx.tcx.hir.get_parent(id)));
if_let_chain!{[ if_let_chain!{[
self_ty.walk_shallow().next().is_none(), // implements_trait does not work with generics self_ty.walk_shallow().next().is_none(), // implements_trait does not work with generics
same_tys(cx, self_ty, return_ty(cx, id), id), same_tys(cx, self_ty, return_ty(cx, id), id),

View file

@ -113,7 +113,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PointerPass {
fn check_fn(cx: &LateContext, decl: &FnDecl, fn_id: NodeId) { fn check_fn(cx: &LateContext, decl: &FnDecl, fn_id: NodeId) {
let fn_def_id = cx.tcx.hir.local_def_id(fn_id); let fn_def_id = cx.tcx.hir.local_def_id(fn_id);
let sig = cx.tcx.item_type(fn_def_id).fn_sig(); let sig = cx.tcx.type_of(fn_def_id).fn_sig();
let fn_ty = sig.skip_binder(); let fn_ty = sig.skip_binder();
for (arg, ty) in decl.inputs.iter().zip(fn_ty.inputs()) { for (arg, ty) in decl.inputs.iter().zip(fn_ty.inputs()) {

View file

@ -364,26 +364,26 @@ fn print_item(cx: &LateContext, item: &hir::Item) {
} }
}, },
hir::ItemUse(ref path, ref kind) => println!("{:?}, {:?}", path, kind), hir::ItemUse(ref path, ref kind) => println!("{:?}, {:?}", path, kind),
hir::ItemStatic(..) => println!("static item of type {:#?}", cx.tcx.item_type(did)), hir::ItemStatic(..) => println!("static item of type {:#?}", cx.tcx.type_of(did)),
hir::ItemConst(..) => println!("const item of type {:#?}", cx.tcx.item_type(did)), hir::ItemConst(..) => println!("const item of type {:#?}", cx.tcx.type_of(did)),
hir::ItemFn(..) => { hir::ItemFn(..) => {
let item_ty = cx.tcx.item_type(did); let item_ty = cx.tcx.type_of(did);
println!("function of type {:#?}", item_ty); println!("function of type {:#?}", item_ty);
}, },
hir::ItemMod(..) => println!("module"), hir::ItemMod(..) => println!("module"),
hir::ItemForeignMod(ref fm) => println!("foreign module with abi: {}", fm.abi), hir::ItemForeignMod(ref fm) => println!("foreign module with abi: {}", fm.abi),
hir::ItemGlobalAsm(ref asm) => println!("global asm: {:?}", asm), hir::ItemGlobalAsm(ref asm) => println!("global asm: {:?}", asm),
hir::ItemTy(..) => { hir::ItemTy(..) => {
println!("type alias for {:?}", cx.tcx.item_type(did)); println!("type alias for {:?}", cx.tcx.type_of(did));
}, },
hir::ItemEnum(..) => { hir::ItemEnum(..) => {
println!("enum definition of type {:?}", cx.tcx.item_type(did)); println!("enum definition of type {:?}", cx.tcx.type_of(did));
}, },
hir::ItemStruct(..) => { hir::ItemStruct(..) => {
println!("struct definition of type {:?}", cx.tcx.item_type(did)); println!("struct definition of type {:?}", cx.tcx.type_of(did));
}, },
hir::ItemUnion(..) => { hir::ItemUnion(..) => {
println!("union definition of type {:?}", cx.tcx.item_type(did)); println!("union definition of type {:?}", cx.tcx.type_of(did));
}, },
hir::ItemTrait(..) => { hir::ItemTrait(..) => {
println!("trait decl"); println!("trait decl");

View file

@ -784,7 +784,7 @@ pub fn camel_case_from(s: &str) -> usize {
pub fn return_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, fn_item: NodeId) -> ty::Ty<'tcx> { pub fn return_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, fn_item: NodeId) -> ty::Ty<'tcx> {
let parameter_env = ty::ParameterEnvironment::for_item(cx.tcx, fn_item); let parameter_env = ty::ParameterEnvironment::for_item(cx.tcx, fn_item);
let fn_def_id = cx.tcx.hir.local_def_id(fn_item); let fn_def_id = cx.tcx.hir.local_def_id(fn_item);
let fn_sig = cx.tcx.item_type(fn_def_id).fn_sig(); let fn_sig = cx.tcx.type_of(fn_def_id).fn_sig();
let fn_sig = cx.tcx.liberate_late_bound_regions(parameter_env.free_id_outlive, &fn_sig); let fn_sig = cx.tcx.liberate_late_bound_regions(parameter_env.free_id_outlive, &fn_sig);
fn_sig.output() fn_sig.output()
} }