Skip to content

Commit ea0227f

Browse files
authored
Merge pull request #1373 from Manishearth/rustup
WIP: rustup
2 parents f9fe50d + 4fcefe2 commit ea0227f

Some content is hidden

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

80 files changed

+1038
-797
lines changed

CHANGELOG.md

+3
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-15
5+
* Update to *rustc 1.15.0-nightly (8f02c429a 2016-12-15)*
6+
47
## 0.0.103 — 2016-11-25
58
* Update to *rustc 1.15.0-nightly (d5814b03e 2016-11-23)*
69

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy"
3-
version = "0.0.103"
3+
version = "0.0.104"
44
authors = [
55
"Manish Goregaokar <[email protected]>",
66
"Andre Bogus <[email protected]>",
@@ -25,7 +25,7 @@ test = false
2525

2626
[dependencies]
2727
# begin automatic update
28-
clippy_lints = { version = "0.0.103", path = "clippy_lints" }
28+
clippy_lints = { version = "0.0.104", path = "clippy_lints" }
2929
# end automatic update
3030

3131
[dev-dependencies]

clippy_lints/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "clippy_lints"
33
# begin automatic update
4-
version = "0.0.103"
4+
version = "0.0.104"
55
# end automatic update
66
authors = [
77
"Manish Goregaokar <[email protected]>",

clippy_lints/src/approx_const.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ impl LintPass for Pass {
5959
}
6060
}
6161

62-
impl LateLintPass for Pass {
63-
fn check_expr(&mut self, cx: &LateContext, e: &Expr) {
62+
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
63+
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
6464
if let ExprLit(ref lit) = e.node {
6565
check_lit(cx, lit, e);
6666
}

clippy_lints/src/arithmetic.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ impl LintPass for Arithmetic {
4747
}
4848
}
4949

50-
impl LateLintPass for Arithmetic {
51-
fn check_expr(&mut self, cx: &LateContext, expr: &hir::Expr) {
50+
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Arithmetic {
51+
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
5252
if self.span.is_some() {
5353
return;
5454
}
@@ -82,7 +82,7 @@ impl LateLintPass for Arithmetic {
8282
}
8383
}
8484

85-
fn check_expr_post(&mut self, _: &LateContext, expr: &hir::Expr) {
85+
fn check_expr_post(&mut self, _: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
8686
if Some(expr.span) == self.span {
8787
self.span = None;
8888
}

clippy_lints/src/array_indexing.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ impl LintPass for ArrayIndexing {
5555
}
5656
}
5757

58-
impl LateLintPass for ArrayIndexing {
59-
fn check_expr(&mut self, cx: &LateContext, e: &hir::Expr) {
58+
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ArrayIndexing {
59+
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx hir::Expr) {
6060
if let hir::ExprIndex(ref array, ref index) = e.node {
6161
// Array with known size can be checked statically
6262
let ty = cx.tcx.tables().expr_ty(array);

clippy_lints/src/assign_ops.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ impl LintPass for AssignOps {
6666
}
6767
}
6868

69-
impl LateLintPass for AssignOps {
70-
fn check_expr(&mut self, cx: &LateContext, expr: &hir::Expr) {
69+
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
70+
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
7171
match expr.node {
7272
hir::ExprAssignOp(op, ref lhs, ref rhs) => {
7373
span_lint_and_then(cx, ASSIGN_OPS, expr.span, "assign operation detected", |db| {

clippy_lints/src/attrs.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ impl LintPass for AttrPass {
8181
}
8282
}
8383

84-
impl LateLintPass for AttrPass {
85-
fn check_attribute(&mut self, cx: &LateContext, attr: &Attribute) {
84+
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass {
85+
fn check_attribute(&mut self, cx: &LateContext<'a, 'tcx>, attr: &'tcx Attribute) {
8686
if let MetaItemKind::List(ref items) = attr.value.node {
8787
if items.is_empty() || attr.name() != "deprecated" {
8888
return;
@@ -99,21 +99,21 @@ impl LateLintPass for AttrPass {
9999
}
100100
}
101101

102-
fn check_item(&mut self, cx: &LateContext, item: &Item) {
102+
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
103103
if is_relevant_item(cx, item) {
104104
check_attrs(cx, item.span, &item.name, &item.attrs)
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
}
@@ -138,38 +138,38 @@ impl LateLintPass for AttrPass {
138138
}
139139
}
140140

141-
fn check_impl_item(&mut self, cx: &LateContext, item: &ImplItem) {
141+
fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx ImplItem) {
142142
if is_relevant_impl(cx, item) {
143143
check_attrs(cx, item.span, &item.name, &item.attrs)
144144
}
145145
}
146146

147-
fn check_trait_item(&mut self, cx: &LateContext, item: &TraitItem) {
147+
fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx TraitItem) {
148148
if is_relevant_trait(cx, item) {
149149
check_attrs(cx, item.span, &item.name, &item.attrs)
150150
}
151151
}
152152
}
153153

154154
fn is_relevant_item(cx: &LateContext, item: &Item) -> bool {
155-
if let ItemFn(_, _, _, _, _, ref expr) = item.node {
156-
is_relevant_expr(cx, expr)
155+
if let ItemFn(_, _, _, _, _, eid) = item.node {
156+
is_relevant_expr(cx, cx.tcx.map.expr(eid))
157157
} else {
158158
false
159159
}
160160
}
161161

162162
fn is_relevant_impl(cx: &LateContext, item: &ImplItem) -> bool {
163163
match item.node {
164-
ImplItemKind::Method(_, ref expr) => is_relevant_expr(cx, expr),
164+
ImplItemKind::Method(_, eid) => is_relevant_expr(cx, cx.tcx.map.expr(eid)),
165165
_ => false,
166166
}
167167
}
168168

169169
fn is_relevant_trait(cx: &LateContext, item: &TraitItem) -> bool {
170170
match item.node {
171171
MethodTraitItem(_, None) => true,
172-
MethodTraitItem(_, Some(ref expr)) => is_relevant_expr(cx, expr),
172+
MethodTraitItem(_, Some(eid)) => is_relevant_expr(cx, cx.tcx.map.expr(eid)),
173173
_ => false,
174174
}
175175
}
@@ -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

+9-14
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;
@@ -79,8 +79,8 @@ impl LintPass for BitMask {
7979
}
8080
}
8181

82-
impl LateLintPass for BitMask {
83-
fn check_expr(&mut self, cx: &LateContext, e: &Expr) {
82+
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BitMask {
83+
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
8484
if let ExprBinary(ref cmp, ref left, ref right) = e.node {
8585
if cmp.node.is_comparison() {
8686
if let Some(cmp_opt) = fetch_int_literal(cx, right) {
@@ -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

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ impl LintPass for BlackListedName {
3737
}
3838
}
3939

40-
impl LateLintPass for BlackListedName {
41-
fn check_pat(&mut self, cx: &LateContext, pat: &Pat) {
42-
if let PatKind::Binding(_, ref ident, _) = pat.node {
40+
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlackListedName {
41+
fn check_pat(&mut self, cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat) {
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/block_in_if_condition.rs

+14-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc::lint::{LateLintPass, LateContext, LintArray, LintPass};
22
use rustc::hir::*;
3-
use rustc::hir::intravisit::{Visitor, walk_expr};
3+
use rustc::hir::intravisit::{Visitor, walk_expr, NestedVisitorMap};
44
use utils::*;
55

66
/// **What it does:** Checks for `if` conditions that use blocks to contain an
@@ -49,28 +49,33 @@ impl LintPass for BlockInIfCondition {
4949
}
5050
}
5151

52-
struct ExVisitor<'v> {
53-
found_block: Option<&'v Expr>,
52+
struct ExVisitor<'a, 'tcx: 'a> {
53+
found_block: Option<&'tcx Expr>,
54+
cx: &'a LateContext<'a, 'tcx>,
5455
}
5556

56-
impl<'v> Visitor<'v> for ExVisitor<'v> {
57-
fn visit_expr(&mut self, expr: &'v Expr) {
58-
if let ExprClosure(_, _, ref expr, _) = expr.node {
57+
impl<'a, 'tcx: 'a> Visitor<'tcx> for ExVisitor<'a, 'tcx> {
58+
fn visit_expr(&mut self, expr: &'tcx Expr) {
59+
if let ExprClosure(_, _, eid, _) = expr.node {
60+
let expr = self.cx.tcx.map.expr(eid);
5961
if matches!(expr.node, ExprBlock(_)) {
6062
self.found_block = Some(expr);
6163
return;
6264
}
6365
}
6466
walk_expr(self, expr);
6567
}
68+
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
69+
NestedVisitorMap::All(&self.cx.tcx.map)
70+
}
6671
}
6772

6873
const BRACED_EXPR_MESSAGE: &'static str = "omit braces around single expression condition";
6974
const COMPLEX_BLOCK_MESSAGE: &'static str = "in an 'if' condition, avoid complex blocks or closures with blocks; \
7075
instead, move the block or closure higher and bind it with a 'let'";
7176

72-
impl LateLintPass for BlockInIfCondition {
73-
fn check_expr(&mut self, cx: &LateContext, expr: &Expr) {
77+
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlockInIfCondition {
78+
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
7479
if let ExprIf(ref check, ref then, _) = expr.node {
7580
if let ExprBlock(ref block) = check.node {
7681
if block.rules == DefaultBlock {
@@ -105,7 +110,7 @@ impl LateLintPass for BlockInIfCondition {
105110
}
106111
}
107112
} else {
108-
let mut visitor = ExVisitor { found_block: None };
113+
let mut visitor = ExVisitor { found_block: None, cx: cx };
109114
walk_expr(&mut visitor, check);
110115
if let Some(block) = visitor.found_block {
111116
span_lint(cx, BLOCK_IN_IF_CONDITION_STMT, block.span, COMPLEX_BLOCK_MESSAGE);

clippy_lints/src/booleans.rs

+18-13
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,15 @@ impl LintPass for NonminimalBool {
5353
}
5454
}
5555

56-
impl LateLintPass for NonminimalBool {
57-
fn check_item(&mut self, cx: &LateContext, item: &Item) {
58-
NonminimalBoolVisitor(cx).visit_item(item)
56+
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonminimalBool {
57+
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
58+
NonminimalBoolVisitor { cx: cx }.visit_item(item)
5959
}
6060
}
6161

62-
struct NonminimalBoolVisitor<'a, 'tcx: 'a>(&'a LateContext<'a, 'tcx>);
62+
struct NonminimalBoolVisitor<'a, 'tcx: 'a> {
63+
cx: &'a LateContext<'a, 'tcx>,
64+
}
6365

6466
use quine_mc_cluskey::Bool;
6567
struct Hir2Qmm<'a, 'tcx: 'a, 'v> {
@@ -308,7 +310,7 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
308310
fn bool_expr(&self, e: &Expr) {
309311
let mut h2q = Hir2Qmm {
310312
terminals: Vec::new(),
311-
cx: self.0,
313+
cx: self.cx,
312314
};
313315
if let Ok(expr) = h2q.run(e) {
314316

@@ -343,7 +345,7 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
343345
continue 'simplified;
344346
}
345347
if stats.terminals[i] != 0 && simplified_stats.terminals[i] == 0 {
346-
span_lint_and_then(self.0,
348+
span_lint_and_then(self.cx,
347349
LOGIC_BUG,
348350
e.span,
349351
"this boolean expression contains a logic bug",
@@ -353,7 +355,7 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
353355
outer expression");
354356
db.span_suggestion(e.span,
355357
"it would look like the following",
356-
suggest(self.0, suggestion, &h2q.terminals));
358+
suggest(self.cx, suggestion, &h2q.terminals));
357359
});
358360
// don't also lint `NONMINIMAL_BOOL`
359361
return;
@@ -370,29 +372,29 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
370372
}
371373
}
372374
if !improvements.is_empty() {
373-
span_lint_and_then(self.0,
375+
span_lint_and_then(self.cx,
374376
NONMINIMAL_BOOL,
375377
e.span,
376378
"this boolean expression can be simplified",
377379
|db| {
378380
for suggestion in &improvements {
379-
db.span_suggestion(e.span, "try", suggest(self.0, suggestion, &h2q.terminals));
381+
db.span_suggestion(e.span, "try", suggest(self.cx, suggestion, &h2q.terminals));
380382
}
381383
});
382384
}
383385
}
384386
}
385387
}
386388

387-
impl<'a, 'v, 'tcx> Visitor<'v> for NonminimalBoolVisitor<'a, 'tcx> {
388-
fn visit_expr(&mut self, e: &'v Expr) {
389-
if in_macro(self.0, e.span) {
389+
impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> {
390+
fn visit_expr(&mut self, e: &'tcx Expr) {
391+
if in_macro(self.cx, e.span) {
390392
return;
391393
}
392394
match e.node {
393395
ExprBinary(binop, _, _) if binop.node == BiOr || binop.node == BiAnd => self.bool_expr(e),
394396
ExprUnary(UnNot, ref inner) => {
395-
if self.0.tcx.tables.borrow().node_types[&inner.id].is_bool() {
397+
if self.cx.tcx.tables.borrow().node_types[&inner.id].is_bool() {
396398
self.bool_expr(e);
397399
} else {
398400
walk_expr(self, e);
@@ -401,4 +403,7 @@ impl<'a, 'v, 'tcx> Visitor<'v> for NonminimalBoolVisitor<'a, 'tcx> {
401403
_ => walk_expr(self, e),
402404
}
403405
}
406+
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
407+
NestedVisitorMap::All(&self.cx.tcx.map)
408+
}
404409
}

0 commit comments

Comments
 (0)