Skip to content

Commit b998821

Browse files
committed
Auto merge of #100419 - flip1995:clippyup, r=Manishearth
Update Clippy r? `@Manishearth`
2 parents 2ed0f29 + ea90d4b commit b998821

File tree

183 files changed

+2242
-829
lines changed

Some content is hidden

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

183 files changed

+2242
-829
lines changed

Cargo.lock

+3-3
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ dependencies = [
661661

662662
[[package]]
663663
name = "clippy"
664-
version = "0.1.64"
664+
version = "0.1.65"
665665
dependencies = [
666666
"clippy_lints",
667667
"clippy_utils",
@@ -704,7 +704,7 @@ dependencies = [
704704

705705
[[package]]
706706
name = "clippy_lints"
707-
version = "0.1.64"
707+
version = "0.1.65"
708708
dependencies = [
709709
"cargo_metadata 0.14.0",
710710
"clippy_utils",
@@ -726,7 +726,7 @@ dependencies = [
726726

727727
[[package]]
728728
name = "clippy_utils"
729-
version = "0.1.64"
729+
version = "0.1.65"
730730
dependencies = [
731731
"arrayvec",
732732
"if_chain",

src/tools/clippy/CHANGELOG.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ Released 2021-09-09
965965
[#7407](https://github.com/rust-lang/rust-clippy/pull/7407)
966966
* [`redundant_allocation`]: Now additionally supports the `Arc<>` type
967967
[#7308](https://github.com/rust-lang/rust-clippy/pull/7308)
968-
* [`blacklisted_name`]: Now allows blacklisted names in test code
968+
* [`disallowed_names`]: Now allows disallowed names in test code
969969
[#7379](https://github.com/rust-lang/rust-clippy/pull/7379)
970970
* [`redundant_closure`]: Suggests `&mut` for `FnMut`
971971
[#7437](https://github.com/rust-lang/rust-clippy/pull/7437)
@@ -2066,7 +2066,7 @@ Released 2020-08-27
20662066
[#5692](https://github.com/rust-lang/rust-clippy/pull/5692)
20672067
* [`if_same_then_else`]: Don't assume multiplication is always commutative
20682068
[#5702](https://github.com/rust-lang/rust-clippy/pull/5702)
2069-
* [`blacklisted_name`]: Remove `bar` from the default configuration
2069+
* [`disallowed_names`]: Remove `bar` from the default configuration
20702070
[#5712](https://github.com/rust-lang/rust-clippy/pull/5712)
20712071
* [`redundant_pattern_matching`]: Avoid suggesting non-`const fn` calls in const contexts
20722072
[#5724](https://github.com/rust-lang/rust-clippy/pull/5724)
@@ -3522,6 +3522,7 @@ Released 2018-09-13
35223522
[`derive_partial_eq_without_eq`]: https://rust-lang.github.io/rust-clippy/master/index.html#derive_partial_eq_without_eq
35233523
[`disallowed_method`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_method
35243524
[`disallowed_methods`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_methods
3525+
[`disallowed_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_names
35253526
[`disallowed_script_idents`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_script_idents
35263527
[`disallowed_type`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_type
35273528
[`disallowed_types`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_types
@@ -3685,6 +3686,7 @@ Released 2018-09-13
36853686
[`manual_find`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_find
36863687
[`manual_find_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_find_map
36873688
[`manual_flatten`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_flatten
3689+
[`manual_instant_elapsed`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_instant_elapsed
36883690
[`manual_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_map
36893691
[`manual_memcpy`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_memcpy
36903692
[`manual_non_exhaustive`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_non_exhaustive
@@ -3816,11 +3818,13 @@ Released 2018-09-13
38163818
[`or_then_unwrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#or_then_unwrap
38173819
[`out_of_bounds_indexing`]: https://rust-lang.github.io/rust-clippy/master/index.html#out_of_bounds_indexing
38183820
[`overflow_check_conditional`]: https://rust-lang.github.io/rust-clippy/master/index.html#overflow_check_conditional
3821+
[`overly_complex_bool_expr`]: https://rust-lang.github.io/rust-clippy/master/index.html#overly_complex_bool_expr
38193822
[`panic`]: https://rust-lang.github.io/rust-clippy/master/index.html#panic
38203823
[`panic_in_result_fn`]: https://rust-lang.github.io/rust-clippy/master/index.html#panic_in_result_fn
38213824
[`panic_params`]: https://rust-lang.github.io/rust-clippy/master/index.html#panic_params
38223825
[`panicking_unwrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#panicking_unwrap
38233826
[`partialeq_ne_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#partialeq_ne_impl
3827+
[`partialeq_to_none`]: https://rust-lang.github.io/rust-clippy/master/index.html#partialeq_to_none
38243828
[`path_buf_push_overwrite`]: https://rust-lang.github.io/rust-clippy/master/index.html#path_buf_push_overwrite
38253829
[`pattern_type_mismatch`]: https://rust-lang.github.io/rust-clippy/master/index.html#pattern_type_mismatch
38263830
[`possible_missing_comma`]: https://rust-lang.github.io/rust-clippy/master/index.html#possible_missing_comma

src/tools/clippy/CONTRIBUTING.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ All contributors are expected to follow the [Rust Code of Conduct].
3030
## The Clippy book
3131

3232
If you're new to Clippy and don't know where to start the [Clippy book] includes
33-
a developer guide and is a good place to start your journey.
33+
a [developer guide] and is a good place to start your journey.
3434

35-
<!-- FIXME: Link to the deployed book, once it is deployed through CI -->
36-
[Clippy book]: book/src
35+
[Clippy book]: https://doc.rust-lang.org/nightly/clippy/index.html
36+
[developer guide]: https://doc.rust-lang.org/nightly/clippy/development/index.html
3737

3838
## High level approach
3939

src/tools/clippy/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy"
3-
version = "0.1.64"
3+
version = "0.1.65"
44
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
55
repository = "https://github.com/rust-lang/rust-clippy"
66
readme = "README.md"

src/tools/clippy/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ value` mapping e.g.
144144

145145
```toml
146146
avoid-breaking-exported-api = false
147-
blacklisted-names = ["toto", "tata", "titi"]
147+
disallowed-names = ["toto", "tata", "titi"]
148148
cognitive-complexity-threshold = 30
149149
```
150150

src/tools/clippy/book/src/configuration.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ basic `variable = value` mapping eg.
77

88
```toml
99
avoid-breaking-exported-api = false
10-
blacklisted-names = ["toto", "tata", "titi"]
10+
disallowed-names = ["toto", "tata", "titi"]
1111
cognitive-complexity-threshold = 30
1212
```
1313

src/tools/clippy/clippy_dev/src/new_lint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ fn setup_mod_file(path: &Path, lint: &LintData<'_>) -> io::Result<&'static str>
438438
let mut lint_context = None;
439439

440440
let mut iter = rustc_lexer::tokenize(&file_contents).map(|t| {
441-
let range = offset..offset + t.len;
441+
let range = offset..offset + t.len as usize;
442442
offset = range.end;
443443

444444
LintDeclSearchResult {

src/tools/clippy/clippy_dev/src/update_lints.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ pub(crate) struct LintDeclSearchResult<'a> {
836836
fn parse_contents(contents: &str, module: &str, lints: &mut Vec<Lint>) {
837837
let mut offset = 0usize;
838838
let mut iter = tokenize(contents).map(|t| {
839-
let range = offset..offset + t.len;
839+
let range = offset..offset + t.len as usize;
840840
offset = range.end;
841841

842842
LintDeclSearchResult {
@@ -899,7 +899,7 @@ fn parse_contents(contents: &str, module: &str, lints: &mut Vec<Lint>) {
899899
fn parse_deprecated_contents(contents: &str, lints: &mut Vec<DeprecatedLint>) {
900900
let mut offset = 0usize;
901901
let mut iter = tokenize(contents).map(|t| {
902-
let range = offset..offset + t.len;
902+
let range = offset..offset + t.len as usize;
903903
offset = range.end;
904904

905905
LintDeclSearchResult {
@@ -946,7 +946,7 @@ fn parse_renamed_contents(contents: &str, lints: &mut Vec<RenamedLint>) {
946946
for line in contents.lines() {
947947
let mut offset = 0usize;
948948
let mut iter = tokenize(line).map(|t| {
949-
let range = offset..offset + t.len;
949+
let range = offset..offset + t.len as usize;
950950
offset = range.end;
951951

952952
LintDeclSearchResult {

src/tools/clippy/clippy_lints/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy_lints"
3-
version = "0.1.64"
3+
version = "0.1.65"
44
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
55
repository = "https://github.com/rust-lang/rust-clippy"
66
readme = "README.md"

src/tools/clippy/clippy_lints/src/assertions_on_result_states.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,14 @@ impl<'tcx> LateLintPass<'tcx> for AssertionsOnResultStates {
5353
if result_type_with_refs != result_type {
5454
return;
5555
} else if let Res::Local(binding_id) = path_res(cx, recv)
56-
&& local_used_after_expr(cx, binding_id, recv) {
56+
&& local_used_after_expr(cx, binding_id, recv)
57+
{
5758
return;
5859
}
5960
}
6061
let mut app = Applicability::MachineApplicable;
6162
match method_segment.ident.as_str() {
62-
"is_ok" if has_debug_impl(cx, substs.type_at(1)) => {
63+
"is_ok" if type_suitable_to_unwrap(cx, substs.type_at(1)) => {
6364
span_lint_and_sugg(
6465
cx,
6566
ASSERTIONS_ON_RESULT_STATES,
@@ -73,7 +74,7 @@ impl<'tcx> LateLintPass<'tcx> for AssertionsOnResultStates {
7374
app,
7475
);
7576
}
76-
"is_err" if has_debug_impl(cx, substs.type_at(0)) => {
77+
"is_err" if type_suitable_to_unwrap(cx, substs.type_at(0)) => {
7778
span_lint_and_sugg(
7879
cx,
7980
ASSERTIONS_ON_RESULT_STATES,
@@ -99,3 +100,7 @@ fn has_debug_impl<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
99100
.get_diagnostic_item(sym::Debug)
100101
.map_or(false, |debug| implements_trait(cx, ty, debug, &[]))
101102
}
103+
104+
fn type_suitable_to_unwrap<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
105+
has_debug_impl(cx, ty) && !ty.is_unit() && !ty.is_never()
106+
}

src/tools/clippy/clippy_lints/src/booleans.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ declare_clippy_lint! {
6464
/// if a {}
6565
/// ```
6666
#[clippy::version = "pre 1.29.0"]
67-
pub LOGIC_BUG,
67+
pub OVERLY_COMPLEX_BOOL_EXPR,
6868
correctness,
6969
"boolean expressions that contain terminals which can be eliminated"
7070
}
7171

7272
// For each pairs, both orders are considered.
7373
const METHODS_WITH_NEGATION: [(&str, &str); 2] = [("is_some", "is_none"), ("is_err", "is_ok")];
7474

75-
declare_lint_pass!(NonminimalBool => [NONMINIMAL_BOOL, LOGIC_BUG]);
75+
declare_lint_pass!(NonminimalBool => [NONMINIMAL_BOOL, OVERLY_COMPLEX_BOOL_EXPR]);
7676

7777
impl<'tcx> LateLintPass<'tcx> for NonminimalBool {
7878
fn check_fn(
@@ -396,7 +396,7 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
396396
if stats.terminals[i] != 0 && simplified_stats.terminals[i] == 0 {
397397
span_lint_hir_and_then(
398398
self.cx,
399-
LOGIC_BUG,
399+
OVERLY_COMPLEX_BOOL_EXPR,
400400
e.hir_id,
401401
e.span,
402402
"this boolean expression contains a logic bug",

src/tools/clippy/clippy_lints/src/casts/cast_abs_to_unsigned.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub(super) fn check(
3737
span,
3838
&format!("casting the result of `{cast_from}::abs()` to {cast_to}"),
3939
"replace with",
40-
format!("{}.unsigned_abs()", Sugg::hir(cx, &args[0], "..")),
40+
format!("{}.unsigned_abs()", Sugg::hir(cx, &args[0], "..").maybe_par()),
4141
Applicability::MachineApplicable,
4242
);
4343
}

src/tools/clippy/clippy_lints/src/checked_conversions.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,7 @@ fn get_types_from_cast<'a>(
270270
let limit_from: Option<(&Expr<'_>, &str)> = call_from_cast.or_else(|| {
271271
if_chain! {
272272
// `from_type::from, to_type::max_value()`
273-
if let ExprKind::Call(from_func, args) = &expr.kind;
274-
// `to_type::max_value()`
275-
if args.len() == 1;
276-
if let limit = &args[0];
273+
if let ExprKind::Call(from_func, [limit]) = &expr.kind;
277274
// `from_type::from`
278275
if let ExprKind::Path(ref path) = &from_func.kind;
279276
if let Some(from_sym) = get_implementing_type(path, INTS, "from");

src/tools/clippy/clippy_lints/src/create_dir.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ declare_lint_pass!(CreateDir => [CREATE_DIR]);
3434
impl LateLintPass<'_> for CreateDir {
3535
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) {
3636
if_chain! {
37-
if let ExprKind::Call(func, args) = expr.kind;
37+
if let ExprKind::Call(func, [arg, ..]) = expr.kind;
3838
if let ExprKind::Path(ref path) = func.kind;
3939
if let Some(def_id) = cx.qpath_res(path, func.hir_id).opt_def_id();
4040
if match_def_path(cx, def_id, &paths::STD_FS_CREATE_DIR);
@@ -45,7 +45,7 @@ impl LateLintPass<'_> for CreateDir {
4545
expr.span,
4646
"calling `std::fs::create_dir` where there may be a better way",
4747
"consider calling `std::fs::create_dir_all` instead",
48-
format!("create_dir_all({})", snippet(cx, args[0].span, "..")),
48+
format!("create_dir_all({})", snippet(cx, arg.span, "..")),
4949
Applicability::MaybeIncorrect,
5050
)
5151
}

src/tools/clippy/clippy_lints/src/default.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use clippy_utils::diagnostics::{span_lint_and_note, span_lint_and_sugg};
22
use clippy_utils::source::snippet_with_macro_callsite;
33
use clippy_utils::ty::{has_drop, is_copy};
4-
use clippy_utils::{any_parent_is_automatically_derived, contains_name, get_parent_expr, match_def_path, paths};
4+
use clippy_utils::{
5+
any_parent_is_automatically_derived, contains_name, get_parent_expr, is_from_proc_macro, match_def_path, paths,
6+
};
57
use if_chain::if_chain;
68
use rustc_data_structures::fx::FxHashSet;
79
use rustc_errors::Applicability;
@@ -94,6 +96,7 @@ impl<'tcx> LateLintPass<'tcx> for Default {
9496
if let QPath::Resolved(None, _path) = qpath;
9597
let expr_ty = cx.typeck_results().expr_ty(expr);
9698
if let ty::Adt(def, ..) = expr_ty.kind();
99+
if !is_from_proc_macro(cx, expr);
97100
then {
98101
// TODO: Work out a way to put "whatever the imported way of referencing
99102
// this type in this file" rather than a fully-qualified type.

0 commit comments

Comments
 (0)