Skip to content

Commit 59b0077

Browse files
committed
WIP compiles and doesn't crash (much) but tests are failing
1 parent f9fe50d commit 59b0077

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+387
-347
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Change Log
22
All notable changes to this project will be documented in this file.
33

4+
## 0.0.104 — 2016-12-01
5+
* Update to *rustc 1.15.0-nightly (1c448574b 2016-11-28)*
6+
47
## 0.0.103 — 2016-11-25
58
* Update to *rustc 1.15.0-nightly (d5814b03e 2016-11-23)*
69

clippy_lints/src/attrs.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,15 @@ impl LateLintPass for AttrPass {
105105
}
106106
match item.node {
107107
ItemExternCrate(_) |
108-
ItemUse(_) => {
108+
ItemUse(_, _) => {
109109
for attr in &item.attrs {
110110
if let MetaItemKind::List(ref lint_list) = attr.value.node {
111111
match &*attr.name().as_str() {
112112
"allow" | "warn" | "deny" | "forbid" => {
113113
// whitelist `unused_imports`
114114
for lint in lint_list {
115115
if is_word(lint, "unused_imports") {
116-
if let ItemUse(_) = item.node {
116+
if let ItemUse(_, _) = item.node {
117117
return;
118118
}
119119
}
@@ -193,8 +193,8 @@ fn is_relevant_expr(cx: &LateContext, expr: &Expr) -> bool {
193193
ExprRet(Some(ref e)) => is_relevant_expr(cx, e),
194194
ExprRet(None) | ExprBreak(_, None) => false,
195195
ExprCall(ref path_expr, _) => {
196-
if let ExprPath(..) = path_expr.node {
197-
let fun_id = resolve_node(cx, path_expr.id).expect("function should be resolved").def_id();
196+
if let ExprPath(ref qpath) = path_expr.node {
197+
let fun_id = resolve_node(cx, qpath, path_expr.id).def_id();
198198
!match_def_path(cx, fun_id, &paths::BEGIN_PANIC)
199199
} else {
200200
true

clippy_lints/src/bit_mask.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use rustc::hir::*;
2-
use rustc::hir::def::{Def, PathResolution};
2+
use rustc::hir::def::Def;
33
use rustc::lint::*;
44
use rustc_const_eval::lookup_const_by_id;
55
use syntax::ast::LitKind;
@@ -245,18 +245,13 @@ fn fetch_int_literal(cx: &LateContext, lit: &Expr) -> Option<u64> {
245245
None
246246
}
247247
}
248-
ExprPath(_, _) => {
249-
{
250-
// Important to let the borrow expire before the const lookup to avoid double
251-
// borrowing.
252-
let def_map = cx.tcx.def_map.borrow();
253-
match def_map.get(&lit.id) {
254-
Some(&PathResolution { base_def: Def::Const(def_id), .. }) => Some(def_id),
255-
_ => None,
256-
}
248+
ExprPath(ref qpath) => {
249+
let def = cx.tcx.tables().qpath_def(qpath, lit.id);
250+
if let Def::Const(def_id) = def {
251+
lookup_const_by_id(cx.tcx, def_id, None).and_then(|(l, _ty)| fetch_int_literal(cx, l))
252+
} else {
253+
None
257254
}
258-
.and_then(|def_id| lookup_const_by_id(cx.tcx, def_id, None))
259-
.and_then(|(l, _ty)| fetch_int_literal(cx, l))
260255
}
261256
_ => None,
262257
}

clippy_lints/src/blacklisted_name.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl LintPass for BlackListedName {
3939

4040
impl LateLintPass for BlackListedName {
4141
fn check_pat(&mut self, cx: &LateContext, pat: &Pat) {
42-
if let PatKind::Binding(_, ref ident, _) = pat.node {
42+
if let PatKind::Binding(_, _, ref ident, _) = pat.node {
4343
if self.blacklist.iter().any(|s| s == &*ident.node.as_str()) {
4444
span_lint(cx,
4545
BLACKLISTED_NAME,

clippy_lints/src/consts.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![allow(cast_possible_truncation)]
22

33
use rustc::lint::LateContext;
4-
use rustc::hir::def::{Def, PathResolution};
4+
use rustc::hir::def::Def;
55
use rustc_const_eval::lookup_const_by_id;
66
use rustc_const_math::{ConstInt, ConstUsize, ConstIsize};
77
use rustc::hir::*;
@@ -10,7 +10,7 @@ use std::cmp::PartialOrd;
1010
use std::hash::{Hash, Hasher};
1111
use std::mem;
1212
use std::rc::Rc;
13-
use syntax::ast::{FloatTy, LitIntType, LitKind, StrStyle, UintTy, IntTy};
13+
use syntax::ast::{FloatTy, LitIntType, LitKind, StrStyle, UintTy, IntTy, NodeId};
1414
use syntax::ptr::P;
1515

1616
#[derive(Debug, Copy, Clone)]
@@ -252,7 +252,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
252252
/// simple constant folding: Insert an expression, get a constant or none.
253253
fn expr(&mut self, e: &Expr) -> Option<Constant> {
254254
match e.node {
255-
ExprPath(_, _) => self.fetch_path(e),
255+
ExprPath(ref qpath) => self.fetch_path(qpath, e.id),
256256
ExprBlock(ref block) => self.block(block),
257257
ExprIf(ref cond, ref then, ref otherwise) => self.ifthenelse(cond, then, otherwise),
258258
ExprLit(ref lit) => Some(lit_to_constant(&lit.node)),
@@ -285,21 +285,22 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
285285
}
286286

287287
/// lookup a possibly constant expression from a ExprPath
288-
fn fetch_path(&mut self, e: &Expr) -> Option<Constant> {
288+
fn fetch_path(&mut self, qpath: &QPath, id: NodeId) -> Option<Constant> {
289289
if let Some(lcx) = self.lcx {
290-
let mut maybe_id = None;
291-
if let Some(&PathResolution { base_def: Def::Const(id), .. }) = lcx.tcx.def_map.borrow().get(&e.id) {
292-
maybe_id = Some(id);
293-
}
294-
// separate if lets to avoid double borrowing the def_map
295-
if let Some(id) = maybe_id {
296-
if let Some((const_expr, _ty)) = lookup_const_by_id(lcx.tcx, id, None) {
297-
let ret = self.expr(const_expr);
298-
if ret.is_some() {
299-
self.needed_resolution = true;
290+
let def = lcx.tcx.tables().qpath_def(qpath, id);
291+
match def {
292+
Def::Const(def_id) | Def::AssociatedConst(def_id) => {
293+
let substs = Some(lcx.tcx.tables().node_id_item_substs(id)
294+
.unwrap_or_else(|| lcx.tcx.intern_substs(&[])));
295+
if let Some((const_expr, _ty)) = lookup_const_by_id(lcx.tcx, def_id, substs) {
296+
let ret = self.expr(const_expr);
297+
if ret.is_some() {
298+
self.needed_resolution = true;
299+
}
300+
return ret;
300301
}
301-
return ret;
302-
}
302+
},
303+
_ => {},
303304
}
304305
}
305306
None

clippy_lints/src/copies.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ fn bindings<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat) -> HashMap<Interned
254254
bindings_impl(cx, pat, map);
255255
}
256256
}
257-
PatKind::Binding(_, ref ident, ref as_pat) => {
257+
PatKind::Binding(_, _, ref ident, ref as_pat) => {
258258
if let Entry::Vacant(v) = map.entry(ident.node.as_str()) {
259259
v.insert(cx.tcx.tables().pat_ty(pat));
260260
}

clippy_lints/src/derive.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc::ty;
55
use rustc::hir::*;
66
use syntax::codemap::Span;
77
use utils::paths;
8-
use utils::{is_automatically_derived, match_path, span_lint_and_then};
8+
use utils::{is_automatically_derived, span_lint_and_then, match_path_old};
99

1010
/// **What it does:** Checks for deriving `Hash` but implementing `PartialEq`
1111
/// explicitly.
@@ -89,7 +89,7 @@ impl LateLintPass for Derive {
8989
fn check_hash_peq<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, span: Span, trait_ref: &TraitRef, ty: ty::Ty<'tcx>,
9090
hash_is_automatically_derived: bool) {
9191
if_let_chain! {[
92-
match_path(&trait_ref.path, &paths::HASH),
92+
match_path_old(&trait_ref.path, &paths::HASH),
9393
let Some(peq_trait_def_id) = cx.tcx.lang_items.eq_trait()
9494
], {
9595
let peq_trait_def = cx.tcx.lookup_trait_def(peq_trait_def_id);
@@ -131,7 +131,7 @@ fn check_hash_peq<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, span: Span, trait_re
131131

132132
/// Implementation of the `EXPL_IMPL_CLONE_ON_COPY` lint.
133133
fn check_copy_clone<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, item: &Item, trait_ref: &TraitRef, ty: ty::Ty<'tcx>) {
134-
if match_path(&trait_ref.path, &paths::CLONE_TRAIT) {
134+
if match_path_old(&trait_ref.path, &paths::CLONE_TRAIT) {
135135
let parameter_environment = ty::ParameterEnvironment::for_item(cx.tcx, item.id);
136136
let subst_ty = ty.subst(cx.tcx, parameter_environment.free_substs);
137137

clippy_lints/src/drop_ref.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ impl LintPass for Pass {
3838
impl LateLintPass for Pass {
3939
fn check_expr(&mut self, cx: &LateContext, expr: &Expr) {
4040
if let ExprCall(ref path, ref args) = expr.node {
41-
if let ExprPath(None, _) = path.node {
42-
let def_id = cx.tcx.expect_def(path.id).def_id();
41+
if let ExprPath(ref qpath) = path.node {
42+
let def_id = cx.tcx.tables().qpath_def(qpath, path.id).def_id();
4343
if match_def_path(cx, def_id, &paths::DROP) {
4444
if args.len() != 1 {
4545
return;

clippy_lints/src/enum_glob_use.rs

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
33
use rustc::hir::*;
44
use rustc::hir::def::Def;
5-
use rustc::hir::map::Node::NodeItem;
6-
use rustc::lint::{LateLintPass, LintPass, LateContext, LintArray, LintContext};
5+
use rustc::lint::{LateLintPass, LintPass, LateContext, LintArray};
76
use syntax::ast::NodeId;
87
use syntax::codemap::Span;
98
use utils::span_lint;
@@ -48,24 +47,9 @@ impl EnumGlobUse {
4847
if item.vis == Visibility::Public {
4948
return; // re-exports are fine
5049
}
51-
if let ItemUse(ref item_use) = item.node {
52-
if let ViewPath_::ViewPathGlob(_) = item_use.node {
53-
if let Some(def) = cx.tcx.def_map.borrow().get(&item.id) {
54-
if let Some(node_id) = cx.tcx.map.as_local_node_id(def.full_def().def_id()) {
55-
if let Some(NodeItem(it)) = cx.tcx.map.find(node_id) {
56-
if let ItemEnum(..) = it.node {
57-
span_lint(cx, ENUM_GLOB_USE, item.span, "don't use glob imports for enum variants");
58-
}
59-
}
60-
} else {
61-
let child = cx.sess().cstore.item_children(def.full_def().def_id());
62-
if let Some(child) = child.first() {
63-
if let Def::Variant(..) = child.def {
64-
span_lint(cx, ENUM_GLOB_USE, item.span, "don't use glob imports for enum variants");
65-
}
66-
}
67-
}
68-
}
50+
if let ItemUse(ref path, UseKind::Glob) = item.node {
51+
if let Def::Enum(_) = path.def {
52+
span_lint(cx, ENUM_GLOB_USE, item.span, "don't use glob imports for enum variants");
6953
}
7054
}
7155
}

clippy_lints/src/eta_reduction.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ fn check_closure(cx: &LateContext, expr: &Expr) {
7272
_ => (),
7373
}
7474
for (a1, a2) in decl.inputs.iter().zip(args) {
75-
if let PatKind::Binding(_, ident, _) = a1.pat.node {
75+
if let PatKind::Binding(_, _, ident, _) = a1.pat.node {
7676
// XXXManishearth Should I be checking the binding mode here?
77-
if let ExprPath(None, ref p) = a2.node {
77+
if let ExprPath(QPath::Resolved(None, ref p)) = a2.node {
7878
if p.segments.len() != 1 {
7979
// If it's a proper path, it can't be a local variable
8080
return;

clippy_lints/src/eval_order_dependence.rs

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,18 @@ impl LateLintPass for EvalOrderDependence {
6161
// Find a write to a local variable.
6262
match expr.node {
6363
ExprAssign(ref lhs, _) | ExprAssignOp(_, ref lhs, _) => {
64-
if let ExprPath(None, ref path) = lhs.node {
65-
if path.segments.len() == 1 {
66-
let var = cx.tcx.expect_def(lhs.id).def_id();
67-
let mut visitor = ReadVisitor {
68-
cx: cx,
69-
var: var,
70-
write_expr: expr,
71-
last_expr: expr,
72-
};
73-
check_for_unsequenced_reads(&mut visitor);
64+
if let ExprPath(ref qpath) = lhs.node {
65+
if let QPath::Resolved(_, ref path) = *qpath {
66+
if path.segments.len() == 1 {
67+
let var = cx.tcx.tables().qpath_def(qpath, lhs.id).def_id();
68+
let mut visitor = ReadVisitor {
69+
cx: cx,
70+
var: var,
71+
write_expr: expr,
72+
last_expr: expr,
73+
};
74+
check_for_unsequenced_reads(&mut visitor);
75+
}
7476
}
7577
}
7678
}
@@ -293,19 +295,21 @@ impl<'v, 't> Visitor<'v> for ReadVisitor<'v, 't> {
293295
}
294296

295297
match expr.node {
296-
ExprPath(None, ref path) => {
297-
if path.segments.len() == 1 && self.cx.tcx.expect_def(expr.id).def_id() == self.var {
298-
if is_in_assignment_position(self.cx, expr) {
299-
// This is a write, not a read.
300-
} else {
301-
span_note_and_lint(
302-
self.cx,
303-
EVAL_ORDER_DEPENDENCE,
304-
expr.span,
305-
"unsequenced read of a variable",
306-
self.write_expr.span,
307-
"whether read occurs before this write depends on evaluation order"
308-
);
298+
ExprPath(ref qpath) => {
299+
if let QPath::Resolved(None, ref path) = *qpath {
300+
if path.segments.len() == 1 && self.cx.tcx.tables().qpath_def(qpath, expr.id).def_id() == self.var {
301+
if is_in_assignment_position(self.cx, expr) {
302+
// This is a write, not a read.
303+
} else {
304+
span_note_and_lint(
305+
self.cx,
306+
EVAL_ORDER_DEPENDENCE,
307+
expr.span,
308+
"unsequenced read of a variable",
309+
self.write_expr.span,
310+
"whether read occurs before this write depends on evaluation order"
311+
);
312+
}
309313
}
310314
}
311315
}

clippy_lints/src/format.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,9 @@ impl LateLintPass for Pass {
4545
// `format!("{}", foo)` expansion
4646
ExprCall(ref fun, ref args) => {
4747
if_let_chain!{[
48-
let ExprPath(..) = fun.node,
48+
let ExprPath(ref qpath) = fun.node,
4949
args.len() == 2,
50-
let Some(fun) = resolve_node(cx, fun.id),
51-
match_def_path(cx, fun.def_id(), &paths::FMT_ARGUMENTS_NEWV1),
50+
match_def_path(cx, resolve_node(cx, qpath, fun.id).def_id(), &paths::FMT_ARGUMENTS_NEWV1),
5251
// ensure the format string is `"{..}"` with only one argument and no text
5352
check_static_str(cx, &args[0]),
5453
// ensure the format argument is `{}` ie. Display with no fancy option
@@ -129,9 +128,8 @@ fn check_arg_is_display(cx: &LateContext, expr: &Expr) -> bool {
129128
exprs.len() == 1,
130129
let ExprCall(_, ref args) = exprs[0].node,
131130
args.len() == 2,
132-
let ExprPath(None, _) = args[1].node,
133-
let Some(fun) = resolve_node(cx, args[1].id),
134-
match_def_path(cx, fun.def_id(), &paths::DISPLAY_FMT_METHOD),
131+
let ExprPath(ref qpath) = args[1].node,
132+
match_def_path(cx, resolve_node(cx, qpath, args[1].id).def_id(), &paths::DISPLAY_FMT_METHOD),
135133
], {
136134
let ty = walk_ptrs_ty(cx.tcx.tables().pat_ty(&pat[0]));
137135

clippy_lints/src/functions.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ impl Functions {
138138
}
139139
}
140140

141-
fn raw_ptr_arg(cx: &LateContext, arg: &hir::Arg) -> Option<hir::def_id::DefId> {
142-
if let (&hir::PatKind::Binding(_, _, _), &hir::TyPtr(_)) = (&arg.pat.node, &arg.ty.node) {
143-
cx.tcx.def_map.borrow().get(&arg.pat.id).map(|pr| pr.full_def().def_id())
141+
fn raw_ptr_arg(_cx: &LateContext, arg: &hir::Arg) -> Option<hir::def_id::DefId> {
142+
if let (&hir::PatKind::Binding(_, def_id, _, _), &hir::TyPtr(_)) = (&arg.pat.node, &arg.ty.node) {
143+
Some(def_id)
144144
} else {
145145
None
146146
}
@@ -183,8 +183,9 @@ impl<'a, 'tcx, 'v> hir::intravisit::Visitor<'v> for DerefVisitor<'a, 'tcx> {
183183

184184
impl<'a, 'tcx: 'a> DerefVisitor<'a, 'tcx> {
185185
fn check_arg(&self, ptr: &hir::Expr) {
186-
if let Some(def) = self.cx.tcx.def_map.borrow().get(&ptr.id) {
187-
if self.ptrs.contains(&def.full_def().def_id()) {
186+
if let hir::ExprPath(ref qpath) = ptr.node {
187+
let def = self.cx.tcx.tables().qpath_def(qpath, ptr.id);
188+
if self.ptrs.contains(&def.def_id()) {
188189
span_lint(self.cx,
189190
NOT_UNSAFE_PTR_ARG_DEREF,
190191
ptr.span,

clippy_lints/src/if_let_redundant_pattern_matching.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl LateLintPass for Pass {
6363
}
6464
}
6565

66-
PatKind::Path(_, ref path) if match_path(path, &paths::OPTION_NONE) => {
66+
PatKind::Path(ref path) if match_path(path, &paths::OPTION_NONE) => {
6767
"is_none()"
6868
}
6969

0 commit comments

Comments
 (0)