Skip to content

Commit fe8ab8a

Browse files
committed
Auto merge of #76034 - flip1995:clippyup, r=Manishearth
Update Clippy Bi-weekly Clippy update, as per the [new policy](https://github.com/rust-lang/rust-clippy/blob/master/CONTRIBUTING.md#syncing-back-changes-in-clippy-to-rust-langrust). r? @Manishearth
2 parents 286a346 + 575e27d commit fe8ab8a

File tree

155 files changed

+4164
-1096
lines changed

Some content is hidden

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

155 files changed

+4164
-1096
lines changed

Cargo.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -518,15 +518,15 @@ dependencies = [
518518
name = "clippy"
519519
version = "0.0.212"
520520
dependencies = [
521-
"cargo_metadata 0.9.1",
521+
"cargo_metadata 0.11.1",
522522
"clippy-mini-macro-test",
523523
"clippy_lints",
524524
"compiletest_rs",
525525
"derive-new",
526526
"lazy_static",
527527
"rustc-workspace-hack",
528528
"rustc_tools_util 0.2.0",
529-
"semver 0.9.0",
529+
"semver 0.10.0",
530530
"serde",
531531
"tempfile",
532532
"tester",
@@ -540,15 +540,15 @@ version = "0.2.0"
540540
name = "clippy_lints"
541541
version = "0.0.212"
542542
dependencies = [
543-
"cargo_metadata 0.9.1",
543+
"cargo_metadata 0.11.1",
544544
"if_chain",
545545
"itertools 0.9.0",
546546
"lazy_static",
547547
"pulldown-cmark",
548548
"quine-mc_cluskey",
549549
"quote",
550550
"regex-syntax",
551-
"semver 0.9.0",
551+
"semver 0.10.0",
552552
"serde",
553553
"smallvec 1.4.2",
554554
"syn",

src/tools/clippy/.cargo/config

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[alias]
22
uitest = "test --test compile-test"
3-
dev = "run --package clippy_dev --bin clippy_dev --manifest-path clippy_dev/Cargo.toml --"
3+
dev = "run --target-dir clippy_dev/target --package clippy_dev --bin clippy_dev --manifest-path clippy_dev/Cargo.toml --"
44

55
[build]
66
rustflags = ["-Zunstable-options"]

src/tools/clippy/.github/workflows/clippy.yml

+7
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ jobs:
9292
env:
9393
OS: ${{ runner.os }}
9494

95+
- name: Test cargo dev new lint
96+
run: |
97+
cargo dev new_lint --name new_early_pass --pass early
98+
cargo dev new_lint --name new_late_pass --pass late
99+
cargo check
100+
git reset --hard HEAD
101+
95102
# Cleanup
96103
- name: Run cargo-cache --autoclean
97104
run: |

src/tools/clippy/CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1498,6 +1498,7 @@ Released 2018-09-13
14981498
[`float_arithmetic`]: https://rust-lang.github.io/rust-clippy/master/index.html#float_arithmetic
14991499
[`float_cmp`]: https://rust-lang.github.io/rust-clippy/master/index.html#float_cmp
15001500
[`float_cmp_const`]: https://rust-lang.github.io/rust-clippy/master/index.html#float_cmp_const
1501+
[`float_equality_without_abs`]: https://rust-lang.github.io/rust-clippy/master/index.html#float_equality_without_abs
15011502
[`fn_address_comparisons`]: https://rust-lang.github.io/rust-clippy/master/index.html#fn_address_comparisons
15021503
[`fn_params_excessive_bools`]: https://rust-lang.github.io/rust-clippy/master/index.html#fn_params_excessive_bools
15031504
[`fn_to_numeric_cast`]: https://rust-lang.github.io/rust-clippy/master/index.html#fn_to_numeric_cast
@@ -1690,6 +1691,7 @@ Released 2018-09-13
16901691
[`same_functions_in_if_condition`]: https://rust-lang.github.io/rust-clippy/master/index.html#same_functions_in_if_condition
16911692
[`same_item_push`]: https://rust-lang.github.io/rust-clippy/master/index.html#same_item_push
16921693
[`search_is_some`]: https://rust-lang.github.io/rust-clippy/master/index.html#search_is_some
1694+
[`self_assignment`]: https://rust-lang.github.io/rust-clippy/master/index.html#self_assignment
16931695
[`serde_api_misuse`]: https://rust-lang.github.io/rust-clippy/master/index.html#serde_api_misuse
16941696
[`shadow_reuse`]: https://rust-lang.github.io/rust-clippy/master/index.html#shadow_reuse
16951697
[`shadow_same`]: https://rust-lang.github.io/rust-clippy/master/index.html#shadow_same
@@ -1699,6 +1701,7 @@ Released 2018-09-13
16991701
[`should_implement_trait`]: https://rust-lang.github.io/rust-clippy/master/index.html#should_implement_trait
17001702
[`similar_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#similar_names
17011703
[`single_char_pattern`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_char_pattern
1704+
[`single_char_push_str`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_char_push_str
17021705
[`single_component_path_imports`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_component_path_imports
17031706
[`single_match`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_match
17041707
[`single_match_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_match_else
@@ -1723,6 +1726,7 @@ Released 2018-09-13
17231726
[`temporary_assignment`]: https://rust-lang.github.io/rust-clippy/master/index.html#temporary_assignment
17241727
[`temporary_cstring_as_ptr`]: https://rust-lang.github.io/rust-clippy/master/index.html#temporary_cstring_as_ptr
17251728
[`to_digit_is_some`]: https://rust-lang.github.io/rust-clippy/master/index.html#to_digit_is_some
1729+
[`to_string_in_display`]: https://rust-lang.github.io/rust-clippy/master/index.html#to_string_in_display
17261730
[`todo`]: https://rust-lang.github.io/rust-clippy/master/index.html#todo
17271731
[`too_many_arguments`]: https://rust-lang.github.io/rust-clippy/master/index.html#too_many_arguments
17281732
[`too_many_lines`]: https://rust-lang.github.io/rust-clippy/master/index.html#too_many_lines
@@ -1752,6 +1756,7 @@ Released 2018-09-13
17521756
[`unnecessary_cast`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast
17531757
[`unnecessary_filter_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_filter_map
17541758
[`unnecessary_fold`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_fold
1759+
[`unnecessary_lazy_evaluations`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_lazy_evaluations
17551760
[`unnecessary_mut_passed`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_mut_passed
17561761
[`unnecessary_operation`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_operation
17571762
[`unnecessary_sort_by`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_sort_by
@@ -1773,6 +1778,7 @@ Released 2018-09-13
17731778
[`unused_label`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_label
17741779
[`unused_self`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_self
17751780
[`unused_unit`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_unit
1781+
[`unwrap_in_result`]: https://rust-lang.github.io/rust-clippy/master/index.html#unwrap_in_result
17761782
[`unwrap_used`]: https://rust-lang.github.io/rust-clippy/master/index.html#unwrap_used
17771783
[`use_debug`]: https://rust-lang.github.io/rust-clippy/master/index.html#use_debug
17781784
[`use_self`]: https://rust-lang.github.io/rust-clippy/master/index.html#use_self

src/tools/clippy/CONTRIBUTING.md

+49-9
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,35 @@ Clippy in the `rust-lang/rust` repository.
189189
For general information about `subtree`s in the Rust repository see [Rust's
190190
`CONTRIBUTING.md`][subtree].
191191

192+
### Patching git-subtree to work with big repos
193+
194+
Currently there's a bug in `git-subtree` that prevents it from working properly
195+
with the [`rust-lang/rust`] repo. There's an open PR to fix that, but it's stale.
196+
Before continuing with the following steps, we need to manually apply that fix to
197+
our local copy of `git-subtree`.
198+
199+
You can get the patched version of `git-subtree` from [here][gitgitgadget-pr].
200+
Put this file under `/usr/lib/git-core` (taking a backup of the previous file)
201+
and make sure it has the proper permissions:
202+
203+
```bash
204+
sudo cp --backup /path/to/patched/git-subtree.sh /usr/lib/git-core/git-subtree
205+
sudo chmod --reference=/usr/lib/git-core/git-subtree~ /usr/lib/git-core/git-subtree
206+
sudo chown --reference=/usr/lib/git-core/git-subtree~ /usr/lib/git-core/git-subtree
207+
```
208+
209+
_Note:_ The first time running `git subtree push` a cache has to be built. This
210+
involves going through the complete Clippy history once. For this you have to
211+
increase the stack limit though, which you can do with `ulimit -s 60000`.
212+
Make sure to run the `ulimit` command from the same session you call git subtree.
213+
214+
_Note:_ If you are a Debian user, `dash` is the shell used by default for scripts instead of `sh`.
215+
This shell has a hardcoded recursion limit set to 1000. In order to make this process work,
216+
you need to force the script to run `bash` instead. You can do this by editing the first
217+
line of the `git-subtree` script and changing `sh` to `bash`.
218+
219+
### Performing the sync
220+
192221
Here is a TL;DR version of the sync process (all of the following commands have
193222
to be run inside the `rust` directory):
194223

@@ -198,6 +227,7 @@ to be run inside the `rust` directory):
198227
# Make sure to change `your-github-name` to your github name in the following command
199228
git subtree push -P src/tools/clippy git@github.com:your-github-name/rust-clippy sync-from-rust
200229
```
230+
201231
_Note:_ This will directly push to the remote repository. You can also push
202232
to your local copy by replacing the remote address with `/path/to/rust-clippy`
203233
directory.
@@ -213,14 +243,30 @@ to be run inside the `rust` directory):
213243
3. Open a PR to `rust-lang/rust-clippy` and wait for it to get merged (to
214244
accelerate the process ping the `@rust-lang/clippy` team in your PR and/or
215245
~~annoy~~ ask them in the [Discord] channel.)
216-
4. Sync the `rust-lang/rust-clippy` master to the rust-copy of Clippy:
246+
247+
### Syncing back changes in Clippy to [`rust-lang/rust`]
248+
249+
To avoid flooding the [`rust-lang/rust`] PR queue, changes in Clippy's repo are synced back
250+
in a bi-weekly basis if there's no urgent changes. This is done starting on the day of
251+
the Rust stable release and then every other week. That way we guarantee that
252+
every feature in Clippy is available for 2 weeks in nightly, before it can get to beta.
253+
For reference, the first sync following this cadence was performed the 2020-08-27.
254+
255+
All of the following commands have to be run inside the `rust` directory.
256+
257+
1. Make sure Clippy itself is up-to-date by following the steps outlined in the previous
258+
section if necessary.
259+
260+
2. Sync the `rust-lang/rust-clippy` master to the rust-copy of Clippy:
217261
```bash
218262
git checkout -b sync-from-clippy
219263
git subtree pull -P src/tools/clippy https://github.com/rust-lang/rust-clippy master
220264
```
221-
5. Open a PR to [`rust-lang/rust`]
265+
3. Open a PR to [`rust-lang/rust`]
266+
267+
### Defining remotes
222268

223-
Also, you may want to define remotes, so you don't have to type out the remote
269+
You may want to define remotes, so you don't have to type out the remote
224270
addresses on every sync. You can do this with the following commands (these
225271
commands still have to be run inside the `rust` directory):
226272
@@ -241,12 +287,6 @@ You can then sync with the remote names from above, e.g.:
241287
$ git subtree push -P src/tools/clippy clippy-local sync-from-rust
242288
```
243289
244-
_Note:_ The first time running `git subtree push` a cache has to be built. This
245-
involves going through the complete Clippy history once. For this you have to
246-
increase the stack limit though, which you can do with `ulimit -s 60000`. For
247-
this to work, you will need the fix of `git subtree` available
248-
[here][gitgitgadget-pr].
249-
250290
[gitgitgadget-pr]: https://github.com/gitgitgadget/git/pull/493
251291
[subtree]: https://rustc-dev-guide.rust-lang.org/contributing.html#external-dependencies-subtree
252292
[`rust-lang/rust`]: https://github.com/rust-lang/rust

src/tools/clippy/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ path = "src/driver.rs"
3131
# begin automatic update
3232
clippy_lints = { version = "0.0.212", path = "clippy_lints" }
3333
# end automatic update
34-
semver = "0.9"
34+
semver = "0.10"
3535
rustc_tools_util = { version = "0.2.0", path = "rustc_tools_util"}
3636
tempfile = { version = "3.1.0", optional = true }
3737
lazy_static = "1.0"
3838

3939
[dev-dependencies]
40-
cargo_metadata = "0.9.1"
40+
cargo_metadata = "0.11.1"
4141
compiletest_rs = { version = "0.5.0", features = ["tmp"] }
4242
tester = "0.7"
4343
lazy_static = "1.0"

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub fn create(pass: Option<&str>, lint_name: Option<&str>, category: Option<&str
4747
fn create_lint(lint: &LintData) -> io::Result<()> {
4848
let (pass_type, pass_lifetimes, pass_import, context_import) = match lint.pass {
4949
"early" => ("EarlyLintPass", "", "use rustc_ast::ast::*;", "EarlyContext"),
50-
"late" => ("LateLintPass", "<'_, '_>", "use rustc_hir::*;", "LateContext"),
50+
"late" => ("LateLintPass", "<'_>", "use rustc_hir::*;", "LateContext"),
5151
_ => {
5252
unreachable!("`pass_type` should only ever be `early` or `late`!");
5353
},

src/tools/clippy/clippy_lints/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ keywords = ["clippy", "lint", "plugin"]
1717
edition = "2018"
1818

1919
[dependencies]
20-
cargo_metadata = "0.9.1"
20+
cargo_metadata = "0.11.1"
2121
if_chain = "1.0.0"
2222
itertools = "0.9"
2323
lazy_static = "1.0.2"
@@ -28,7 +28,7 @@ serde = { version = "1.0", features = ["derive"] }
2828
smallvec = { version = "1", features = ["union"] }
2929
toml = "0.5.3"
3030
unicode-normalization = "0.1"
31-
semver = "0.9.0"
31+
semver = "0.10.0"
3232
# NOTE: cargo requires serde feat in its url dep
3333
# see <https://github.com/rust-lang/rust/pull/63587#issuecomment-522343864>
3434
url = { version = "2.1.0", features = ["serde"] }

src/tools/clippy/clippy_lints/src/assign_ops.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::utils::{
2-
get_trait_def_id, implements_trait, snippet_opt, span_lint_and_then, trait_ref_of_method, SpanlessEq,
2+
eq_expr_value, get_trait_def_id, implements_trait, snippet_opt, span_lint_and_then, trait_ref_of_method,
33
};
44
use crate::utils::{higher, sugg};
55
use if_chain::if_chain;
@@ -70,11 +70,11 @@ impl<'tcx> LateLintPass<'tcx> for AssignOps {
7070
return;
7171
}
7272
// lhs op= l op r
73-
if SpanlessEq::new(cx).ignore_fn().eq_expr(lhs, l) {
73+
if eq_expr_value(cx, lhs, l) {
7474
lint_misrefactored_assign_op(cx, expr, *op, rhs, lhs, r);
7575
}
7676
// lhs op= l commutative_op r
77-
if is_commutative(op.node) && SpanlessEq::new(cx).ignore_fn().eq_expr(lhs, r) {
77+
if is_commutative(op.node) && eq_expr_value(cx, lhs, r) {
7878
lint_misrefactored_assign_op(cx, expr, *op, rhs, lhs, l);
7979
}
8080
}
@@ -161,14 +161,12 @@ impl<'tcx> LateLintPass<'tcx> for AssignOps {
161161

162162
if visitor.counter == 1 {
163163
// a = a op b
164-
if SpanlessEq::new(cx).ignore_fn().eq_expr(assignee, l) {
164+
if eq_expr_value(cx, assignee, l) {
165165
lint(assignee, r);
166166
}
167167
// a = b commutative_op a
168168
// Limited to primitive type as these ops are know to be commutative
169-
if SpanlessEq::new(cx).ignore_fn().eq_expr(assignee, r)
170-
&& cx.typeck_results().expr_ty(assignee).is_primitive_ty()
171-
{
169+
if eq_expr_value(cx, assignee, r) && cx.typeck_results().expr_ty(assignee).is_primitive_ty() {
172170
match op.node {
173171
hir::BinOpKind::Add
174172
| hir::BinOpKind::Mul
@@ -253,7 +251,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ExprVisitor<'a, 'tcx> {
253251
type Map = Map<'tcx>;
254252

255253
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) {
256-
if SpanlessEq::new(self.cx).ignore_fn().eq_expr(self.assignee, expr) {
254+
if eq_expr_value(self.cx, self.assignee, expr) {
257255
self.counter += 1;
258256
}
259257

src/tools/clippy/clippy_lints/src/attrs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use crate::utils::{
55
span_lint_and_sugg, span_lint_and_then, without_block_comments,
66
};
77
use if_chain::if_chain;
8-
use rustc_ast::{AttrKind, AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem};
98
use rustc_ast::util::lev_distance::find_best_match_for_name;
9+
use rustc_ast::{AttrKind, AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem};
1010
use rustc_errors::Applicability;
1111
use rustc_hir::{
1212
Block, Expr, ExprKind, ImplItem, ImplItemKind, Item, ItemKind, StmtKind, TraitFn, TraitItem, TraitItemKind,

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::utils::{
2-
get_trait_def_id, implements_trait, in_macro, is_type_diagnostic_item, paths, snippet_opt, span_lint_and_sugg,
3-
span_lint_and_then, SpanlessEq,
2+
eq_expr_value, get_trait_def_id, implements_trait, in_macro, is_type_diagnostic_item, paths, snippet_opt,
3+
span_lint_and_sugg, span_lint_and_then,
44
};
55
use if_chain::if_chain;
66
use rustc_ast::ast::LitKind;
@@ -128,7 +128,7 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
128128
}
129129
}
130130
for (n, expr) in self.terminals.iter().enumerate() {
131-
if SpanlessEq::new(self.cx).ignore_fn().eq_expr(e, expr) {
131+
if eq_expr_value(self.cx, e, expr) {
132132
#[allow(clippy::cast_possible_truncation)]
133133
return Ok(Bool::Term(n as u8));
134134
}
@@ -138,8 +138,8 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
138138
if implements_ord(self.cx, e_lhs);
139139
if let ExprKind::Binary(expr_binop, expr_lhs, expr_rhs) = &expr.kind;
140140
if negate(e_binop.node) == Some(expr_binop.node);
141-
if SpanlessEq::new(self.cx).ignore_fn().eq_expr(e_lhs, expr_lhs);
142-
if SpanlessEq::new(self.cx).ignore_fn().eq_expr(e_rhs, expr_rhs);
141+
if eq_expr_value(self.cx, e_lhs, expr_lhs);
142+
if eq_expr_value(self.cx, e_rhs, expr_rhs);
143143
then {
144144
#[allow(clippy::cast_possible_truncation)]
145145
return Ok(Bool::Not(Box::new(Bool::Term(n as u8))));

src/tools/clippy/clippy_lints/src/copies.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
use crate::utils::{eq_expr_value, SpanlessEq, SpanlessHash};
12
use crate::utils::{get_parent_expr, higher, if_sequence, snippet, span_lint_and_note, span_lint_and_then};
2-
use crate::utils::{SpanlessEq, SpanlessHash};
33
use rustc_data_structures::fx::FxHashMap;
44
use rustc_hir::{Arm, Block, Expr, ExprKind, MatchSource, Pat, PatKind};
55
use rustc_lint::{LateContext, LateLintPass};
@@ -197,8 +197,7 @@ fn lint_same_cond(cx: &LateContext<'_>, conds: &[&Expr<'_>]) {
197197
h.finish()
198198
};
199199

200-
let eq: &dyn Fn(&&Expr<'_>, &&Expr<'_>) -> bool =
201-
&|&lhs, &rhs| -> bool { SpanlessEq::new(cx).ignore_fn().eq_expr(lhs, rhs) };
200+
let eq: &dyn Fn(&&Expr<'_>, &&Expr<'_>) -> bool = &|&lhs, &rhs| -> bool { eq_expr_value(cx, lhs, rhs) };
202201

203202
for (i, j) in search_same(conds, hash, eq) {
204203
span_lint_and_note(
@@ -222,7 +221,7 @@ fn lint_same_fns_in_if_cond(cx: &LateContext<'_>, conds: &[&Expr<'_>]) {
222221

223222
let eq: &dyn Fn(&&Expr<'_>, &&Expr<'_>) -> bool = &|&lhs, &rhs| -> bool {
224223
// Do not spawn warning if `IFS_SAME_COND` already produced it.
225-
if SpanlessEq::new(cx).ignore_fn().eq_expr(lhs, rhs) {
224+
if eq_expr_value(cx, lhs, rhs) {
226225
return false;
227226
}
228227
SpanlessEq::new(cx).eq_expr(lhs, rhs)

0 commit comments

Comments
 (0)