Skip to content

Commit f27aaac

Browse files
authored
Merge pull request #2923 from rust-lang-nursery/kind
Rustup to 1ecf692
2 parents 196ffa8 + 3246a1f commit f27aaac

File tree

109 files changed

+1307
-1267
lines changed

Some content is hidden

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

109 files changed

+1307
-1267
lines changed

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ a `.stdout` file with the generated code:
9393
// ./tests/ui/my_lint.stdout
9494

9595
if_chain! {
96-
if let Expr_::ExprArray(ref elements) = stmt.node;
96+
if let ExprKind::Array(ref elements) = stmt.node;
9797
if elements.len() == 1;
98-
if let Expr_::ExprLit(ref lit) = elements[0].node;
98+
if let ExprKind::Lit(ref lit) = elements[0].node;
9999
if let LitKind::Int(7, _) = lit.node;
100100
then {
101101
// report your lint here
@@ -179,7 +179,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
179179
```
180180

181181
The [`rustc_plugin::PluginRegistry`][plugin_registry] provides two methods to register lints: [register_early_lint_pass][reg_early_lint_pass] and [register_late_lint_pass][reg_late_lint_pass].
182-
Both take an object that implements an [`EarlyLintPass`][early_lint_pass] or [`LateLintPass`][late_lint_pass] respectively. This is done in every single lint.
182+
Both take an object that implements an [`EarlyLintPass`][early_lint_pass] or [`LateLintPass`][late_lint_pass] respectively. This is done in every single lint.
183183
It's worth noting that the majority of `clippy_lints/src/lib.rs` is autogenerated by `util/update_lints.py` and you don't have to add anything by hand. When you are writing your own lint, you can use that script to save you some time.
184184

185185
```rust

clippy_lints/src/approx_const.rs

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

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

clippy_lints/src/arithmetic.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,21 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Arithmetic {
5555
return;
5656
}
5757
match expr.node {
58-
hir::ExprBinary(ref op, ref l, ref r) => {
58+
hir::ExprKind::Binary(ref op, ref l, ref r) => {
5959
match op.node {
60-
hir::BiAnd
61-
| hir::BiOr
62-
| hir::BiBitAnd
63-
| hir::BiBitOr
64-
| hir::BiBitXor
65-
| hir::BiShl
66-
| hir::BiShr
67-
| hir::BiEq
68-
| hir::BiLt
69-
| hir::BiLe
70-
| hir::BiNe
71-
| hir::BiGe
72-
| hir::BiGt => return,
60+
hir::BinOpKind::And
61+
| hir::BinOpKind::Or
62+
| hir::BinOpKind::BitAnd
63+
| hir::BinOpKind::BitOr
64+
| hir::BinOpKind::BitXor
65+
| hir::BinOpKind::Shl
66+
| hir::BinOpKind::Shr
67+
| hir::BinOpKind::Eq
68+
| hir::BinOpKind::Lt
69+
| hir::BinOpKind::Le
70+
| hir::BinOpKind::Ne
71+
| hir::BinOpKind::Ge
72+
| hir::BinOpKind::Gt => return,
7373
_ => (),
7474
}
7575
let (l_ty, r_ty) = (cx.tables.expr_ty(l), cx.tables.expr_ty(r));
@@ -81,7 +81,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Arithmetic {
8181
self.span = Some(expr.span);
8282
}
8383
},
84-
hir::ExprUnary(hir::UnOp::UnNeg, ref arg) => {
84+
hir::ExprKind::Unary(hir::UnOp::UnNeg, ref arg) => {
8585
let ty = cx.tables.expr_ty(arg);
8686
if ty.is_integral() {
8787
span_lint(cx, INTEGER_ARITHMETIC, expr.span, "integer arithmetic detected");

clippy_lints/src/assign_ops.rs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl LintPass for AssignOps {
7676
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
7777
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
7878
match expr.node {
79-
hir::ExprAssignOp(op, ref lhs, ref rhs) => {
79+
hir::ExprKind::AssignOp(op, ref lhs, ref rhs) => {
8080
span_lint_and_then(cx, ASSIGN_OPS, expr.span, "assign operation detected", |db| {
8181
let lhs = &sugg::Sugg::hir(cx, lhs, "..");
8282
let rhs = &sugg::Sugg::hir(cx, rhs, "..");
@@ -87,7 +87,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
8787
format!("{} = {}", lhs, sugg::make_binop(higher::binop(op.node), lhs, rhs)),
8888
);
8989
});
90-
if let hir::ExprBinary(binop, ref l, ref r) = rhs.node {
90+
if let hir::ExprKind::Binary(binop, ref l, ref r) = rhs.node {
9191
if op.node == binop.node {
9292
let lint = |assignee: &hir::Expr, rhs_other: &hir::Expr| {
9393
span_lint_and_then(
@@ -131,8 +131,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
131131
}
132132
}
133133
},
134-
hir::ExprAssign(ref assignee, ref e) => {
135-
if let hir::ExprBinary(op, ref l, ref r) = e.node {
134+
hir::ExprKind::Assign(ref assignee, ref e) => {
135+
if let hir::ExprKind::Binary(op, ref l, ref r) = e.node {
136136
#[allow(cyclomatic_complexity)]
137137
let lint = |assignee: &hir::Expr, rhs: &hir::Expr| {
138138
let ty = cx.tables.expr_ty(assignee);
@@ -142,9 +142,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
142142
$cx:expr,
143143
$ty:expr,
144144
$rty:expr,
145-
$($trait_name:ident:$full_trait_name:ident),+) => {
145+
$($trait_name:ident),+) => {
146146
match $op {
147-
$(hir::$full_trait_name => {
147+
$(hir::BinOpKind::$trait_name => {
148148
let [krate, module] = crate::utils::paths::OPS_MODULE;
149149
let path = [krate, module, concat!(stringify!($trait_name), "Assign")];
150150
let trait_id = if let Some(trait_id) = get_trait_def_id($cx, &path) {
@@ -159,7 +159,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
159159
if_chain! {
160160
if parent_impl != ast::CRATE_NODE_ID;
161161
if let hir::map::Node::NodeItem(item) = cx.tcx.hir.get(parent_impl);
162-
if let hir::Item_::ItemImpl(_, _, _, _, Some(ref trait_ref), _, _) =
162+
if let hir::ItemKind::Impl(_, _, _, _, Some(ref trait_ref), _, _) =
163163
item.node;
164164
if trait_ref.path.def.def_id() == trait_id;
165165
then { return; }
@@ -175,18 +175,18 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
175175
cx,
176176
ty,
177177
rty.into(),
178-
Add: BiAdd,
179-
Sub: BiSub,
180-
Mul: BiMul,
181-
Div: BiDiv,
182-
Rem: BiRem,
183-
And: BiAnd,
184-
Or: BiOr,
185-
BitAnd: BiBitAnd,
186-
BitOr: BiBitOr,
187-
BitXor: BiBitXor,
188-
Shr: BiShr,
189-
Shl: BiShl
178+
Add,
179+
Sub,
180+
Mul,
181+
Div,
182+
Rem,
183+
And,
184+
Or,
185+
BitAnd,
186+
BitOr,
187+
BitXor,
188+
Shr,
189+
Shl
190190
) {
191191
span_lint_and_then(
192192
cx,
@@ -224,13 +224,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
224224
// a = b commutative_op a
225225
if SpanlessEq::new(cx).ignore_fn().eq_expr(assignee, r) {
226226
match op.node {
227-
hir::BiAdd
228-
| hir::BiMul
229-
| hir::BiAnd
230-
| hir::BiOr
231-
| hir::BiBitXor
232-
| hir::BiBitAnd
233-
| hir::BiBitOr => {
227+
hir::BinOpKind::Add
228+
| hir::BinOpKind::Mul
229+
| hir::BinOpKind::And
230+
| hir::BinOpKind::Or
231+
| hir::BinOpKind::BitXor
232+
| hir::BinOpKind::BitAnd
233+
| hir::BinOpKind::BitOr => {
234234
lint(assignee, l);
235235
},
236236
_ => {},
@@ -244,11 +244,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
244244
}
245245
}
246246

247-
fn is_commutative(op: hir::BinOp_) -> bool {
248-
use rustc::hir::BinOp_::*;
247+
fn is_commutative(op: hir::BinOpKind) -> bool {
248+
use rustc::hir::BinOpKind::*;
249249
match op {
250-
BiAdd | BiMul | BiAnd | BiOr | BiBitXor | BiBitAnd | BiBitOr | BiEq | BiNe => true,
251-
BiSub | BiDiv | BiRem | BiShl | BiShr | BiLt | BiLe | BiGe | BiGt => false,
250+
Add | Mul | And | Or | BitXor | BitAnd | BitOr | Eq | Ne => true,
251+
Sub | Div | Rem | Shl | Shr | Lt | Le | Ge | Gt => false,
252252
}
253253
}
254254

clippy_lints/src/attrs.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass {
154154
check_attrs(cx, item.span, item.name, &item.attrs)
155155
}
156156
match item.node {
157-
ItemExternCrate(_) | ItemUse(_, _) => {
157+
ItemKind::ExternCrate(_) | ItemKind::Use(_, _) => {
158158
for attr in &item.attrs {
159159
if let Some(ref lint_list) = attr.meta_item_list() {
160160
match &*attr.name().as_str() {
161161
"allow" | "warn" | "deny" | "forbid" => {
162162
// whitelist `unused_imports` and `deprecated`
163163
for lint in lint_list {
164164
if is_word(lint, "unused_imports") || is_word(lint, "deprecated") {
165-
if let ItemUse(_, _) = item.node {
165+
if let ItemKind::Use(_, _) = item.node {
166166
return;
167167
}
168168
}
@@ -207,7 +207,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass {
207207
}
208208

209209
fn is_relevant_item(tcx: TyCtxt, item: &Item) -> bool {
210-
if let ItemFn(_, _, _, eid) = item.node {
210+
if let ItemKind::Fn(_, _, _, eid) = item.node {
211211
is_relevant_expr(tcx, tcx.body_tables(eid), &tcx.hir.body(eid).value)
212212
} else {
213213
true
@@ -234,8 +234,8 @@ fn is_relevant_trait(tcx: TyCtxt, item: &TraitItem) -> bool {
234234
fn is_relevant_block(tcx: TyCtxt, tables: &ty::TypeckTables, block: &Block) -> bool {
235235
if let Some(stmt) = block.stmts.first() {
236236
match stmt.node {
237-
StmtDecl(_, _) => true,
238-
StmtExpr(ref expr, _) | StmtSemi(ref expr, _) => is_relevant_expr(tcx, tables, expr),
237+
StmtKind::Decl(_, _) => true,
238+
StmtKind::Expr(ref expr, _) | StmtKind::Semi(ref expr, _) => is_relevant_expr(tcx, tables, expr),
239239
}
240240
} else {
241241
block.expr.as_ref().map_or(false, |e| is_relevant_expr(tcx, tables, e))
@@ -244,10 +244,10 @@ fn is_relevant_block(tcx: TyCtxt, tables: &ty::TypeckTables, block: &Block) -> b
244244

245245
fn is_relevant_expr(tcx: TyCtxt, tables: &ty::TypeckTables, expr: &Expr) -> bool {
246246
match expr.node {
247-
ExprBlock(ref block, _) => is_relevant_block(tcx, tables, block),
248-
ExprRet(Some(ref e)) => is_relevant_expr(tcx, tables, e),
249-
ExprRet(None) | ExprBreak(_, None) => false,
250-
ExprCall(ref path_expr, _) => if let ExprPath(ref qpath) = path_expr.node {
247+
ExprKind::Block(ref block, _) => is_relevant_block(tcx, tables, block),
248+
ExprKind::Ret(Some(ref e)) => is_relevant_expr(tcx, tables, e),
249+
ExprKind::Ret(None) | ExprKind::Break(_, None) => false,
250+
ExprKind::Call(ref path_expr, _) => if let ExprKind::Path(ref qpath) = path_expr.node {
251251
if let Some(fun_id) = opt_def_id(tables.qpath_def(qpath, path_expr.hir_id)) {
252252
!match_def_path(tcx, fun_id, &paths::BEGIN_PANIC)
253253
} else {

clippy_lints/src/bit_mask.rs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ impl LintPass for BitMask {
109109

110110
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BitMask {
111111
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
112-
if let ExprBinary(ref cmp, ref left, ref right) = e.node {
112+
if let ExprKind::Binary(ref cmp, ref left, ref right) = e.node {
113113
if cmp.node.is_comparison() {
114114
if let Some(cmp_opt) = fetch_int_literal(cx, right) {
115115
check_compare(cx, left, cmp.node, cmp_opt, e.span)
@@ -119,13 +119,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BitMask {
119119
}
120120
}
121121
if_chain! {
122-
if let Expr_::ExprBinary(ref op, ref left, ref right) = e.node;
123-
if BinOp_::BiEq == op.node;
124-
if let Expr_::ExprBinary(ref op1, ref left1, ref right1) = left.node;
125-
if BinOp_::BiBitAnd == op1.node;
126-
if let Expr_::ExprLit(ref lit) = right1.node;
122+
if let ExprKind::Binary(ref op, ref left, ref right) = e.node;
123+
if BinOpKind::Eq == op.node;
124+
if let ExprKind::Binary(ref op1, ref left1, ref right1) = left.node;
125+
if BinOpKind::BitAnd == op1.node;
126+
if let ExprKind::Lit(ref lit) = right1.node;
127127
if let LitKind::Int(n, _) = lit.node;
128-
if let Expr_::ExprLit(ref lit1) = right.node;
128+
if let ExprKind::Lit(ref lit1) = right.node;
129129
if let LitKind::Int(0, _) = lit1.node;
130130
if n.leading_zeros() == n.count_zeros();
131131
if n > u128::from(self.verbose_bit_mask_threshold);
@@ -143,22 +143,22 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BitMask {
143143
}
144144
}
145145

146-
fn invert_cmp(cmp: BinOp_) -> BinOp_ {
146+
fn invert_cmp(cmp: BinOpKind) -> BinOpKind {
147147
match cmp {
148-
BiEq => BiEq,
149-
BiNe => BiNe,
150-
BiLt => BiGt,
151-
BiGt => BiLt,
152-
BiLe => BiGe,
153-
BiGe => BiLe,
154-
_ => BiOr, // Dummy
148+
BinOpKind::Eq => BinOpKind::Eq,
149+
BinOpKind::Ne => BinOpKind::Ne,
150+
BinOpKind::Lt => BinOpKind::Gt,
151+
BinOpKind::Gt => BinOpKind::Lt,
152+
BinOpKind::Le => BinOpKind::Ge,
153+
BinOpKind::Ge => BinOpKind::Le,
154+
_ => BinOpKind::Or, // Dummy
155155
}
156156
}
157157

158158

159-
fn check_compare(cx: &LateContext, bit_op: &Expr, cmp_op: BinOp_, cmp_value: u128, span: Span) {
160-
if let ExprBinary(ref op, ref left, ref right) = bit_op.node {
161-
if op.node != BiBitAnd && op.node != BiBitOr {
159+
fn check_compare(cx: &LateContext, bit_op: &Expr, cmp_op: BinOpKind, cmp_value: u128, span: Span) {
160+
if let ExprKind::Binary(ref op, ref left, ref right) = bit_op.node {
161+
if op.node != BinOpKind::BitAnd && op.node != BinOpKind::BitOr {
162162
return;
163163
}
164164
fetch_int_literal(cx, right)
@@ -167,10 +167,10 @@ fn check_compare(cx: &LateContext, bit_op: &Expr, cmp_op: BinOp_, cmp_value: u12
167167
}
168168
}
169169

170-
fn check_bit_mask(cx: &LateContext, bit_op: BinOp_, cmp_op: BinOp_, mask_value: u128, cmp_value: u128, span: Span) {
170+
fn check_bit_mask(cx: &LateContext, bit_op: BinOpKind, cmp_op: BinOpKind, mask_value: u128, cmp_value: u128, span: Span) {
171171
match cmp_op {
172-
BiEq | BiNe => match bit_op {
173-
BiBitAnd => if mask_value & cmp_value != cmp_value {
172+
BinOpKind::Eq | BinOpKind::Ne => match bit_op {
173+
BinOpKind::BitAnd => if mask_value & cmp_value != cmp_value {
174174
if cmp_value != 0 {
175175
span_lint(
176176
cx,
@@ -186,7 +186,7 @@ fn check_bit_mask(cx: &LateContext, bit_op: BinOp_, cmp_op: BinOp_, mask_value:
186186
} else if mask_value == 0 {
187187
span_lint(cx, BAD_BIT_MASK, span, "&-masking with zero");
188188
},
189-
BiBitOr => if mask_value | cmp_value != cmp_value {
189+
BinOpKind::BitOr => if mask_value | cmp_value != cmp_value {
190190
span_lint(
191191
cx,
192192
BAD_BIT_MASK,
@@ -200,8 +200,8 @@ fn check_bit_mask(cx: &LateContext, bit_op: BinOp_, cmp_op: BinOp_, mask_value:
200200
},
201201
_ => (),
202202
},
203-
BiLt | BiGe => match bit_op {
204-
BiBitAnd => if mask_value < cmp_value {
203+
BinOpKind::Lt | BinOpKind::Ge => match bit_op {
204+
BinOpKind::BitAnd => if mask_value < cmp_value {
205205
span_lint(
206206
cx,
207207
BAD_BIT_MASK,
@@ -215,7 +215,7 @@ fn check_bit_mask(cx: &LateContext, bit_op: BinOp_, cmp_op: BinOp_, mask_value:
215215
} else if mask_value == 0 {
216216
span_lint(cx, BAD_BIT_MASK, span, "&-masking with zero");
217217
},
218-
BiBitOr => if mask_value >= cmp_value {
218+
BinOpKind::BitOr => if mask_value >= cmp_value {
219219
span_lint(
220220
cx,
221221
BAD_BIT_MASK,
@@ -229,11 +229,11 @@ fn check_bit_mask(cx: &LateContext, bit_op: BinOp_, cmp_op: BinOp_, mask_value:
229229
} else {
230230
check_ineffective_lt(cx, span, mask_value, cmp_value, "|");
231231
},
232-
BiBitXor => check_ineffective_lt(cx, span, mask_value, cmp_value, "^"),
232+
BinOpKind::BitXor => check_ineffective_lt(cx, span, mask_value, cmp_value, "^"),
233233
_ => (),
234234
},
235-
BiLe | BiGt => match bit_op {
236-
BiBitAnd => if mask_value <= cmp_value {
235+
BinOpKind::Le | BinOpKind::Gt => match bit_op {
236+
BinOpKind::BitAnd => if mask_value <= cmp_value {
237237
span_lint(
238238
cx,
239239
BAD_BIT_MASK,
@@ -247,7 +247,7 @@ fn check_bit_mask(cx: &LateContext, bit_op: BinOp_, cmp_op: BinOp_, mask_value:
247247
} else if mask_value == 0 {
248248
span_lint(cx, BAD_BIT_MASK, span, "&-masking with zero");
249249
},
250-
BiBitOr => if mask_value > cmp_value {
250+
BinOpKind::BitOr => if mask_value > cmp_value {
251251
span_lint(
252252
cx,
253253
BAD_BIT_MASK,
@@ -261,7 +261,7 @@ fn check_bit_mask(cx: &LateContext, bit_op: BinOp_, cmp_op: BinOp_, mask_value:
261261
} else {
262262
check_ineffective_gt(cx, span, mask_value, cmp_value, "|");
263263
},
264-
BiBitXor => check_ineffective_gt(cx, span, mask_value, cmp_value, "^"),
264+
BinOpKind::BitXor => check_ineffective_gt(cx, span, mask_value, cmp_value, "^"),
265265
_ => (),
266266
},
267267
_ => (),

0 commit comments

Comments
 (0)