Skip to content

Commit 6c8927b

Browse files
committed
Auto merge of #74792 - flip1995:clippyup, r=Manishearth
Update Clippy Biweekly Clippy Sync r? @Manishearth
2 parents 6239296 + e4e1b8c commit 6c8927b

Some content is hidden

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

54 files changed

+840
-259
lines changed

src/tools/clippy/.github/deploy.sh

+15-6
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fi
1919

2020
if [[ $BETA = "true" ]]; then
2121
echo "Update documentation for the beta release"
22-
cp -r out/master out/beta
22+
cp -r out/master/* out/beta
2323
fi
2424

2525
# Generate version index that is shown as root index page
@@ -33,12 +33,13 @@ cd out
3333
git config user.name "GHA CI"
3434
git config user.email "[email protected]"
3535

36-
if git diff --exit-code --quiet; then
37-
echo "No changes to the output on this push; exiting."
38-
exit 0
39-
fi
40-
4136
if [[ -n $TAG_NAME ]]; then
37+
# track files, so that the following check works
38+
git add --intent-to-add "$TAG_NAME"
39+
if git diff --exit-code --quiet -- $TAG_NAME/; then
40+
echo "No changes to the output on this push; exiting."
41+
exit 0
42+
fi
4243
# Add the new dir
4344
git add "$TAG_NAME"
4445
# Update the symlink
@@ -47,9 +48,17 @@ if [[ -n $TAG_NAME ]]; then
4748
git add versions.json
4849
git commit -m "Add documentation for ${TAG_NAME} release: ${SHA}"
4950
elif [[ $BETA = "true" ]]; then
51+
if git diff --exit-code --quiet -- beta/; then
52+
echo "No changes to the output on this push; exiting."
53+
exit 0
54+
fi
5055
git add beta
5156
git commit -m "Automatic deploy to GitHub Pages (beta): ${SHA}"
5257
else
58+
if git diff --exit-code --quiet; then
59+
echo "No changes to the output on this push; exiting."
60+
exit 0
61+
fi
5362
git add .
5463
git commit -m "Automatic deploy to GitHub Pages: ${SHA}"
5564
fi

src/tools/clippy/CHANGELOG.md

+67-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,78 @@
1-
# Change Log
1+
# Changelog
22

33
All notable changes to this project will be documented in this file.
44
See [Changelog Update](doc/changelog_update.md) if you want to update this
55
document.
66

77
## Unreleased / In Rust Nightly
88

9-
[7ea7cd1...master](https://github.com/rust-lang/rust-clippy/compare/7ea7cd1...master)
9+
[c2c07fa...master](https://github.com/rust-lang/rust-clippy/compare/7ea7cd1...master)
10+
11+
## Rust 1.46
12+
13+
Current beta, release 2020-08-27
14+
15+
[7ea7cd1...c2c07fa](https://github.com/rust-lang/rust-clippy/compare/7ea7cd1...master)
16+
17+
### New lints
18+
19+
* [`unnested_or_patterns`] [#5378](https://github.com/rust-lang/rust-clippy/pull/5378)
20+
* [`iter_next_slice`] [#5597](https://github.com/rust-lang/rust-clippy/pull/5597)
21+
* [`unnecessary_sort_by`] [#5623](https://github.com/rust-lang/rust-clippy/pull/5623)
22+
* [`vec_resize_to_zero`] [#5637](https://github.com/rust-lang/rust-clippy/pull/5637)
23+
24+
### Moves and Deprecations
25+
26+
* Move [`cast_ptr_alignment`] to pedantic [#5667](https://github.com/rust-lang/rust-clippy/pull/5667)
27+
28+
### Enhancements
29+
30+
* Improve [`mem_replace_with_uninit`] lint [#5695](https://github.com/rust-lang/rust-clippy/pull/5695)
31+
32+
### False Positive Fixes
33+
34+
* [`len_zero`]: Avoid linting ranges when the `range_is_empty` feature is not enabled
35+
[#5656](https://github.com/rust-lang/rust-clippy/pull/5656)
36+
* [`let_and_return`]: Don't lint if a temporary borrow is involved
37+
[#5680](https://github.com/rust-lang/rust-clippy/pull/5680)
38+
* [`reversed_empty_ranges`]: Avoid linting `N..N` in for loop arguments in
39+
[#5692](https://github.com/rust-lang/rust-clippy/pull/5692)
40+
* [`if_same_then_else`]: Don't assume multiplication is always commutative
41+
[#5702](https://github.com/rust-lang/rust-clippy/pull/5702)
42+
* [`blacklisted_name`]: Remove `bar` from the default configuration
43+
[#5712](https://github.com/rust-lang/rust-clippy/pull/5712)
44+
* [`redundant_pattern_matching`]: Avoid suggesting non-`const fn` calls in const contexts
45+
[#5724](https://github.com/rust-lang/rust-clippy/pull/5724)
46+
47+
### Suggestion Fixes/Improvements
48+
49+
* Fix suggestion of [`unit_arg`] lint, so that it suggest semantic equivalent code
50+
[#4455](https://github.com/rust-lang/rust-clippy/pull/4455)
51+
* Add auto applicable suggestion to [`macro_use_imports`]
52+
[#5279](https://github.com/rust-lang/rust-clippy/pull/5279)
53+
54+
### ICE Fixes
55+
56+
* Fix ICE in the `consts` module of Clippy [#5709](https://github.com/rust-lang/rust-clippy/pull/5709)
57+
58+
### Documentation Improvements
59+
60+
* Improve code examples across multiple lints [#5664](https://github.com/rust-lang/rust-clippy/pull/5664)
61+
62+
### Others
63+
64+
* Introduce a `--rustc` flag to `clippy-driver`, which turns `clippy-driver`
65+
into `rustc` and passes all the given arguments to `rustc`. This is especially
66+
useful for tools that need the `rustc` version Clippy was compiled with,
67+
instead of the Clippy version. E.g. `clippy-driver --rustc --version` will
68+
print the output of `rustc --version`.
69+
[#5178](https://github.com/rust-lang/rust-clippy/pull/5178)
70+
* New issue templates now make it easier to complain if Clippy is too annoying
71+
or not annoying enough! [#5735](https://github.com/rust-lang/rust-clippy/pull/5735)
1072

1173
## Rust 1.45
1274

13-
Current beta, release 2020-07-16
75+
Current stable, released 2020-07-16
1476

1577
[891e1a8...7ea7cd1](https://github.com/rust-lang/rust-clippy/compare/891e1a8...7ea7cd1)
1678

@@ -87,7 +149,7 @@ and [`similar_names`]. [#5651](https://github.com/rust-lang/rust-clippy/pull/565
87149

88150
## Rust 1.44
89151

90-
Current stable, released 2020-06-04
152+
Released 2020-06-04
91153

92154
[204bb9b...891e1a8](https://github.com/rust-lang/rust-clippy/compare/204bb9b...891e1a8)
93155

@@ -1679,6 +1741,7 @@ Released 2018-09-13
16791741
[`uninit_assumed_init`]: https://rust-lang.github.io/rust-clippy/master/index.html#uninit_assumed_init
16801742
[`unit_arg`]: https://rust-lang.github.io/rust-clippy/master/index.html#unit_arg
16811743
[`unit_cmp`]: https://rust-lang.github.io/rust-clippy/master/index.html#unit_cmp
1744+
[`unit_return_expecting_ord`]: https://rust-lang.github.io/rust-clippy/master/index.html#unit_return_expecting_ord
16821745
[`unknown_clippy_lints`]: https://rust-lang.github.io/rust-clippy/master/index.html#unknown_clippy_lints
16831746
[`unnecessary_cast`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast
16841747
[`unnecessary_filter_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_filter_map

src/tools/clippy/README.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,8 @@ Table of contents:
4242

4343
## Usage
4444

45-
Since this is a tool for helping the developer of a library or application
46-
write better code, it is recommended not to include Clippy as a hard dependency.
47-
Options include using it as an optional dependency, as a cargo subcommand, or
48-
as an included feature during build. These options are detailed below.
45+
Below are instructions on how to use Clippy as a subcommand, compiled from source
46+
or in Travis CI.
4947

5048
### As a cargo subcommand (`cargo clippy`)
5149

src/tools/clippy/clippy_lints/src/deprecated_lints.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ declare_deprecated_lint! {
153153
///
154154
/// **Deprecation reason:** Associated-constants are now preferred.
155155
pub REPLACE_CONSTS,
156-
"associated-constants `MIN`/`MAX` of integers are prefered to `{min,max}_value()` and module constants"
156+
"associated-constants `MIN`/`MAX` of integers are preferred to `{min,max}_value()` and module constants"
157157
}
158158

159159
declare_deprecated_lint! {

src/tools/clippy/clippy_lints/src/dereference.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_span::source_map::Span;
1010
declare_clippy_lint! {
1111
/// **What it does:** Checks for explicit `deref()` or `deref_mut()` method calls.
1212
///
13-
/// **Why is this bad?** Derefencing by `&*x` or `&mut *x` is clearer and more concise,
13+
/// **Why is this bad?** Dereferencing by `&*x` or `&mut *x` is clearer and more concise,
1414
/// when not part of a method chain.
1515
///
1616
/// **Example:**

src/tools/clippy/clippy_lints/src/inherent_impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl<'tcx> LateLintPass<'tcx> for MultipleInherentImpl {
5555
..
5656
} = item.kind
5757
{
58-
// Remember for each inherent implementation encoutered its span and generics
58+
// Remember for each inherent implementation encountered its span and generics
5959
// but filter out implementations that have generic params (type or lifetime)
6060
// or are derived from a macro
6161
if !in_macro(item.span) && generics.params.is_empty() {

src/tools/clippy/clippy_lints/src/lib.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ mod ptr_offset_with_cast;
276276
mod question_mark;
277277
mod ranges;
278278
mod redundant_clone;
279+
mod redundant_closure_call;
279280
mod redundant_field_names;
280281
mod redundant_pub_crate;
281282
mod redundant_static_lifetimes;
@@ -300,6 +301,7 @@ mod trivially_copy_pass_by_ref;
300301
mod try_err;
301302
mod types;
302303
mod unicode;
304+
mod unit_return_expecting_ord;
303305
mod unnamed_address;
304306
mod unnecessary_sort_by;
305307
mod unnested_or_patterns;
@@ -462,7 +464,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
462464
);
463465
store.register_removed(
464466
"clippy::replace_consts",
465-
"associated-constants `MIN`/`MAX` of integers are prefered to `{min,max}_value()` and module constants",
467+
"associated-constants `MIN`/`MAX` of integers are preferred to `{min,max}_value()` and module constants",
466468
);
467469
store.register_removed(
468470
"clippy::regex_macro",
@@ -701,7 +703,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
701703
&misc_early::DOUBLE_NEG,
702704
&misc_early::DUPLICATE_UNDERSCORE_ARGUMENT,
703705
&misc_early::MIXED_CASE_HEX_LITERALS,
704-
&misc_early::REDUNDANT_CLOSURE_CALL,
705706
&misc_early::REDUNDANT_PATTERN,
706707
&misc_early::UNNEEDED_FIELD_PATTERN,
707708
&misc_early::UNNEEDED_WILDCARD_PATTERN,
@@ -758,6 +759,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
758759
&ranges::RANGE_ZIP_WITH_LEN,
759760
&ranges::REVERSED_EMPTY_RANGES,
760761
&redundant_clone::REDUNDANT_CLONE,
762+
&redundant_closure_call::REDUNDANT_CLOSURE_CALL,
761763
&redundant_field_names::REDUNDANT_FIELD_NAMES,
762764
&redundant_pub_crate::REDUNDANT_PUB_CRATE,
763765
&redundant_static_lifetimes::REDUNDANT_STATIC_LIFETIMES,
@@ -826,6 +828,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
826828
&unicode::NON_ASCII_LITERAL,
827829
&unicode::UNICODE_NOT_NFC,
828830
&unicode::ZERO_WIDTH_SPACE,
831+
&unit_return_expecting_ord::UNIT_RETURN_EXPECTING_ORD,
829832
&unnamed_address::FN_ADDRESS_COMPARISONS,
830833
&unnamed_address::VTABLE_ADDRESS_COMPARISONS,
831834
&unnecessary_sort_by::UNNECESSARY_SORT_BY,
@@ -891,6 +894,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
891894
store.register_late_pass(|| box attrs::Attributes);
892895
store.register_late_pass(|| box blocks_in_if_conditions::BlocksInIfConditions);
893896
store.register_late_pass(|| box unicode::Unicode);
897+
store.register_late_pass(|| box unit_return_expecting_ord::UnitReturnExpectingOrd);
894898
store.register_late_pass(|| box strings::StringAdd);
895899
store.register_late_pass(|| box implicit_return::ImplicitReturn);
896900
store.register_late_pass(|| box implicit_saturating_sub::ImplicitSaturatingSub);
@@ -1015,6 +1019,8 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
10151019
store.register_early_pass(|| box int_plus_one::IntPlusOne);
10161020
store.register_early_pass(|| box formatting::Formatting);
10171021
store.register_early_pass(|| box misc_early::MiscEarlyLints);
1022+
store.register_early_pass(|| box redundant_closure_call::RedundantClosureCall);
1023+
store.register_late_pass(|| box redundant_closure_call::RedundantClosureCall);
10181024
store.register_early_pass(|| box returns::Return);
10191025
store.register_late_pass(|| box let_and_return::LetReturn);
10201026
store.register_early_pass(|| box collapsible_if::CollapsibleIf);
@@ -1356,7 +1362,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
13561362
LintId::of(&misc_early::DOUBLE_NEG),
13571363
LintId::of(&misc_early::DUPLICATE_UNDERSCORE_ARGUMENT),
13581364
LintId::of(&misc_early::MIXED_CASE_HEX_LITERALS),
1359-
LintId::of(&misc_early::REDUNDANT_CLOSURE_CALL),
13601365
LintId::of(&misc_early::REDUNDANT_PATTERN),
13611366
LintId::of(&misc_early::UNNEEDED_WILDCARD_PATTERN),
13621367
LintId::of(&misc_early::ZERO_PREFIXED_LITERAL),
@@ -1390,6 +1395,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
13901395
LintId::of(&ranges::RANGE_ZIP_WITH_LEN),
13911396
LintId::of(&ranges::REVERSED_EMPTY_RANGES),
13921397
LintId::of(&redundant_clone::REDUNDANT_CLONE),
1398+
LintId::of(&redundant_closure_call::REDUNDANT_CLOSURE_CALL),
13931399
LintId::of(&redundant_field_names::REDUNDANT_FIELD_NAMES),
13941400
LintId::of(&redundant_static_lifetimes::REDUNDANT_STATIC_LIFETIMES),
13951401
LintId::of(&reference::DEREF_ADDROF),
@@ -1436,6 +1442,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
14361442
LintId::of(&types::UNNECESSARY_CAST),
14371443
LintId::of(&types::VEC_BOX),
14381444
LintId::of(&unicode::ZERO_WIDTH_SPACE),
1445+
LintId::of(&unit_return_expecting_ord::UNIT_RETURN_EXPECTING_ORD),
14391446
LintId::of(&unnamed_address::FN_ADDRESS_COMPARISONS),
14401447
LintId::of(&unnamed_address::VTABLE_ADDRESS_COMPARISONS),
14411448
LintId::of(&unnecessary_sort_by::UNNECESSARY_SORT_BY),
@@ -1589,7 +1596,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
15891596
LintId::of(&methods::UNNECESSARY_FILTER_MAP),
15901597
LintId::of(&methods::USELESS_ASREF),
15911598
LintId::of(&misc::SHORT_CIRCUIT_STATEMENT),
1592-
LintId::of(&misc_early::REDUNDANT_CLOSURE_CALL),
15931599
LintId::of(&misc_early::UNNEEDED_WILDCARD_PATTERN),
15941600
LintId::of(&misc_early::ZERO_PREFIXED_LITERAL),
15951601
LintId::of(&needless_bool::BOOL_COMPARISON),
@@ -1604,6 +1610,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
16041610
LintId::of(&precedence::PRECEDENCE),
16051611
LintId::of(&ptr_offset_with_cast::PTR_OFFSET_WITH_CAST),
16061612
LintId::of(&ranges::RANGE_ZIP_WITH_LEN),
1613+
LintId::of(&redundant_closure_call::REDUNDANT_CLOSURE_CALL),
16071614
LintId::of(&reference::DEREF_ADDROF),
16081615
LintId::of(&reference::REF_IN_DEREF),
16091616
LintId::of(&repeat_once::REPEAT_ONCE),
@@ -1692,6 +1699,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
16921699
LintId::of(&types::CAST_REF_TO_MUT),
16931700
LintId::of(&types::UNIT_CMP),
16941701
LintId::of(&unicode::ZERO_WIDTH_SPACE),
1702+
LintId::of(&unit_return_expecting_ord::UNIT_RETURN_EXPECTING_ORD),
16951703
LintId::of(&unnamed_address::FN_ADDRESS_COMPARISONS),
16961704
LintId::of(&unnamed_address::VTABLE_ADDRESS_COMPARISONS),
16971705
LintId::of(&unused_io_amount::UNUSED_IO_AMOUNT),

src/tools/clippy/clippy_lints/src/matches.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -1512,6 +1512,10 @@ mod redundant_pattern_match {
15121512
}
15131513
}
15141514

1515+
let result_expr = match &op.kind {
1516+
ExprKind::AddrOf(_, _, borrowed) => borrowed,
1517+
_ => op,
1518+
};
15151519
span_lint_and_then(
15161520
cx,
15171521
REDUNDANT_PATTERN_MATCHING,
@@ -1524,7 +1528,7 @@ mod redundant_pattern_match {
15241528

15251529
// while let ... = ... { ... }
15261530
// ^^^
1527-
let op_span = op.span.source_callsite();
1531+
let op_span = result_expr.span.source_callsite();
15281532

15291533
// while let ... = ... { ... }
15301534
// ^^^^^^^^^^^^^^^^^^^
@@ -1589,17 +1593,21 @@ mod redundant_pattern_match {
15891593
};
15901594

15911595
if let Some(good_method) = found_good_method {
1596+
let span = expr.span.to(op.span);
1597+
let result_expr = match &op.kind {
1598+
ExprKind::AddrOf(_, _, borrowed) => borrowed,
1599+
_ => op,
1600+
};
15921601
span_lint_and_then(
15931602
cx,
15941603
REDUNDANT_PATTERN_MATCHING,
15951604
expr.span,
15961605
&format!("redundant pattern matching, consider using `{}`", good_method),
15971606
|diag| {
1598-
let span = expr.span.to(op.span);
15991607
diag.span_suggestion(
16001608
span,
16011609
"try this",
1602-
format!("{}.{}", snippet(cx, op.span, "_"), good_method),
1610+
format!("{}.{}", snippet(cx, result_expr.span, "_"), good_method),
16031611
Applicability::MaybeIncorrect, // snippet
16041612
);
16051613
},

src/tools/clippy/clippy_lints/src/methods/mod.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -2354,8 +2354,8 @@ fn lint_iter_nth_zero<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, nth_ar
23542354
cx,
23552355
ITER_NTH_ZERO,
23562356
expr.span,
2357-
"called `.nth(0)` on a `std::iter::Iterator`",
2358-
"try calling",
2357+
"called `.nth(0)` on a `std::iter::Iterator`, when `.next()` is equivalent",
2358+
"try calling `.next()` instead of `.nth(0)`",
23592359
format!("{}.next()", snippet_with_applicability(cx, nth_args[0].span, "..", &mut applicability)),
23602360
applicability,
23612361
);
@@ -3290,7 +3290,12 @@ fn lint_option_as_ref_deref<'tcx>(
32903290
if let hir::ExprKind::Path(qpath) = &args[0].kind;
32913291
if let hir::def::Res::Local(local_id) = cx.qpath_res(qpath, args[0].hir_id);
32923292
if closure_body.params[0].pat.hir_id == local_id;
3293-
let adj = cx.typeck_results().expr_adjustments(&args[0]).iter().map(|x| &x.kind).collect::<Box<[_]>>();
3293+
let adj = cx
3294+
.typeck_results()
3295+
.expr_adjustments(&args[0])
3296+
.iter()
3297+
.map(|x| &x.kind)
3298+
.collect::<Box<[_]>>();
32943299
if let [ty::adjustment::Adjust::Deref(None), ty::adjustment::Adjust::Borrow(_)] = *adj;
32953300
then {
32963301
let method_did = cx.typeck_results().type_dependent_def_id(closure_expr.hir_id).unwrap();

src/tools/clippy/clippy_lints/src/misc.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ declare_clippy_lint! {
9999
/// if y != x {} // where both are floats
100100
///
101101
/// // Good
102-
/// let error = 0.01f64; // Use an epsilon for comparison
102+
/// let error = f64::EPSILON; // Use an epsilon for comparison
103+
/// // Or, if Rust <= 1.42, use `std::f64::EPSILON` constant instead.
104+
/// // let error = std::f64::EPSILON;
103105
/// if (y - 1.23f64).abs() < error { }
104106
/// if (y - x).abs() > error { }
105107
/// ```
@@ -237,10 +239,12 @@ declare_clippy_lint! {
237239
/// const ONE: f64 = 1.00;
238240
///
239241
/// // Bad
240-
/// if x == ONE { } // where both are floats
242+
/// if x == ONE { } // where both are floats
241243
///
242244
/// // Good
243-
/// let error = 0.1f64; // Use an epsilon for comparison
245+
/// let error = f64::EPSILON; // Use an epsilon for comparison
246+
/// // Or, if Rust <= 1.42, use `std::f64::EPSILON` constant instead.
247+
/// // let error = std::f64::EPSILON;
244248
/// if (x - ONE).abs() < error { }
245249
/// ```
246250
pub FLOAT_CMP_CONST,

0 commit comments

Comments
 (0)