Skip to content

Commit b127ad2

Browse files
committed
Rustup
1 parent 36cd745 commit b127ad2

19 files changed

+245
-245
lines changed

Cargo.lock

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

clippy_lints/src/attrs.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc::ty::{self, TyCtxt};
77
use semver::Version;
88
use syntax::ast::{Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem, NestedMetaItemKind};
99
use syntax::codemap::Span;
10-
use utils::{in_macro, match_def_path, paths, snippet_opt, span_lint, span_lint_and_then};
10+
use utils::{in_macro, match_def_path, paths, snippet_opt, span_lint, span_lint_and_then, opt_def_id};
1111

1212
/// **What it does:** Checks for items annotated with `#[inline(always)]`,
1313
/// unless the annotated function is empty or simply panics.
@@ -211,8 +211,11 @@ fn is_relevant_expr(tcx: TyCtxt, tables: &ty::TypeckTables, expr: &Expr) -> bool
211211
ExprRet(Some(ref e)) => is_relevant_expr(tcx, tables, e),
212212
ExprRet(None) | ExprBreak(_, None) => false,
213213
ExprCall(ref path_expr, _) => if let ExprPath(ref qpath) = path_expr.node {
214-
let fun_id = tables.qpath_def(qpath, path_expr.hir_id).def_id();
215-
!match_def_path(tcx, fun_id, &paths::BEGIN_PANIC)
214+
if let Some(fun_id) = opt_def_id(tables.qpath_def(qpath, path_expr.hir_id)) {
215+
!match_def_path(tcx, fun_id, &paths::BEGIN_PANIC)
216+
} else {
217+
true
218+
}
216219
} else {
217220
true
218221
},

clippy_lints/src/drop_forget_ref.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc::lint::*;
22
use rustc::ty;
33
use rustc::hir::*;
4-
use utils::{is_copy, match_def_path, paths, span_note_and_lint};
4+
use utils::{is_copy, match_def_path, paths, span_note_and_lint, opt_def_id};
55

66
/// **What it does:** Checks for calls to `std::mem::drop` with a reference
77
/// instead of an owned value.
@@ -119,8 +119,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
119119
let ExprCall(ref path, ref args) = expr.node,
120120
let ExprPath(ref qpath) = path.node,
121121
args.len() == 1,
122+
let Some(def_id) = opt_def_id(cx.tables.qpath_def(qpath, path.hir_id)),
122123
], {
123-
let def_id = cx.tables.qpath_def(qpath, path.hir_id).def_id();
124124
let lint;
125125
let msg;
126126
let arg = &args[0];

clippy_lints/src/eval_order_dependence.rs

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use rustc::hir::def_id::DefId;
21
use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
32
use rustc::hir::*;
43
use rustc::ty;
54
use rustc::lint::*;
5+
use syntax::ast;
66
use utils::{get_parent_expr, span_lint, span_note_and_lint};
77

88
/// **What it does:** Checks for a read and a write to the same variable where
@@ -65,14 +65,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EvalOrderDependence {
6565
ExprAssign(ref lhs, _) | ExprAssignOp(_, ref lhs, _) => if let ExprPath(ref qpath) = lhs.node {
6666
if let QPath::Resolved(_, ref path) = *qpath {
6767
if path.segments.len() == 1 {
68-
let var = cx.tables.qpath_def(qpath, lhs.hir_id).def_id();
69-
let mut visitor = ReadVisitor {
70-
cx: cx,
71-
var: var,
72-
write_expr: expr,
73-
last_expr: expr,
74-
};
75-
check_for_unsequenced_reads(&mut visitor);
68+
if let def::Def::Local(var) = cx.tables.qpath_def(qpath, lhs.hir_id) {
69+
let mut visitor = ReadVisitor {
70+
cx: cx,
71+
var: var,
72+
write_expr: expr,
73+
last_expr: expr,
74+
};
75+
check_for_unsequenced_reads(&mut visitor);
76+
}
7677
}
7778
}
7879
},
@@ -280,7 +281,7 @@ fn check_stmt<'a, 'tcx>(vis: &mut ReadVisitor<'a, 'tcx>, stmt: &'tcx Stmt) -> St
280281
struct ReadVisitor<'a, 'tcx: 'a> {
281282
cx: &'a LateContext<'a, 'tcx>,
282283
/// The id of the variable we're looking for.
283-
var: DefId,
284+
var: ast::NodeId,
284285
/// The expressions where the write to the variable occurred (for reporting
285286
/// in the lint).
286287
write_expr: &'tcx Expr,
@@ -297,22 +298,23 @@ impl<'a, 'tcx> Visitor<'tcx> for ReadVisitor<'a, 'tcx> {
297298

298299
match expr.node {
299300
ExprPath(ref qpath) => {
300-
if let QPath::Resolved(None, ref path) = *qpath {
301-
if path.segments.len() == 1 && self.cx.tables.qpath_def(qpath, expr.hir_id).def_id() == self.var {
302-
if is_in_assignment_position(self.cx, expr) {
303-
// This is a write, not a read.
304-
} else {
305-
span_note_and_lint(
306-
self.cx,
307-
EVAL_ORDER_DEPENDENCE,
308-
expr.span,
309-
"unsequenced read of a variable",
310-
self.write_expr.span,
311-
"whether read occurs before this write depends on evaluation order"
312-
);
313-
}
314-
}
315-
}
301+
if_let_chain! {[
302+
let QPath::Resolved(None, ref path) = *qpath,
303+
path.segments.len() == 1,
304+
let def::Def::Local(local_id) = self.cx.tables.qpath_def(qpath, expr.hir_id),
305+
local_id == self.var,
306+
// Check that this is a read, not a write.
307+
!is_in_assignment_position(self.cx, expr),
308+
], {
309+
span_note_and_lint(
310+
self.cx,
311+
EVAL_ORDER_DEPENDENCE,
312+
expr.span,
313+
"unsequenced read of a variable",
314+
self.write_expr.span,
315+
"whether read occurs before this write depends on evaluation order"
316+
);
317+
}}
316318
}
317319
// We're about to descend a closure. Since we don't know when (or
318320
// if) the closure will be evaluated, any reads in it might not

clippy_lints/src/format.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc::ty;
55
use syntax::ast::LitKind;
66
use syntax::symbol::InternedString;
77
use utils::paths;
8-
use utils::{is_expn_of, match_def_path, match_type, resolve_node, span_lint, walk_ptrs_ty};
8+
use utils::{is_expn_of, match_def_path, match_type, resolve_node, span_lint, walk_ptrs_ty, opt_def_id};
99

1010
/// **What it does:** Checks for the use of `format!("string literal with no
1111
/// argument")` and `format!("{}", foo)` where `foo` is a string.
@@ -47,7 +47,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
4747
if_let_chain!{[
4848
let ExprPath(ref qpath) = fun.node,
4949
args.len() == 2,
50-
match_def_path(cx.tcx, resolve_node(cx, qpath, fun.hir_id).def_id(), &paths::FMT_ARGUMENTS_NEWV1),
50+
let Some(fun_def_id) = opt_def_id(resolve_node(cx, qpath, fun.hir_id)),
51+
match_def_path(cx.tcx, fun_def_id, &paths::FMT_ARGUMENTS_NEWV1),
5152
// ensure the format string is `"{..}"` with only one argument and no text
5253
check_static_str(cx, &args[0]),
5354
// ensure the format argument is `{}` ie. Display with no fancy option
@@ -128,7 +129,8 @@ fn check_arg_is_display(cx: &LateContext, expr: &Expr) -> bool {
128129
let ExprCall(_, ref args) = exprs[0].node,
129130
args.len() == 2,
130131
let ExprPath(ref qpath) = args[1].node,
131-
match_def_path(cx.tcx, resolve_node(cx, qpath, args[1].hir_id).def_id(), &paths::DISPLAY_FMT_METHOD),
132+
let Some(fun_def_id) = opt_def_id(resolve_node(cx, qpath, args[1].hir_id)),
133+
match_def_path(cx.tcx, fun_def_id, &paths::DISPLAY_FMT_METHOD),
132134
], {
133135
let ty = walk_ptrs_ty(cx.tables.pat_ty(&pat[0]));
134136

clippy_lints/src/functions.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use rustc::hir::intravisit;
22
use rustc::hir;
33
use rustc::lint::*;
44
use rustc::ty;
5+
use rustc::hir::def::Def;
56
use std::collections::HashSet;
67
use syntax::ast;
78
use syntax::abi::Abi;
@@ -166,17 +167,17 @@ impl<'a, 'tcx> Functions {
166167
}
167168
}
168169

169-
fn raw_ptr_arg(arg: &hir::Arg, ty: &hir::Ty) -> Option<hir::def_id::DefId> {
170-
if let (&hir::PatKind::Binding(_, def_id, _, _), &hir::TyPtr(_)) = (&arg.pat.node, &ty.node) {
171-
Some(def_id)
170+
fn raw_ptr_arg(arg: &hir::Arg, ty: &hir::Ty) -> Option<ast::NodeId> {
171+
if let (&hir::PatKind::Binding(_, id, _, _), &hir::TyPtr(_)) = (&arg.pat.node, &ty.node) {
172+
Some(id)
172173
} else {
173174
None
174175
}
175176
}
176177

177178
struct DerefVisitor<'a, 'tcx: 'a> {
178179
cx: &'a LateContext<'a, 'tcx>,
179-
ptrs: HashSet<hir::def_id::DefId>,
180+
ptrs: HashSet<ast::NodeId>,
180181
tables: &'a ty::TypeckTables<'tcx>,
181182
}
182183

@@ -216,14 +217,15 @@ impl<'a, 'tcx> hir::intravisit::Visitor<'tcx> for DerefVisitor<'a, 'tcx> {
216217
impl<'a, 'tcx: 'a> DerefVisitor<'a, 'tcx> {
217218
fn check_arg(&self, ptr: &hir::Expr) {
218219
if let hir::ExprPath(ref qpath) = ptr.node {
219-
let def = self.cx.tables.qpath_def(qpath, ptr.hir_id);
220-
if self.ptrs.contains(&def.def_id()) {
221-
span_lint(
222-
self.cx,
223-
NOT_UNSAFE_PTR_ARG_DEREF,
224-
ptr.span,
225-
"this public function dereferences a raw pointer but is not marked `unsafe`",
226-
);
220+
if let Def::Local(id) = self.cx.tables.qpath_def(qpath, ptr.hir_id) {
221+
if self.ptrs.contains(&id) {
222+
span_lint(
223+
self.cx,
224+
NOT_UNSAFE_PTR_ARG_DEREF,
225+
ptr.span,
226+
"this public function dereferences a raw pointer but is not marked `unsafe`",
227+
);
228+
}
227229
}
228230
}
229231
}

clippy_lints/src/let_if_seq.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use rustc::lint::*;
22
use rustc::hir;
33
use rustc::hir::BindingAnnotation;
4+
use rustc::hir::def::Def;
5+
use syntax::ast;
46
use utils::{snippet, span_lint_and_then};
57

68
/// **What it does:** Checks for variable declarations immediately followed by a
@@ -65,19 +67,19 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetIfSeq {
6567
let Some(expr) = it.peek(),
6668
let hir::StmtDecl(ref decl, _) = stmt.node,
6769
let hir::DeclLocal(ref decl) = decl.node,
68-
let hir::PatKind::Binding(mode, def_id, ref name, None) = decl.pat.node,
70+
let hir::PatKind::Binding(mode, canonical_id, ref name, None) = decl.pat.node,
6971
let hir::StmtExpr(ref if_, _) = expr.node,
7072
let hir::ExprIf(ref cond, ref then, ref else_) = if_.node,
71-
!used_in_expr(cx, def_id, cond),
73+
!used_in_expr(cx, canonical_id, cond),
7274
let hir::ExprBlock(ref then) = then.node,
73-
let Some(value) = check_assign(cx, def_id, &*then),
74-
!used_in_expr(cx, def_id, value),
75+
let Some(value) = check_assign(cx, canonical_id, &*then),
76+
!used_in_expr(cx, canonical_id, value),
7577
], {
7678
let span = stmt.span.to(if_.span);
7779

7880
let (default_multi_stmts, default) = if let Some(ref else_) = *else_ {
7981
if let hir::ExprBlock(ref else_) = else_.node {
80-
if let Some(default) = check_assign(cx, def_id, else_) {
82+
if let Some(default) = check_assign(cx, canonical_id, else_) {
8183
(else_.stmts.len() > 1, default)
8284
} else if let Some(ref default) = decl.init {
8385
(true, &**default)
@@ -130,15 +132,16 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetIfSeq {
130132

131133
struct UsedVisitor<'a, 'tcx: 'a> {
132134
cx: &'a LateContext<'a, 'tcx>,
133-
id: hir::def_id::DefId,
135+
id: ast::NodeId,
134136
used: bool,
135137
}
136138

137139
impl<'a, 'tcx> hir::intravisit::Visitor<'tcx> for UsedVisitor<'a, 'tcx> {
138140
fn visit_expr(&mut self, expr: &'tcx hir::Expr) {
139141
if_let_chain! {[
140142
let hir::ExprPath(ref qpath) = expr.node,
141-
self.id == self.cx.tables.qpath_def(qpath, expr.hir_id).def_id(),
143+
let Def::Local(local_id) = self.cx.tables.qpath_def(qpath, expr.hir_id),
144+
self.id == local_id,
142145
], {
143146
self.used = true;
144147
return;
@@ -152,7 +155,7 @@ impl<'a, 'tcx> hir::intravisit::Visitor<'tcx> for UsedVisitor<'a, 'tcx> {
152155

153156
fn check_assign<'a, 'tcx>(
154157
cx: &LateContext<'a, 'tcx>,
155-
decl: hir::def_id::DefId,
158+
decl: ast::NodeId,
156159
block: &'tcx hir::Block,
157160
) -> Option<&'tcx hir::Expr> {
158161
if_let_chain! {[
@@ -161,7 +164,8 @@ fn check_assign<'a, 'tcx>(
161164
let hir::StmtSemi(ref expr, _) = expr.node,
162165
let hir::ExprAssign(ref var, ref value) = expr.node,
163166
let hir::ExprPath(ref qpath) = var.node,
164-
decl == cx.tables.qpath_def(qpath, var.hir_id).def_id(),
167+
let Def::Local(local_id) = cx.tables.qpath_def(qpath, var.hir_id),
168+
decl == local_id,
165169
], {
166170
let mut v = UsedVisitor {
167171
cx: cx,
@@ -183,7 +187,7 @@ fn check_assign<'a, 'tcx>(
183187
None
184188
}
185189

186-
fn used_in_expr<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, id: hir::def_id::DefId, expr: &'tcx hir::Expr) -> bool {
190+
fn used_in_expr<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, id: ast::NodeId, expr: &'tcx hir::Expr) -> bool {
187191
let mut v = UsedVisitor {
188192
cx: cx,
189193
id: id,

0 commit comments

Comments
 (0)