Skip to content

Commit e877de1

Browse files
committed
Rustup
1 parent fc9f2b9 commit e877de1

File tree

7 files changed

+64
-61
lines changed

7 files changed

+64
-61
lines changed

clippy_lints/src/enum_glob_use.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use rustc::hir::*;
44
use rustc::hir::def::Def;
55
use rustc::hir::map::Node::NodeItem;
66
use rustc::lint::{LateLintPass, LintPass, LateContext, LintArray, LintContext};
7-
use rustc::middle::cstore::DefLike;
87
use syntax::ast::NodeId;
98
use syntax::codemap::Span;
109
use utils::span_lint;
@@ -61,7 +60,7 @@ impl EnumGlobUse {
6160
} else {
6261
let child = cx.sess().cstore.item_children(def.full_def().def_id());
6362
if let Some(child) = child.first() {
64-
if let DefLike::DlDef(Def::Variant(..)) = child.def {
63+
if let Some(Def::Variant(..)) = cx.tcx.sess.cstore.describe_def(child.def_id) {
6564
span_lint(cx, ENUM_GLOB_USE, item.span, "don't use glob imports for enum variants");
6665
}
6766
}

clippy_lints/src/len_zero.rs

+14-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc::lint::*;
22
use rustc::hir::def_id::DefId;
3-
use rustc::ty::{self, MethodTraitItemId, ImplOrTraitItemId};
3+
use rustc::ty::{self, ImplOrTraitItem};
44
use rustc::hir::*;
55
use syntax::ast::{Lit, LitKind, Name};
66
use syntax::codemap::{Span, Spanned};
@@ -184,37 +184,33 @@ fn check_len_zero(cx: &LateContext, span: Span, name: &Name, args: &[P<Expr>], l
184184
/// Check if this type has an `is_empty` method.
185185
fn has_is_empty(cx: &LateContext, expr: &Expr) -> bool {
186186
/// Get an `ImplOrTraitItem` and return true if it matches `is_empty(self)`.
187-
fn is_is_empty(cx: &LateContext, id: &ImplOrTraitItemId) -> bool {
188-
if let MethodTraitItemId(def_id) = *id {
189-
if let ty::MethodTraitItem(ref method) = cx.tcx.impl_or_trait_item(def_id) {
190-
method.name.as_str() == "is_empty" && method.fty.sig.skip_binder().inputs.len() == 1
191-
} else {
192-
false
193-
}
187+
fn is_is_empty(item: &ImplOrTraitItem) -> bool {
188+
if let ty::MethodTraitItem(ref method) = *item {
189+
method.name.as_str() == "is_empty" && method.fty.sig.skip_binder().inputs.len() == 1
194190
} else {
195191
false
196192
}
197193
}
198194

199195
/// Check the inherent impl's items for an `is_empty(self)` method.
200-
fn has_is_empty_impl(cx: &LateContext, id: &DefId) -> bool {
201-
let impl_items = cx.tcx.impl_items.borrow();
202-
cx.tcx.inherent_impls.borrow().get(id).map_or(false, |ids| {
203-
ids.iter().any(|iid| impl_items.get(iid).map_or(false, |iids| iids.iter().any(|i| is_is_empty(cx, i))))
196+
fn has_is_empty_impl(cx: &LateContext, id: DefId) -> bool {
197+
cx.tcx.inherent_impls.borrow()[&id].iter().any(|imp| {
198+
cx.tcx.impl_or_trait_items(*imp).iter().any(|item| {
199+
is_is_empty(&cx.tcx.impl_or_trait_item(*item))
200+
})
204201
})
205202
}
206203

207204
let ty = &walk_ptrs_ty(cx.tcx.expr_ty(expr));
208205
match ty.sty {
209206
ty::TyTrait(_) => {
210207
cx.tcx
211-
.trait_item_def_ids
212-
.borrow()
213-
.get(&ty.ty_to_def_id().expect("trait impl not found"))
214-
.map_or(false, |ids| ids.iter().any(|i| is_is_empty(cx, i)))
208+
.impl_or_trait_items(ty.ty_to_def_id().expect("trait impl not found"))
209+
.iter()
210+
.any(|item| is_is_empty(&cx.tcx.impl_or_trait_item(*item)))
215211
}
216-
ty::TyProjection(_) => ty.ty_to_def_id().map_or(false, |id| has_is_empty_impl(cx, &id)),
217-
ty::TyAdt(id, _) => has_is_empty_impl(cx, &id.did),
212+
ty::TyProjection(_) => ty.ty_to_def_id().map_or(false, |id| has_is_empty_impl(cx, id)),
213+
ty::TyAdt(id, _) => has_is_empty_impl(cx, id.did),
218214
ty::TyArray(..) | ty::TyStr => true,
219215
_ => false,
220216
}

clippy_lints/src/loops.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,10 @@ impl<'v, 't> Visitor<'v> for VarVisitor<'v, 't> {
755755
if let Some(def) = def_map.get(&seqexpr.id) {
756756
match def.base_def {
757757
Def::Local(..) | Def::Upvar(..) => {
758-
let extent = self.cx.tcx.region_maps.var_scope(def.base_def.var_id());
758+
let def_id = def.base_def.def_id();
759+
let node_id = self.cx.tcx.map.as_local_node_id(def_id).unwrap();
760+
761+
let extent = self.cx.tcx.region_maps.var_scope(node_id);
759762
self.indexed.insert(seqvar.segments[0].name, Some(extent));
760763
return; // no need to walk further
761764
}
@@ -1040,7 +1043,8 @@ impl<'v, 't> Visitor<'v> for InitializeVisitor<'v, 't> {
10401043

10411044
fn var_def_id(cx: &LateContext, expr: &Expr) -> Option<NodeId> {
10421045
if let Some(path_res) = cx.tcx.def_map.borrow().get(&expr.id) {
1043-
if let Def::Local(_, node_id) = path_res.base_def {
1046+
if let Def::Local(def_id) = path_res.base_def {
1047+
let node_id = cx.tcx.map.as_local_node_id(def_id).expect("That DefId should be valid");
10441048
return Some(node_id);
10451049
}
10461050
}

clippy_lints/src/misc.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,9 @@ fn in_attributes_expansion(cx: &LateContext, expr: &Expr) -> bool {
443443
/// Test whether `def` is a variable defined outside a macro.
444444
fn non_macro_local(cx: &LateContext, def: &def::Def) -> bool {
445445
match *def {
446-
def::Def::Local(_, id) | def::Def::Upvar(_, id, _, _) => {
446+
def::Def::Local(id) | def::Def::Upvar(id, _, _) => {
447+
let id = cx.tcx.map.as_local_node_id(id).expect("That DefId should be valid");
448+
447449
if let Some(span) = cx.tcx.map.opt_span(id) {
448450
!in_macro(cx, span)
449451
} else {

clippy_lints/src/types.rs

+31-23
Original file line numberDiff line numberDiff line change
@@ -127,18 +127,21 @@ declare_lint! {
127127
fn check_let_unit(cx: &LateContext, decl: &Decl) {
128128
if let DeclLocal(ref local) = decl.node {
129129
let bindtype = &cx.tcx.pat_ty(&local.pat).sty;
130-
if *bindtype == ty::TyTuple(&[]) {
131-
if in_external_macro(cx, decl.span) || in_macro(cx, local.pat.span) {
132-
return;
133-
}
134-
if higher::is_from_for_desugar(decl) {
135-
return;
130+
match *bindtype {
131+
ty::TyTuple(slice) if slice.is_empty() => {
132+
if in_external_macro(cx, decl.span) || in_macro(cx, local.pat.span) {
133+
return;
134+
}
135+
if higher::is_from_for_desugar(decl) {
136+
return;
137+
}
138+
span_lint(cx,
139+
LET_UNIT_VALUE,
140+
decl.span,
141+
&format!("this let-binding has unit value. Consider omitting `let {} =`",
142+
snippet(cx, local.pat.span, "..")));
136143
}
137-
span_lint(cx,
138-
LET_UNIT_VALUE,
139-
decl.span,
140-
&format!("this let-binding has unit value. Consider omitting `let {} =`",
141-
snippet(cx, local.pat.span, "..")));
144+
_ => (),
142145
}
143146
}
144147
}
@@ -193,18 +196,23 @@ impl LateLintPass for UnitCmp {
193196
}
194197
if let ExprBinary(ref cmp, ref left, _) = expr.node {
195198
let op = cmp.node;
196-
let sty = &cx.tcx.expr_ty(left).sty;
197-
if *sty == ty::TyTuple(&[]) && op.is_comparison() {
198-
let result = match op {
199-
BiEq | BiLe | BiGe => "true",
200-
_ => "false",
201-
};
202-
span_lint(cx,
203-
UNIT_CMP,
204-
expr.span,
205-
&format!("{}-comparison of unit values detected. This will always be {}",
206-
op.as_str(),
207-
result));
199+
if op.is_comparison() {
200+
let sty = &cx.tcx.expr_ty(left).sty;
201+
match *sty {
202+
ty::TyTuple(slice) if slice.is_empty() => {
203+
let result = match op {
204+
BiEq | BiLe | BiGe => "true",
205+
_ => "false",
206+
};
207+
span_lint(cx,
208+
UNIT_CMP,
209+
expr.span,
210+
&format!("{}-comparison of unit values detected. This will always be {}",
211+
op.as_str(),
212+
result));
213+
}
214+
_ => ()
215+
}
208216
}
209217
}
210218
}

clippy_lints/src/utils/mod.rs

+7-13
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use reexport::*;
22
use rustc::hir::*;
3-
use rustc::hir::def_id::DefId;
3+
use rustc::hir::def_id::{DefId, CRATE_DEF_INDEX};
44
use rustc::hir::map::Node;
55
use rustc::lint::{LintContext, LateContext, Level, Lint};
6-
use rustc::middle::cstore;
76
use rustc::session::Session;
87
use rustc::traits::Reveal;
98
use rustc::traits;
@@ -216,13 +215,14 @@ pub fn match_path_ast(path: &ast::Path, segments: &[&str]) -> bool {
216215

217216
/// Get the definition associated to a path.
218217
/// TODO: investigate if there is something more efficient for that.
219-
pub fn path_to_def(cx: &LateContext, path: &[&str]) -> Option<cstore::DefLike> {
218+
pub fn path_to_def(cx: &LateContext, path: &[&str]) -> Option<def::Def> {
220219
let cstore = &cx.tcx.sess.cstore;
221220

222221
let crates = cstore.crates();
223222
let krate = crates.iter().find(|&&krate| cstore.crate_name(krate) == path[0]);
224223
if let Some(krate) = krate {
225-
let mut items = cstore.crate_top_level_items(*krate);
224+
let krate = DefId { krate: *krate, index: CRATE_DEF_INDEX };
225+
let mut items = cstore.item_children(krate);
226226
let mut path_it = path.iter().skip(1).peekable();
227227

228228
loop {
@@ -234,16 +234,10 @@ pub fn path_to_def(cx: &LateContext, path: &[&str]) -> Option<cstore::DefLike> {
234234
for item in &mem::replace(&mut items, vec![]) {
235235
if item.name.as_str() == *segment {
236236
if path_it.peek().is_none() {
237-
return Some(item.def);
237+
return cx.tcx.sess.cstore.describe_def(item.def_id);
238238
}
239239

240-
let def_id = match item.def {
241-
cstore::DefLike::DlDef(def) => def.def_id(),
242-
cstore::DefLike::DlImpl(def_id) => def_id,
243-
_ => panic!("Unexpected {:?}", item.def),
244-
};
245-
246-
items = cstore.item_children(def_id);
240+
items = cstore.item_children(item.def_id);
247241
break;
248242
}
249243
}
@@ -261,7 +255,7 @@ pub fn get_trait_def_id(cx: &LateContext, path: &[&str]) -> Option<DefId> {
261255
};
262256

263257
match def {
264-
cstore::DlDef(def::Def::Trait(trait_id)) => Some(trait_id),
258+
def::Def::Trait(trait_id) => Some(trait_id),
265259
_ => None,
266260
}
267261
}

tests/consts.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ extern crate syntax;
99
use clippy_lints::consts::{constant_simple, Constant, FloatWidth};
1010
use rustc_const_math::ConstInt;
1111
use rustc::hir::*;
12-
use syntax::ast::{LitIntType, LitKind, StrStyle};
12+
use syntax::ast::{LitIntType, LitKind, NodeId, StrStyle};
1313
use syntax::codemap::{Spanned, COMMAND_LINE_SP};
1414
use syntax::parse::token::InternedString;
1515
use syntax::ptr::P;
@@ -24,7 +24,7 @@ fn spanned<T>(t: T) -> Spanned<T> {
2424

2525
fn expr(n: Expr_) -> Expr {
2626
Expr {
27-
id: 1,
27+
id: NodeId::new(1),
2828
node: n,
2929
span: COMMAND_LINE_SP,
3030
attrs: ThinVec::new(),

0 commit comments

Comments
 (0)