Skip to content

Commit c955ade

Browse files
committed
update clippy
1 parent 55a7864 commit c955ade

Some content is hidden

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

50 files changed

+880
-455
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,7 @@ All notable changes to this project will be documented in this file.
785785
[`double_comparisons`]: https://rust-lang.github.io/rust-clippy/master/index.html#double_comparisons
786786
[`double_neg`]: https://rust-lang.github.io/rust-clippy/master/index.html#double_neg
787787
[`double_parens`]: https://rust-lang.github.io/rust-clippy/master/index.html#double_parens
788+
[`drop_bounds`]: https://rust-lang.github.io/rust-clippy/master/index.html#drop_bounds
788789
[`drop_copy`]: https://rust-lang.github.io/rust-clippy/master/index.html#drop_copy
789790
[`drop_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#drop_ref
790791
[`duplicate_underscore_argument`]: https://rust-lang.github.io/rust-clippy/master/index.html#duplicate_underscore_argument

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@
77

88
A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code.
99

10-
[There are 296 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
10+
[There are 297 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
1111

1212
We have a bunch of lint categories to allow you to choose how much Clippy is supposed to ~~annoy~~ help you:
1313

14-
* `clippy::all` (everything that has no false positives)
15-
* `clippy::pedantic` (everything)
16-
* `clippy::nursery` (new lints that aren't quite ready yet)
14+
* `clippy::all` (everything that is on by default: all the categories below except for `nursery`, `pedantic`, and `cargo`)
15+
* **`clippy::correctness`** (code that is just outright wrong or very very useless, causes hard errors by default)
1716
* `clippy::style` (code that should be written in a more idiomatic way)
1817
* `clippy::complexity` (code that does something simple but in a complex way)
1918
* `clippy::perf` (code that can be written in a faster way)
20-
* `clippy::cargo` (checks against the cargo manifest)
21-
* **`clippy::correctness`** (code that is just outright wrong or very very useless)
19+
* `clippy::pedantic` (lints which are rather strict, off by default)
20+
* `clippy::nursery` (new lints that aren't quite ready yet, off by default)
21+
* `clippy::cargo` (checks against the cargo manifest, off by default)
2222

2323
More to come, please [file an issue](https://github.com/rust-lang/rust-clippy/issues) if you have ideas!
2424

@@ -31,6 +31,8 @@ Only the following of those categories are enabled by default:
3131

3232
Other categories need to be enabled in order for their lints to be executed.
3333

34+
The [lint list](https://rust-lang.github.io/rust-clippy/master/index.html) also contains "restriction lints", which are for things which are usually not considered "bad", but may be useful to turn on in specific cases. These should be used very selectively, if at all.
35+
3436
Table of contents:
3537

3638
* [Usage instructions](#usage)

ci/base-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ rustup override set nightly
5959
# avoid loop spam and allow cmds with exit status != 0
6060
set +ex
6161

62-
for file in `find tests -not -path "tests/ui/methods.rs" -not -path "tests/ui/format.rs" -not -path "tests/ui/formatting.rs" -not -path "tests/ui/empty_line_after_outer_attribute.rs" -not -path "tests/ui/double_parens.rs" -not -path "tests/ui/doc.rs" -not -path "tests/ui/unused_unit.rs" | grep "\.rs$"` ; do
62+
for file in `find tests -not -path "tests/ui/format.rs" -not -path "tests/ui/formatting.rs" -not -path "tests/ui/empty_line_after_outer_attribute.rs" -not -path "tests/ui/double_parens.rs" -not -path "tests/ui/doc.rs" -not -path "tests/ui/unused_unit.rs" | grep "\.rs$"` ; do
6363
rustfmt ${file} --check
6464
if [ $? -ne 0 ]; then
6565
echo "${file} needs reformatting!"

clippy_lints/src/assign_ops.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
66
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
77
use rustc::{declare_tool_lint, lint_array};
88
use rustc_errors::Applicability;
9-
use syntax::ast;
109

1110
/// **What it does:** Checks for `a = a op b` or `a = b commutative_op a`
1211
/// patterns.
@@ -140,12 +139,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
140139
return; // useless if the trait doesn't exist
141140
};
142141
// check that we are not inside an `impl AssignOp` of this exact operation
143-
let parent_fn = cx.tcx.hir().get_parent(e.id);
144-
let parent_impl = cx.tcx.hir().get_parent(parent_fn);
142+
let parent_fn = cx.tcx.hir().get_parent_item(e.hir_id);
143+
let parent_impl = cx.tcx.hir().get_parent_item(parent_fn);
145144
// the crate node is the only one that is not in the map
146145
if_chain! {
147-
if parent_impl != ast::CRATE_NODE_ID;
148-
if let hir::Node::Item(item) = cx.tcx.hir().get(parent_impl);
146+
if parent_impl != hir::CRATE_HIR_ID;
147+
if let hir::Node::Item(item) = cx.tcx.hir().get_by_hir_id(parent_impl);
149148
if let hir::ItemKind::Impl(_, _, _, _, Some(trait_ref), _, _) =
150149
&item.node;
151150
if trait_ref.path.def.def_id() == trait_id;

clippy_lints/src/booleans.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
77
use rustc::{declare_tool_lint, lint_array};
88
use rustc_data_structures::thin_vec::ThinVec;
99
use rustc_errors::Applicability;
10-
use syntax::ast::{LitKind, DUMMY_NODE_ID};
10+
use syntax::ast::LitKind;
1111
use syntax::source_map::{dummy_spanned, Span, DUMMY_SP};
1212

1313
/// **What it does:** Checks for boolean expressions that can be written more
@@ -132,7 +132,6 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
132132
}
133133

134134
let mk_expr = |op| Expr {
135-
id: DUMMY_NODE_ID,
136135
hir_id: DUMMY_HIR_ID,
137136
span: DUMMY_SP,
138137
attrs: ThinVec::new(),

clippy_lints/src/copies.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CopyAndPaste {
125125
..
126126
}) = get_parent_expr(cx, expr)
127127
{
128-
if else_expr.id == expr.id {
128+
if else_expr.hir_id == expr.hir_id {
129129
return;
130130
}
131131
}

clippy_lints/src/cyclomatic_complexity.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,7 @@ fn report_cc_bug(
222222
span: Span,
223223
id: HirId,
224224
) {
225-
let node_id = cx.tcx.hir().hir_to_node_id(id);
226-
if !is_allowed(cx, CYCLOMATIC_COMPLEXITY, node_id) {
225+
if !is_allowed(cx, CYCLOMATIC_COMPLEXITY, id) {
227226
cx.sess().span_note_without_error(
228227
span,
229228
&format!(

clippy_lints/src/default_trait_access.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DefaultTraitAccess {
4545
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
4646
if_chain! {
4747
if let ExprKind::Call(ref path, ..) = expr.node;
48-
if !any_parent_is_automatically_derived(cx.tcx, expr.id);
48+
if !any_parent_is_automatically_derived(cx.tcx, expr.hir_id);
4949
if let ExprKind::Path(ref qpath) = path.node;
5050
if let Some(def_id) = opt_def_id(cx.tables.qpath_def(qpath, path.hir_id));
5151
if match_def_path(cx.tcx, def_id, &paths::DEFAULT_TRAIT_METHOD);

clippy_lints/src/drop_bounds.rs

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
use crate::utils::{match_def_path, paths, span_lint};
2+
use if_chain::if_chain;
3+
use rustc::hir::*;
4+
use rustc::lint::{LateLintPass, LintArray, LintPass};
5+
use rustc::{declare_tool_lint, lint_array};
6+
7+
/// **What it does:** Checks for generics with `std::ops::Drop` as bounds.
8+
///
9+
/// **Why is this bad?** `Drop` bounds do not really accomplish anything.
10+
/// A type may have compiler-generated drop glue without implementing the
11+
/// `Drop` trait itself. The `Drop` trait also only has one method,
12+
/// `Drop::drop`, and that function is by fiat not callable in user code.
13+
/// So there is really no use case for using `Drop` in trait bounds.
14+
///
15+
/// The most likely use case of a drop bound is to distinguish between types
16+
/// that have destructors and types that don't. Combined with specialization,
17+
/// a naive coder would write an implementation that assumed a type could be
18+
/// trivially dropped, then write a specialization for `T: Drop` that actually
19+
/// calls the destructor. Except that doing so is not correct; String, for
20+
/// example, doesn't actually implement Drop, but because String contains a
21+
/// Vec, assuming it can be trivially dropped will leak memory.
22+
///
23+
/// **Known problems:** None.
24+
///
25+
/// **Example:**
26+
/// ```rust
27+
/// fn foo<T: Drop>() {}
28+
/// ```
29+
declare_clippy_lint! {
30+
pub DROP_BOUNDS,
31+
correctness,
32+
"Bounds of the form `T: Drop` are useless"
33+
}
34+
35+
const DROP_BOUNDS_SUMMARY: &str = "Bounds of the form `T: Drop` are useless. \
36+
Use `std::mem::needs_drop` to detect if a type has drop glue.";
37+
38+
pub struct Pass;
39+
40+
impl LintPass for Pass {
41+
fn get_lints(&self) -> LintArray {
42+
lint_array!(DROP_BOUNDS)
43+
}
44+
45+
fn name(&self) -> &'static str {
46+
"DropBounds"
47+
}
48+
}
49+
50+
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
51+
fn check_generic_param(&mut self, cx: &rustc::lint::LateContext<'a, 'tcx>, p: &'tcx GenericParam) {
52+
for bound in &p.bounds {
53+
lint_bound(cx, bound);
54+
}
55+
}
56+
fn check_where_predicate(&mut self, cx: &rustc::lint::LateContext<'a, 'tcx>, p: &'tcx WherePredicate) {
57+
if let WherePredicate::BoundPredicate(WhereBoundPredicate { bounds, .. }) = p {
58+
for bound in bounds {
59+
lint_bound(cx, bound);
60+
}
61+
}
62+
}
63+
}
64+
65+
fn lint_bound<'a, 'tcx>(cx: &rustc::lint::LateContext<'a, 'tcx>, bound: &'tcx GenericBound) {
66+
if_chain! {
67+
if let GenericBound::Trait(t, _) = bound;
68+
if let Some(def_id) = t.trait_ref.path.def.opt_def_id();
69+
if match_def_path(cx.tcx, def_id, &paths::DROP_TRAIT);
70+
then {
71+
span_lint(
72+
cx,
73+
DROP_BOUNDS,
74+
t.span,
75+
DROP_BOUNDS_SUMMARY
76+
);
77+
}
78+
}
79+
}

clippy_lints/src/escape.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
100100
}
101101

102102
impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
103-
fn consume(&mut self, _: NodeId, _: Span, cmt: &cmt_<'tcx>, mode: ConsumeMode) {
103+
fn consume(&mut self, _: HirId, _: Span, cmt: &cmt_<'tcx>, mode: ConsumeMode) {
104104
if let Categorization::Local(lid) = cmt.cat {
105105
if let Move(DirectRefMove) = mode {
106106
// moved out or in. clearly can't be localized
@@ -150,7 +150,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
150150
}
151151
fn borrow(
152152
&mut self,
153-
_: NodeId,
153+
_: HirId,
154154
_: Span,
155155
cmt: &cmt_<'tcx>,
156156
_: ty::Region<'_>,
@@ -178,7 +178,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
178178
}
179179
}
180180
fn decl_without_init(&mut self, _: NodeId, _: Span) {}
181-
fn mutate(&mut self, _: NodeId, _: Span, _: &cmt_<'tcx>, _: MutateMode) {}
181+
fn mutate(&mut self, _: HirId, _: Span, _: &cmt_<'tcx>, _: MutateMode) {}
182182
}
183183

184184
impl<'a, 'tcx> EscapeDelegate<'a, 'tcx> {

0 commit comments

Comments
 (0)