Skip to content

Commit 963e5c0

Browse files
committed
Auto merge of rust-lang#111255 - flip1995:clippyup, r=Manishearth
Update Clippy r? `@Manishearth`
2 parents f9a6b71 + b53c1bb commit 963e5c0

File tree

153 files changed

+2230
-444
lines changed

Some content is hidden

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

153 files changed

+2230
-444
lines changed

Cargo.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ checksum = "8a2dd5a6fe8c6e3502f568a6353e5273bbb15193ad9a89e457b9970798efbea1"
577577

578578
[[package]]
579579
name = "clippy"
580-
version = "0.1.70"
580+
version = "0.1.71"
581581
dependencies = [
582582
"clap 4.2.1",
583583
"clippy_lints",
@@ -619,7 +619,7 @@ dependencies = [
619619

620620
[[package]]
621621
name = "clippy_lints"
622-
version = "0.1.70"
622+
version = "0.1.71"
623623
dependencies = [
624624
"arrayvec",
625625
"cargo_metadata 0.15.3",
@@ -643,7 +643,7 @@ dependencies = [
643643

644644
[[package]]
645645
name = "clippy_utils"
646-
version = "0.1.70"
646+
version = "0.1.71"
647647
dependencies = [
648648
"arrayvec",
649649
"if_chain",
@@ -969,7 +969,7 @@ checksum = "a0afaad2b26fa326569eb264b1363e8ae3357618c43982b3f285f0774ce76b69"
969969

970970
[[package]]
971971
name = "declare_clippy_lint"
972-
version = "0.1.70"
972+
version = "0.1.71"
973973
dependencies = [
974974
"itertools",
975975
"quote",

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

+6
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ jobs:
3636
- name: Check *.md files
3737
run: git ls-files -z '*.md' | xargs -0 -n 1 -I {} ./node_modules/.bin/remark {} -u lint -f > /dev/null
3838

39+
- name: Linkcheck book
40+
run: |
41+
rustup toolchain install nightly --component rust-docs
42+
curl https://raw.githubusercontent.com/rust-lang/rust/master/src/tools/linkchecker/linkcheck.sh -o linkcheck.sh
43+
sh linkcheck.sh clippy --path ./book
44+
3945
- name: Build mdbook
4046
run: mdbook build book
4147

src/tools/clippy/CHANGELOG.md

+14-11
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Current stable, released 2023-04-20
4444

4545
### Enhancements
4646

47-
* [`arithmetic_side_effects`]: No longer lints, if safe constant values are used.
47+
* [`arithmetic_side_effects`]: No longer lints if safe constant values are used.
4848
[#10310](https://github.com/rust-lang/rust-clippy/pull/10310)
4949
* [`needless_lifetimes`]: Now works in local macros
5050
[#10257](https://github.com/rust-lang/rust-clippy/pull/10257)
@@ -60,39 +60,39 @@ Current stable, released 2023-04-20
6060

6161
### False Positive Fixes
6262

63-
* [`explicit_auto_deref`]: Now considers projections, when determining if auto deref is applicable
63+
* [`explicit_auto_deref`]: Now considers projections when determining if auto deref is applicable
6464
[#10386](https://github.com/rust-lang/rust-clippy/pull/10386)
65-
* [`manual_let_else`]: Now considers side effects of branches, before linting
65+
* [`manual_let_else`]: Now considers side effects of branches before linting
6666
[#10336](https://github.com/rust-lang/rust-clippy/pull/10336)
6767
* [`uninlined_format_args`]: No longer lints for arguments with generic parameters
6868
[#10343](https://github.com/rust-lang/rust-clippy/pull/10343)
69-
* [`needless_lifetimes`]: No longer lints signatures in macros, if the lifetime is a metavariable
69+
* [`needless_lifetimes`]: No longer lints signatures in macros if the lifetime is a metavariable
7070
[#10380](https://github.com/rust-lang/rust-clippy/pull/10380)
71-
* [`len_without_is_empty`]: No longer lints, if `len` as a non-default signature
71+
* [`len_without_is_empty`]: No longer lints if `len` as a non-default signature
7272
[#10255](https://github.com/rust-lang/rust-clippy/pull/10255)
73-
* [`unusual_byte_groupings`]: Relaxed the required restrictions for specific sizes, to reduce false
73+
* [`unusual_byte_groupings`]: Relaxed the required restrictions for specific sizes to reduce false
7474
positives
7575
[#10353](https://github.com/rust-lang/rust-clippy/pull/10353)
7676
* [`manual_let_else`]: No longer lints `if-else` blocks if they can divergent
7777
[#10332](https://github.com/rust-lang/rust-clippy/pull/10332)
7878
* [`expect_used`], [`unwrap_used`], [`dbg_macro`], [`print_stdout`], [`print_stderr`]: No longer lint
79-
in test functions, if `allow-expect-in-tests` is set
79+
in test functions if `allow-expect-in-tests` is set
8080
[#10391](https://github.com/rust-lang/rust-clippy/pull/10391)
8181
* [`unnecessary_safety_comment`]: No longer lints code inside macros
8282
[#10106](https://github.com/rust-lang/rust-clippy/pull/10106)
83-
* [`never_loop`]: No longer lints, for statements following break statements for outer blocks.
83+
* [`never_loop`]: No longer lints statements following break statements for outer blocks.
8484
[#10311](https://github.com/rust-lang/rust-clippy/pull/10311)
8585

8686
### Suggestion Fixes/Improvements
8787

88-
* [`box_default`]: The suggestion now includes the type for trait objects, when needed
88+
* [`box_default`]: The suggestion now includes the type for trait objects when needed
8989
[#10382](https://github.com/rust-lang/rust-clippy/pull/10382)
9090
* [`cast_possible_truncation`]: Now suggests using `try_from` or allowing the lint
9191
[#10038](https://github.com/rust-lang/rust-clippy/pull/10038)
9292
* [`invalid_regex`]: Regex errors for non-literals or regular strings containing escape sequences will
9393
now show the complete error
9494
[#10231](https://github.com/rust-lang/rust-clippy/pull/10231)
95-
* [`transmutes_expressible_as_ptr_casts`]: The suggestion now works, if the base type is borrowed
95+
* [`transmutes_expressible_as_ptr_casts`]: The suggestion now works if the base type is borrowed
9696
[#10193](https://github.com/rust-lang/rust-clippy/pull/10193)
9797
* [`needless_return`]: Now removes all semicolons on the same line
9898
[#10187](https://github.com/rust-lang/rust-clippy/pull/10187)
@@ -113,7 +113,7 @@ Current stable, released 2023-04-20
113113

114114
### ICE Fixes
115115

116-
* [`needless_pass_by_value`]: Fixed an ICE, caused by how late bounds were handled
116+
* [`needless_pass_by_value`]: Fixed an ICE caused by how late bounds were handled
117117
[#10328](https://github.com/rust-lang/rust-clippy/pull/10328)
118118
* [`needless_borrow`]: No longer panics on ambiguous projections
119119
[#10403](https://github.com/rust-lang/rust-clippy/pull/10403)
@@ -4582,6 +4582,7 @@ Released 2018-09-13
45824582
[`debug_assert_with_mut_call`]: https://rust-lang.github.io/rust-clippy/master/index.html#debug_assert_with_mut_call
45834583
[`decimal_literal_representation`]: https://rust-lang.github.io/rust-clippy/master/index.html#decimal_literal_representation
45844584
[`declare_interior_mutable_const`]: https://rust-lang.github.io/rust-clippy/master/index.html#declare_interior_mutable_const
4585+
[`default_constructed_unit_structs`]: https://rust-lang.github.io/rust-clippy/master/index.html#default_constructed_unit_structs
45854586
[`default_instead_of_iter_empty`]: https://rust-lang.github.io/rust-clippy/master/index.html#default_instead_of_iter_empty
45864587
[`default_numeric_fallback`]: https://rust-lang.github.io/rust-clippy/master/index.html#default_numeric_fallback
45874588
[`default_trait_access`]: https://rust-lang.github.io/rust-clippy/master/index.html#default_trait_access
@@ -4797,6 +4798,7 @@ Released 2018-09-13
47974798
[`manual_strip`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_strip
47984799
[`manual_swap`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_swap
47994800
[`manual_unwrap_or`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_unwrap_or
4801+
[`manual_while_let_some`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_while_let_some
48004802
[`many_single_char_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#many_single_char_names
48014803
[`map_clone`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_clone
48024804
[`map_collect_result_unit`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_collect_result_unit
@@ -4864,6 +4866,7 @@ Released 2018-09-13
48644866
[`needless_arbitrary_self_type`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_arbitrary_self_type
48654867
[`needless_bitwise_bool`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_bitwise_bool
48664868
[`needless_bool`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_bool
4869+
[`needless_bool_assign`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_bool_assign
48674870
[`needless_borrow`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
48684871
[`needless_borrowed_reference`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrowed_reference
48694872
[`needless_collect`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_collect

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.70"
3+
version = "0.1.71"
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

+2-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ cargo clippy
9191

9292
#### Automatically applying Clippy suggestions
9393

94-
Clippy can automatically apply some lint suggestions, just like the compiler.
94+
Clippy can automatically apply some lint suggestions, just like the compiler. Note that `--fix` implies
95+
`--all-targets`, so it can fix as much code as it can.
9596

9697
```terminal
9798
cargo clippy --fix

src/tools/clippy/book/src/development/lint_passes.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ questions already, but the parser is okay with it. This is what we
5050
mean when we say `EarlyLintPass` deals with only syntax on the AST level.
5151

5252
Alternatively, think of the `foo_functions` lint we mentioned in
53-
define new lints chapter.
53+
define new lints <!-- FIXME: add link --> chapter.
5454

5555
We want the `foo_functions` lint to detect functions with `foo` as their name.
5656
Writing a lint that only checks for the name of a function means that we only

src/tools/clippy/book/src/development/proposals/syntax-tree-patterns.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ whether the pattern matched.
139139
140140
## Pattern syntax
141141

142-
The following examples demonstate the pattern syntax:
142+
The following examples demonstrate the pattern syntax:
143143

144144

145145
#### Any (`_`)

src/tools/clippy/book/src/lint_configuration.md

+18
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Please use that command to update the file and do not edit it by hand.
1313
| [msrv](#msrv) | `None` |
1414
| [cognitive-complexity-threshold](#cognitive-complexity-threshold) | `25` |
1515
| [disallowed-names](#disallowed-names) | `["foo", "baz", "quux"]` |
16+
| [semicolon-inside-block-ignore-singleline](#semicolon-inside-block-ignore-singleline) | `false` |
17+
| [semicolon-outside-block-ignore-multiline](#semicolon-outside-block-ignore-multiline) | `false` |
1618
| [doc-valid-idents](#doc-valid-idents) | `["KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "DirectX", "ECMAScript", "GPLv2", "GPLv3", "GitHub", "GitLab", "IPv4", "IPv6", "ClojureScript", "CoffeeScript", "JavaScript", "PureScript", "TypeScript", "NaN", "NaNs", "OAuth", "GraphQL", "OCaml", "OpenGL", "OpenMP", "OpenSSH", "OpenSSL", "OpenStreetMap", "OpenDNS", "WebGL", "TensorFlow", "TrueType", "iOS", "macOS", "FreeBSD", "TeX", "LaTeX", "BibTeX", "BibLaTeX", "MinGW", "CamelCase"]` |
1719
| [too-many-arguments-threshold](#too-many-arguments-threshold) | `7` |
1820
| [type-complexity-threshold](#type-complexity-threshold) | `250` |
@@ -203,6 +205,22 @@ default configuration of Clippy. By default, any configuration will replace the
203205
* [disallowed_names](https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_names)
204206

205207

208+
### semicolon-inside-block-ignore-singleline
209+
Whether to lint only if it's multiline.
210+
211+
**Default Value:** `false` (`bool`)
212+
213+
* [semicolon_inside_block](https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_inside_block)
214+
215+
216+
### semicolon-outside-block-ignore-multiline
217+
Whether to lint only if it's singleline.
218+
219+
**Default Value:** `false` (`bool`)
220+
221+
* [semicolon_outside_block](https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_outside_block)
222+
223+
206224
### doc-valid-idents
207225
The list of words this lint should not consider as identifiers needing ticks. The value
208226
`".."` can be used as part of the list to indicate, that the configured values should be appended to the

src/tools/clippy/book/src/usage.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ fn main() {
111111

112112
### Automatically applying Clippy suggestions
113113

114-
Clippy can automatically apply some lint suggestions, just like the compiler.
114+
Clippy can automatically apply some lint suggestions, just like the compiler. Note that `--fix` implies
115+
`--all-targets`, so it can fix as much code as it can.
115116

116117
```terminal
117118
cargo clippy --fix

src/tools/clippy/clippy_dev/src/dogfood.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::clippy_project_root;
1+
use crate::{clippy_project_root, exit_if_err};
22
use std::process::Command;
33

44
/// # Panics
@@ -10,7 +10,7 @@ pub fn dogfood(fix: bool, allow_dirty: bool, allow_staged: bool) {
1010
cmd.current_dir(clippy_project_root())
1111
.args(["test", "--test", "dogfood"])
1212
.args(["--features", "internal"])
13-
.args(["--", "dogfood_clippy"]);
13+
.args(["--", "dogfood_clippy", "--nocapture"]);
1414

1515
let mut dogfood_args = Vec::new();
1616
if fix {
@@ -27,7 +27,5 @@ pub fn dogfood(fix: bool, allow_dirty: bool, allow_staged: bool) {
2727

2828
cmd.env("__CLIPPY_DOGFOOD_ARGS", dogfood_args.join(" "));
2929

30-
let output = cmd.output().expect("failed to run command");
31-
32-
println!("{}", String::from_utf8_lossy(&output.stdout));
30+
exit_if_err(cmd.status());
3331
}

src/tools/clippy/clippy_dev/src/lib.rs

+13
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
extern crate rustc_driver;
1111
extern crate rustc_lexer;
1212

13+
use std::io;
1314
use std::path::PathBuf;
15+
use std::process::{self, ExitStatus};
1416

1517
pub mod bless;
1618
pub mod dogfood;
@@ -58,3 +60,14 @@ pub fn clippy_project_root() -> PathBuf {
5860
}
5961
panic!("error: Can't determine root of project. Please run inside a Clippy working dir.");
6062
}
63+
64+
pub fn exit_if_err(status: io::Result<ExitStatus>) {
65+
match status.expect("failed to run command").code() {
66+
Some(0) => {},
67+
Some(n) => process::exit(n),
68+
None => {
69+
eprintln!("Killed by signal");
70+
process::exit(1);
71+
},
72+
}
73+
}

src/tools/clippy/clippy_dev/src/lint.rs

+3-14
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
1-
use crate::cargo_clippy_path;
2-
use std::process::{self, Command, ExitStatus};
3-
use std::{fs, io};
4-
5-
fn exit_if_err(status: io::Result<ExitStatus>) {
6-
match status.expect("failed to run command").code() {
7-
Some(0) => {},
8-
Some(n) => process::exit(n),
9-
None => {
10-
eprintln!("Killed by signal");
11-
process::exit(1);
12-
},
13-
}
14-
}
1+
use crate::{cargo_clippy_path, exit_if_err};
2+
use std::fs;
3+
use std::process::{self, Command};
154

165
pub fn run<'a>(path: &str, args: impl Iterator<Item = &'a String>) {
176
let is_file = match fs::metadata(path) {

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

-54
Original file line numberDiff line numberDiff line change
@@ -36,60 +36,6 @@ pub enum UpdateMode {
3636
pub fn update(update_mode: UpdateMode) {
3737
let (lints, deprecated_lints, renamed_lints) = gather_all();
3838
generate_lint_files(update_mode, &lints, &deprecated_lints, &renamed_lints);
39-
remove_old_files(update_mode);
40-
}
41-
42-
/// Remove files no longer needed after <https://github.com/rust-lang/rust-clippy/pull/9541>
43-
/// that may be reintroduced unintentionally
44-
///
45-
/// FIXME: This is a temporary measure that should be removed when there are no more PRs that
46-
/// include the stray files
47-
fn remove_old_files(update_mode: UpdateMode) {
48-
let mut failed = false;
49-
let mut remove_file = |path: &Path| match update_mode {
50-
UpdateMode::Check => {
51-
if path.exists() {
52-
failed = true;
53-
println!("unexpected file: {}", path.display());
54-
}
55-
},
56-
UpdateMode::Change => {
57-
if fs::remove_file(path).is_ok() {
58-
println!("removed file: {}", path.display());
59-
}
60-
},
61-
};
62-
63-
let files = [
64-
"clippy_lints/src/lib.register_all.rs",
65-
"clippy_lints/src/lib.register_cargo.rs",
66-
"clippy_lints/src/lib.register_complexity.rs",
67-
"clippy_lints/src/lib.register_correctness.rs",
68-
"clippy_lints/src/lib.register_internal.rs",
69-
"clippy_lints/src/lib.register_lints.rs",
70-
"clippy_lints/src/lib.register_nursery.rs",
71-
"clippy_lints/src/lib.register_pedantic.rs",
72-
"clippy_lints/src/lib.register_perf.rs",
73-
"clippy_lints/src/lib.register_restriction.rs",
74-
"clippy_lints/src/lib.register_style.rs",
75-
"clippy_lints/src/lib.register_suspicious.rs",
76-
"src/docs.rs",
77-
];
78-
79-
for file in files {
80-
remove_file(Path::new(file));
81-
}
82-
83-
if let Ok(docs_dir) = fs::read_dir("src/docs") {
84-
for doc_file in docs_dir {
85-
let path = doc_file.unwrap().path();
86-
remove_file(&path);
87-
}
88-
}
89-
90-
if failed {
91-
exit_with_failure();
92-
}
9339
}
9440

9541
fn generate_lint_files(

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.70"
3+
version = "0.1.71"
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/allow_attributes.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ use ast::AttrStyle;
22
use clippy_utils::diagnostics::span_lint_and_sugg;
33
use rustc_ast as ast;
44
use rustc_errors::Applicability;
5-
use rustc_lint::{LateContext, LateLintPass};
5+
use rustc_lint::{LateContext, LateLintPass, LintContext};
6+
use rustc_middle::lint::in_external_macro;
67
use rustc_session::{declare_lint_pass, declare_tool_lint};
78

89
declare_clippy_lint! {
@@ -51,6 +52,7 @@ impl LateLintPass<'_> for AllowAttribute {
5152
// Separate each crate's features.
5253
fn check_attribute(&mut self, cx: &LateContext<'_>, attr: &ast::Attribute) {
5354
if_chain! {
55+
if !in_external_macro(cx.sess(), attr.span);
5456
if cx.tcx.features().lint_reasons;
5557
if let AttrStyle::Outer = attr.style;
5658
if let Some(ident) = attr.ident();

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ declare_clippy_lint! {
638638
#[clippy::version = "1.66.0"]
639639
pub AS_PTR_CAST_MUT,
640640
nursery,
641-
"casting the result of the `&self`-taking `as_ptr` to a mutabe pointer"
641+
"casting the result of the `&self`-taking `as_ptr` to a mutable pointer"
642642
}
643643

644644
declare_clippy_lint! {

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ fn lint_unnecessary_cast(
141141

142142
fn get_numeric_literal<'e>(expr: &'e Expr<'e>) -> Option<&'e Lit> {
143143
match expr.kind {
144-
ExprKind::Lit(ref lit) => Some(lit),
144+
ExprKind::Lit(lit) => Some(lit),
145145
ExprKind::Unary(UnOp::Neg, e) => {
146-
if let ExprKind::Lit(ref lit) = e.kind {
146+
if let ExprKind::Lit(lit) = e.kind {
147147
Some(lit)
148148
} else {
149149
None

0 commit comments

Comments
 (0)