Skip to content

Commit f11d993

Browse files
author
A.A.Abroskin
committed
Merge branch 'master' into add-lints-aseert-checks
* master: (58 commits) Rustfmt all the things Don't make decisions on values that don't represent the decision Improving comments. Rustup Added rustfix to the test. Improve span shortening. Added "make_return" and "blockify" convenience methods in Sugg and used them in "needless_bool". Actually check for constants. Fixed potential mistakes with nesting. Added tests. formatting fix Update clippy_lints/src/needless_bool.rs formatting fix Fixing typo in CONTRIBUTING.md Fix breakage due to #57651 needless bool lint suggestion is wrapped in brackets if it is an "else" clause of an "if-else" statement Fix automatic suggestion on `use_self`. Remove negative integer literal checks. Fix `implicit_return` false positives. Run rustfmt Fixed breakage due to #57489 ...
2 parents 58abdb5 + a069320 commit f11d993

File tree

699 files changed

+4043
-6625
lines changed

Some content is hidden

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

699 files changed

+4043
-6625
lines changed

.github/deploy.sh

-11
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
11
#!/bin/bash
22

3-
# Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
4-
# file at the top-level directory of this distribution and at
5-
# http://rust-lang.org/COPYRIGHT.
6-
#
7-
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
8-
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
9-
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
10-
# option. This file may not be copied, modified, or distributed
11-
# except according to those terms.
12-
13-
143
# Automatically deploy on gh-pages
154

165
set -ex

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ to lint-writing, though it does get into advanced stuff. Most lints consist of a
7979
of this.
8080

8181
If you want to add a new lint or change existing ones apart from bugfixing, it's
82-
also a good idea to give the [stability guaratees][rfc_stability] and
82+
also a good idea to give the [stability guarantees][rfc_stability] and
8383
[lint categories][rfc_lint_cats] sections of the [Clippy 1.0 RFC][clippy_rfc] a
8484
quick read.
8585

COPYRIGHT

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright 2014-2018 The Rust Project Developers
1+
Copyright 2014-2019 The Rust Project Developers
22

33
Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
44
http://www.apache.org/licenses/LICENSE-2.0> or the MIT license

README.md

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Clippy
22

3-
[![Build Status](https://travis-ci.org/rust-lang/rust-clippy.svg?branch=master)](https://travis-ci.org/rust-lang/rust-clippy)
3+
[![Build Status](https://travis-ci.com/rust-lang/rust-clippy.svg?branch=master)](https://travis-ci.com/rust-lang/rust-clippy)
44
[![Windows Build status](https://ci.appveyor.com/api/projects/status/id677xpw1dguo7iw?svg=true)](https://ci.appveyor.com/project/rust-lang-libs/rust-clippy)
55
[![Current Version](https://meritbadge.herokuapp.com/clippy)](https://crates.io/crates/clippy)
66
[![License: MIT/Apache-2.0](https://img.shields.io/crates/l/clippy.svg)](#license)
@@ -68,10 +68,15 @@ Once you have rustup and the latest stable release (at least Rust 1.29) installe
6868
```terminal
6969
rustup component add clippy
7070
```
71+
If it says that it can't find the `clippy` component, please run `rustup self update`.
7172

72-
Now you can run Clippy by invoking `cargo clippy`.
73+
#### Step 3: Run Clippy
7374

74-
If it says that it can't find the `clippy` subcommand, please run `rustup self update`
75+
Now you can run Clippy by invoking the following command:
76+
77+
```terminal
78+
cargo clippy
79+
```
7580

7681
### Running Clippy from the command line without installing it
7782

@@ -157,7 +162,7 @@ If you want to contribute to Clippy, you can find more information in [CONTRIBUT
157162

158163
## License
159164

160-
Copyright 2014-2018 The Rust Project Developers
165+
Copyright 2014-2019 The Rust Project Developers
161166

162167
Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
163168
http://www.apache.org/licenses/LICENSE-2.0> or the MIT license

bors.toml

-4
This file was deleted.

build.rs

-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2-
// file at the top-level directory of this distribution.
3-
//
4-
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5-
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6-
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7-
// option. This file may not be copied, modified, or distributed
8-
// except according to those terms.
9-
101
fn main() {
112
// Forward the profile to the main compilation
123
println!("cargo:rustc-env=PROFILE={}", std::env::var("PROFILE").unwrap());

ci/base-tests.sh

-11
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,3 @@
1-
# Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2-
# file at the top-level directory of this distribution and at
3-
# http://rust-lang.org/COPYRIGHT.
4-
#
5-
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6-
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7-
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8-
# option. This file may not be copied, modified, or distributed
9-
# except according to those terms.
10-
11-
121
set -ex
132

143
echo "Running clippy base tests"

ci/integration-tests.sh

-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
# Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2-
# file at the top-level directory of this distribution and at
3-
# http://rust-lang.org/COPYRIGHT.
4-
#
5-
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6-
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7-
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8-
# option. This file may not be copied, modified, or distributed
9-
# except according to those terms.
10-
111
set -x
122
rm ~/.cargo/bin/cargo-clippy
133
cargo install --force --path .

clippy_dev/src/lib.rs

-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2-
// file at the top-level directory of this distribution.
3-
//
4-
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5-
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6-
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7-
// option. This file may not be copied, modified, or distributed
8-
// except according to those terms.
9-
101
#![allow(clippy::default_hash_types)]
112

123
use itertools::Itertools;

clippy_dev/src/main.rs

-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2-
// file at the top-level directory of this distribution.
3-
//
4-
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5-
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6-
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7-
// option. This file may not be copied, modified, or distributed
8-
// except according to those terms.
9-
101
extern crate clap;
112
extern crate clippy_dev;
123
extern crate regex;

clippy_dummy/build.rs

+1-11
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2-
// file at the top-level directory of this distribution.
3-
//
4-
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5-
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6-
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7-
// option. This file may not be copied, modified, or distributed
8-
// except according to those terms.
9-
10-
111
extern crate term;
122

133
fn main() {
@@ -49,4 +39,4 @@ fn foo() -> Result<(), ()> {
4939

5040
t.reset().map_err(|_| ())?;
5141
Ok(())
52-
}
42+
}

clippy_dummy/src/main.rs

-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2-
// file at the top-level directory of this distribution.
3-
//
4-
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5-
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6-
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7-
// option. This file may not be copied, modified, or distributed
8-
// except according to those terms.
9-
10-
111
fn main() {
122
panic!("This shouldn't even compile")
133
}

clippy_lints/src/approx_const.rs

-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2-
// file at the top-level directory of this distribution.
3-
//
4-
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5-
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6-
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7-
// option. This file may not be copied, modified, or distributed
8-
// except according to those terms.
9-
101
use crate::utils::span_lint;
112
use rustc::hir::*;
123
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};

clippy_lints/src/arithmetic.rs

+6-12
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
1-
// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2-
// file at the top-level directory of this distribution.
3-
//
4-
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5-
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6-
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7-
// option. This file may not be copied, modified, or distributed
8-
// except according to those terms.
9-
1+
use crate::consts::constant_simple;
102
use crate::utils::span_lint;
113
use rustc::hir;
124
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
@@ -103,8 +95,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Arithmetic {
10395
hir::ExprKind::Unary(hir::UnOp::UnNeg, arg) => {
10496
let ty = cx.tables.expr_ty(arg);
10597
if ty.is_integral() {
106-
span_lint(cx, INTEGER_ARITHMETIC, expr.span, "integer arithmetic detected");
107-
self.expr_span = Some(expr.span);
98+
if constant_simple(cx, cx.tables, expr).is_none() {
99+
span_lint(cx, INTEGER_ARITHMETIC, expr.span, "integer arithmetic detected");
100+
self.expr_span = Some(expr.span);
101+
}
108102
} else if ty.is_floating_point() {
109103
span_lint(cx, FLOAT_ARITHMETIC, expr.span, "floating-point arithmetic detected");
110104
self.expr_span = Some(expr.span);
@@ -134,7 +128,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Arithmetic {
134128
}
135129
self.const_span = Some(body_span);
136130
},
137-
hir::BodyOwnerKind::Fn => (),
131+
hir::BodyOwnerKind::Fn | hir::BodyOwnerKind::Closure => (),
138132
}
139133
}
140134

clippy_lints/src/assign_ops.rs

-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2-
// file at the top-level directory of this distribution.
3-
//
4-
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5-
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6-
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7-
// option. This file may not be copied, modified, or distributed
8-
// except according to those terms.
9-
101
use crate::utils::{get_trait_def_id, implements_trait, snippet_opt, span_lint_and_then, SpanlessEq};
112
use crate::utils::{higher, sugg};
123
use if_chain::if_chain;

clippy_lints/src/attrs.rs

+13-19
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2-
// file at the top-level directory of this distribution.
3-
//
4-
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5-
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6-
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7-
// option. This file may not be copied, modified, or distributed
8-
// except according to those terms.
9-
101
//! checks for attributes
112
123
use crate::reexport::*;
@@ -341,9 +332,12 @@ fn check_clippy_lint_names(cx: &LateContext<'_, '_>, items: &[NestedMetaItem]) {
341332
// https://github.com/rust-lang/rust/pull/56992
342333
CheckLintNameResult::NoLint(None) => (),
343334
_ => {
344-
db.span_suggestion(lint.span,
345-
"lowercase the lint name",
346-
name_lower);
335+
db.span_suggestion_with_applicability(
336+
lint.span,
337+
"lowercase the lint name",
338+
name_lower,
339+
Applicability::MaybeIncorrect,
340+
);
347341
}
348342
}
349343
}
@@ -382,8 +376,9 @@ fn is_relevant_trait(tcx: TyCtxt<'_, '_, '_>, item: &TraitItem) -> bool {
382376
fn is_relevant_block(tcx: TyCtxt<'_, '_, '_>, tables: &ty::TypeckTables<'_>, block: &Block) -> bool {
383377
if let Some(stmt) = block.stmts.first() {
384378
match &stmt.node {
385-
StmtKind::Decl(_, _) => true,
386-
StmtKind::Expr(expr, _) | StmtKind::Semi(expr, _) => is_relevant_expr(tcx, tables, expr),
379+
StmtKind::Local(_) => true,
380+
StmtKind::Expr(expr) | StmtKind::Semi(expr) => is_relevant_expr(tcx, tables, expr),
381+
_ => false,
387382
}
388383
} else {
389384
block.expr.as_ref().map_or(false, |e| is_relevant_expr(tcx, tables, e))
@@ -520,18 +515,17 @@ impl EarlyLintPass for CfgAttrPass {
520515
// check for `rustfmt_skip` and `rustfmt::skip`
521516
if let Some(skip_item) = &items[1].meta_item();
522517
if skip_item.name() == "rustfmt_skip" || skip_item.name() == "skip";
518+
// Only lint outer attributes, because custom inner attributes are unstable
519+
// Tracking issue: https://github.com/rust-lang/rust/issues/54726
520+
if let AttrStyle::Outer = attr.style;
523521
then {
524-
let attr_style = match attr.style {
525-
AttrStyle::Outer => "#[",
526-
AttrStyle::Inner => "#![",
527-
};
528522
span_lint_and_sugg(
529523
cx,
530524
DEPRECATED_CFG_ATTR,
531525
attr.span,
532526
"`cfg_attr` is deprecated for rustfmt and got replaced by tool_attributes",
533527
"use",
534-
format!("{}rustfmt::skip]", attr_style),
528+
"#[rustfmt::skip]".to_string(),
535529
Applicability::MachineApplicable,
536530
);
537531
}

clippy_lints/src/bit_mask.rs

-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2-
// file at the top-level directory of this distribution.
3-
//
4-
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5-
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6-
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7-
// option. This file may not be copied, modified, or distributed
8-
// except according to those terms.
9-
101
use crate::consts::{constant, Constant};
112
use crate::utils::sugg::Sugg;
123
use crate::utils::{span_lint, span_lint_and_then};

clippy_lints/src/blacklisted_name.rs

-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2-
// file at the top-level directory of this distribution.
3-
//
4-
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5-
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6-
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7-
// option. This file may not be copied, modified, or distributed
8-
// except according to those terms.
9-
101
use crate::utils::span_lint;
112
use rustc::hir::*;
123
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};

clippy_lints/src/block_in_if_condition.rs

-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2-
// file at the top-level directory of this distribution.
3-
//
4-
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5-
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6-
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7-
// option. This file may not be copied, modified, or distributed
8-
// except according to those terms.
9-
101
use crate::utils::*;
112
use matches::matches;
123
use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};

clippy_lints/src/booleans.rs

-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2-
// file at the top-level directory of this distribution.
3-
//
4-
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5-
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6-
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7-
// option. This file may not be copied, modified, or distributed
8-
// except according to those terms.
9-
101
use crate::utils::{
112
get_trait_def_id, implements_trait, in_macro, match_type, paths, snippet_opt, span_lint_and_then, SpanlessEq,
123
};

clippy_lints/src/bytecount.rs

-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2-
// file at the top-level directory of this distribution.
3-
//
4-
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5-
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6-
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7-
// option. This file may not be copied, modified, or distributed
8-
// except according to those terms.
9-
101
use crate::utils::{
112
contains_name, get_pat_name, match_type, paths, single_segment_path, snippet_with_applicability,
123
span_lint_and_sugg, walk_ptrs_ty,

clippy_lints/src/cargo_common_metadata.rs

-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2-
// file at the top-level directory of this distribution.
3-
//
4-
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5-
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6-
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7-
// option. This file may not be copied, modified, or distributed
8-
// except according to those terms.
9-
101
//! lint on missing cargo common metadata
112
123
use crate::utils::span_lint;

clippy_lints/src/collapsible_if.rs

-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2-
// file at the top-level directory of this distribution.
3-
//
4-
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5-
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6-
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7-
// option. This file may not be copied, modified, or distributed
8-
// except according to those terms.
9-
101
//! Checks for if expressions that contain only an if expression.
112
//!
123
//! For example, the lint would catch:

0 commit comments

Comments
 (0)