Skip to content

Commit 7be6e21

Browse files
committed
Merge commit '10136170fe9ed01e46aeb4f4479175b79eb0e3c7' into clippy-subtree-update
1 parent 5931794 commit 7be6e21

File tree

1,096 files changed

+14122
-10811
lines changed

Some content is hidden

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

1,096 files changed

+14122
-10811
lines changed

.github/driver.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ test "$sysroot" = $desired_sysroot
3232
)
3333

3434
# Check that the --sysroot argument is only passed once via arg_file.txt (SYSROOT is ignored)
35-
(
35+
(
3636
echo "fn main() {}" > target/driver_test.rs
3737
echo "--sysroot="$(./target/debug/clippy-driver --print sysroot)"" > arg_file.txt
3838
echo "--verbose" >> arg_file.txt
@@ -45,7 +45,7 @@ unset CARGO_MANIFEST_DIR
4545
# Run a lint and make sure it produces the expected output. It's also expected to exit with code 1
4646
# FIXME: How to match the clippy invocation in compile-test.rs?
4747
./target/debug/clippy-driver -Dwarnings -Aunused -Zui-testing --emit metadata --crate-type bin tests/ui/double_neg.rs 2>double_neg.stderr && exit 1
48-
sed -e "s,tests/ui,\$DIR," -e "/= help: for/d" double_neg.stderr > normalized.stderr
48+
sed -e "/= help: for/d" double_neg.stderr > normalized.stderr
4949
diff -u normalized.stderr tests/ui/double_neg.stderr
5050

5151
# make sure "clippy-driver --rustc --arg" and "rustc --arg" behave the same

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -5125,6 +5125,7 @@ Released 2018-09-13
51255125
[`default_trait_access`]: https://rust-lang.github.io/rust-clippy/master/index.html#default_trait_access
51265126
[`default_union_representation`]: https://rust-lang.github.io/rust-clippy/master/index.html#default_union_representation
51275127
[`deprecated_cfg_attr`]: https://rust-lang.github.io/rust-clippy/master/index.html#deprecated_cfg_attr
5128+
[`deprecated_clippy_cfg_attr`]: https://rust-lang.github.io/rust-clippy/master/index.html#deprecated_clippy_cfg_attr
51285129
[`deprecated_semver`]: https://rust-lang.github.io/rust-clippy/master/index.html#deprecated_semver
51295130
[`deref_addrof`]: https://rust-lang.github.io/rust-clippy/master/index.html#deref_addrof
51305131
[`deref_by_slicing`]: https://rust-lang.github.io/rust-clippy/master/index.html#deref_by_slicing
@@ -5157,6 +5158,7 @@ Released 2018-09-13
51575158
[`duration_subsec`]: https://rust-lang.github.io/rust-clippy/master/index.html#duration_subsec
51585159
[`eager_transmute`]: https://rust-lang.github.io/rust-clippy/master/index.html#eager_transmute
51595160
[`else_if_without_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#else_if_without_else
5161+
[`empty_docs`]: https://rust-lang.github.io/rust-clippy/master/index.html#empty_docs
51605162
[`empty_drop`]: https://rust-lang.github.io/rust-clippy/master/index.html#empty_drop
51615163
[`empty_enum`]: https://rust-lang.github.io/rust-clippy/master/index.html#empty_enum
51625164
[`empty_enum_variants_with_brackets`]: https://rust-lang.github.io/rust-clippy/master/index.html#empty_enum_variants_with_brackets
@@ -5429,6 +5431,7 @@ Released 2018-09-13
54295431
[`modulo_arithmetic`]: https://rust-lang.github.io/rust-clippy/master/index.html#modulo_arithmetic
54305432
[`modulo_one`]: https://rust-lang.github.io/rust-clippy/master/index.html#modulo_one
54315433
[`multi_assignments`]: https://rust-lang.github.io/rust-clippy/master/index.html#multi_assignments
5434+
[`multiple_bound_locations`]: https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations
54325435
[`multiple_crate_versions`]: https://rust-lang.github.io/rust-clippy/master/index.html#multiple_crate_versions
54335436
[`multiple_inherent_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#multiple_inherent_impl
54345437
[`multiple_unsafe_ops_per_block`]: https://rust-lang.github.io/rust-clippy/master/index.html#multiple_unsafe_ops_per_block
@@ -5725,10 +5728,12 @@ Released 2018-09-13
57255728
[`unknown_clippy_lints`]: https://rust-lang.github.io/rust-clippy/master/index.html#unknown_clippy_lints
57265729
[`unnecessary_box_returns`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_box_returns
57275730
[`unnecessary_cast`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast
5731+
[`unnecessary_clippy_cfg`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_clippy_cfg
57285732
[`unnecessary_fallible_conversions`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_fallible_conversions
57295733
[`unnecessary_filter_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_filter_map
57305734
[`unnecessary_find_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_find_map
57315735
[`unnecessary_fold`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_fold
5736+
[`unnecessary_get_then_check`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_get_then_check
57325737
[`unnecessary_join`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_join
57335738
[`unnecessary_lazy_evaluations`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_lazy_evaluations
57345739
[`unnecessary_literal_unwrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_literal_unwrap

Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@ rustc_tools_util = "0.3.0"
2727
tempfile = { version = "3.2", optional = true }
2828
termize = "0.1"
2929
color-print = "0.3.4"
30-
anstream = "0.5.0"
30+
anstream = "0.6.0"
3131

3232
[dev-dependencies]
33-
ui_test = "0.21.2"
33+
ui_test = "0.22.2"
3434
tester = "0.9"
3535
regex = "1.5"
3636
toml = "0.7.3"
3737
walkdir = "2.3"
3838
# This is used by the `collect-metadata` alias.
3939
filetime = "0.2"
40-
itertools = "0.11"
40+
itertools = "0.12"
4141

4242
# UI test dependencies
4343
clippy_utils = { path = "clippy_utils" }

book/src/configuration.md

+32-18
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,29 @@ disallowed-names = ["bar", ".."] # -> ["bar", "foo", "baz", "quux"]
3333
To deactivate the "for further information visit *lint-link*" message you can define the `CLIPPY_DISABLE_DOCS_LINKS`
3434
environment variable.
3535

36-
### Allowing/denying lints
36+
### Allowing/Denying Lints
3737

38-
You can add options to your code to `allow`/`warn`/`deny` Clippy lints:
38+
#### Attributes in Code
3939

40-
* the whole set of `Warn` lints using the `clippy` lint group (`#![deny(clippy::all)]`)
40+
You can add attributes to your code to `allow`/`warn`/`deny` Clippy lints:
4141

42-
* all lints using both the `clippy` and `clippy::pedantic` lint groups (`#![deny(clippy::all)]`,
43-
`#![deny(clippy::pedantic)]`). Note that `clippy::pedantic` contains some very aggressive lints prone to false
44-
positives.
42+
* the whole set of `warn`-by-default lints using the `clippy` lint group (`#![allow(clippy::all)]`)
43+
44+
* all lints using both the `clippy` and `clippy::pedantic` lint groups (`#![warn(clippy::all, clippy::pedantic)]`. Note
45+
that `clippy::pedantic` contains some very aggressive lints prone to false positives.
4546

4647
* only some lints (`#![deny(clippy::single_match, clippy::box_vec)]`, etc.)
4748

4849
* `allow`/`warn`/`deny` can be limited to a single function or module using `#[allow(...)]`, etc.
4950

5051
Note: `allow` means to suppress the lint for your code. With `warn` the lint will only emit a warning, while with `deny`
51-
the lint will emit an error, when triggering for your code. An error causes clippy to exit with an error code, so is
52-
useful in scripts like CI/CD.
52+
the lint will emit an error, when triggering for your code. An error causes Clippy to exit with an error code, so is
53+
most useful in scripts used in CI/CD.
54+
55+
#### Command Line Flags
5356

54-
If you do not want to include your lint levels in your code, you can globally enable/disable lints by passing extra
55-
flags to Clippy during the run:
57+
If you do not want to include your lint levels in the code, you can globally enable/disable lints by passing extra flags
58+
to Clippy during the run:
5659

5760
To allow `lint_name`, run
5861

@@ -66,19 +69,33 @@ And to warn on `lint_name`, run
6669
cargo clippy -- -W clippy::lint_name
6770
```
6871

69-
This also works with lint groups. For example, you can run Clippy with warnings for all lints enabled:
72+
This also works with lint groups. For example, you can run Clippy with warnings for all pedantic lints enabled:
7073

7174
```terminal
7275
cargo clippy -- -W clippy::pedantic
7376
```
7477

75-
If you care only about a single lint, you can allow all others and then explicitly warn on the lint(s) you are
78+
If you care only about a certain lints, you can allow all others and then explicitly warn on the lints you are
7679
interested in:
7780

7881
```terminal
7982
cargo clippy -- -A clippy::all -W clippy::useless_format -W clippy::...
8083
```
8184

85+
#### Lints Section in `Cargo.toml`
86+
87+
Finally, lints can be allowed/denied using [the lints
88+
section](https://doc.rust-lang.org/nightly/cargo/reference/manifest.html#the-lints-section)) in the `Cargo.toml` file:
89+
90+
To deny `clippy::enum_glob_use`, put the following in the `Cargo.toml`:
91+
92+
```toml
93+
[lints.clippy]
94+
enum_glob_use = "deny"
95+
```
96+
97+
For more details and options, refer to the Cargo documentation.
98+
8299
### Specifying the minimum supported Rust version
83100

84101
Projects that intend to support old versions of Rust can disable lints pertaining to newer features by specifying the
@@ -113,17 +130,14 @@ found [here](https://rust-lang.github.io/rust-clippy/master/index.html#msrv)
113130
114131
Very rarely, you may wish to prevent Clippy from evaluating certain sections of code entirely. You can do this with
115132
[conditional compilation](https://doc.rust-lang.org/reference/conditional-compilation.html) by checking that the
116-
`cargo-clippy` feature is not set. You may need to provide a stub so that the code compiles:
133+
`clippy` cfg is not set. You may need to provide a stub so that the code compiles:
117134

118135
```rust
119-
#[cfg(not(feature = "cargo-clippy"))]
136+
#[cfg(not(clippy)]
120137
include!(concat!(env!("OUT_DIR"), "/my_big_function-generated.rs"));
121138

122-
#[cfg(feature = "cargo-clippy")]
139+
#[cfg(clippy)]
123140
fn my_big_function(_input: &str) -> Option<MyStruct> {
124141
None
125142
}
126143
```
127-
128-
This feature is not actually part of your crate, so specifying `--all-features` to other tools, e.g. `cargo test
129-
--all-features`, will not disable it.

book/src/development/emitting_lints.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ The output looks something like this (from the example earlier):
8282

8383
```text
8484
error: an inclusive range would be more readable
85-
--> $DIR/range_plus_minus_one.rs:37:14
85+
--> tests/ui/range_plus_minus_one.rs:37:14
8686
|
8787
LL | for _ in 1..1 + 1 {}
8888
| ^^^^^^^^ help: use: `1..=1`
@@ -135,14 +135,14 @@ Examples:
135135

136136
```text
137137
error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing.
138-
--> $DIR/drop_forget_ref.rs:10:5
138+
--> tests/ui/drop_forget_ref.rs:10:5
139139
|
140140
10 | forget(&SomeStruct);
141141
| ^^^^^^^^^^^^^^^^^^^
142142
|
143143
= note: `-D clippy::forget-ref` implied by `-D warnings`
144144
note: argument has type &SomeStruct
145-
--> $DIR/drop_forget_ref.rs:10:12
145+
--> tests/ui/drop_forget_ref.rs:10:12
146146
|
147147
10 | forget(&SomeStruct);
148148
| ^^^^^^^^^^^
@@ -158,7 +158,7 @@ Example:
158158

159159
```text
160160
error: constant division of 0.0 with 0.0 will always result in NaN
161-
--> $DIR/zero_div_zero.rs:6:25
161+
--> tests/ui/zero_div_zero.rs:6:25
162162
|
163163
6 | let other_f64_nan = 0.0f64 / 0.0;
164164
| ^^^^^^^^^^^^
@@ -176,7 +176,7 @@ Example:
176176

177177
```text
178178
error: This `.fold` can be more succinctly expressed as `.any`
179-
--> $DIR/methods.rs:390:13
179+
--> tests/ui/methods.rs:390:13
180180
|
181181
390 | let _ = (0..3).fold(false, |acc, x| acc || x > 2);
182182
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `.any(|x| x > 2)`

book/src/development/writing_tests.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,19 @@ failures:
9797
---- compile_test stdout ----
9898
normalized stderr:
9999
error: function called "foo"
100-
--> $DIR/foo_functions.rs:6:12
100+
--> tests/ui/foo_functions.rs:6:12
101101
|
102102
LL | pub fn foo(&self) {}
103103
| ^^^
104104
|
105105
= note: `-D clippy::foo-functions` implied by `-D warnings`
106106
error: function called "foo"
107-
--> $DIR/foo_functions.rs:13:8
107+
--> tests/ui/foo_functions.rs:13:8
108108
|
109109
LL | fn foo(&self) {}
110110
| ^^^
111111
error: function called "foo"
112-
--> $DIR/foo_functions.rs:19:4
112+
--> tests/ui/foo_functions.rs:19:4
113113
|
114114
LL | fn foo() {}
115115
| ^^^

book/src/lint_configuration.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ The minimum number of struct fields for the lints about field names to trigger
278278

279279
---
280280
**Affected lints:**
281-
* [`struct_variant_names`](https://rust-lang.github.io/rust-clippy/master/index.html#struct_variant_names)
281+
* [`struct_field_names`](https://rust-lang.github.io/rust-clippy/master/index.html#struct_field_names)
282282

283283

284284
## `enum-variant-size-threshold`

clippy_config/src/conf.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ define_Conf! {
325325
///
326326
/// The minimum number of enum variants for the lints about variant names to trigger
327327
(enum_variant_name_threshold: u64 = 3),
328-
/// Lint: STRUCT_VARIANT_NAMES.
328+
/// Lint: STRUCT_FIELD_NAMES.
329329
///
330330
/// The minimum number of struct fields for the lints about field names to trigger
331331
(struct_field_name_threshold: u64 = 3),
@@ -648,7 +648,7 @@ fn deserialize(file: &SourceFile) -> TryConf {
648648
extend_vec_if_indicator_present(&mut conf.conf.doc_valid_idents, DEFAULT_DOC_VALID_IDENTS);
649649
extend_vec_if_indicator_present(&mut conf.conf.disallowed_names, DEFAULT_DISALLOWED_NAMES);
650650
// TODO: THIS SHOULD BE TESTED, this comment will be gone soon
651-
if conf.conf.allowed_idents_below_min_chars.contains(&"..".to_owned()) {
651+
if conf.conf.allowed_idents_below_min_chars.contains("..") {
652652
conf.conf
653653
.allowed_idents_below_min_chars
654654
.extend(DEFAULT_ALLOWED_IDENTS_BELOW_MIN_CHARS.iter().map(ToString::to_string));

clippy_config/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
clippy::missing_panics_doc,
77
rustc::diagnostic_outside_of_impl,
88
rustc::untranslatable_diagnostic,
9-
rustc::untranslatable_diagnostic_trivial,
9+
rustc::untranslatable_diagnostic_trivial
1010
)]
1111

1212
extern crate rustc_ast;

clippy_dev/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ edition = "2021"
77
aho-corasick = "1.0"
88
clap = "4.1.4"
99
indoc = "1.0"
10-
itertools = "0.11"
10+
itertools = "0.12"
1111
opener = "0.6"
1212
shell-escape = "0.1"
1313
walkdir = "2.3"

clippy_lints/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ cargo_metadata = "0.18"
1414
clippy_config = { path = "../clippy_config" }
1515
clippy_utils = { path = "../clippy_utils" }
1616
declare_clippy_lint = { path = "../declare_clippy_lint" }
17-
itertools = "0.11"
17+
itertools = "0.12"
1818
quine-mc_cluskey = "0.2"
1919
regex-syntax = "0.8"
2020
serde = { version = "1.0", features = ["derive"] }

clippy_lints/src/asm_syntax.rs

+31-6
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ use std::fmt;
22

33
use clippy_utils::diagnostics::span_lint_and_help;
44
use rustc_ast::ast::{Expr, ExprKind, InlineAsmOptions};
5-
use rustc_lint::{EarlyContext, EarlyLintPass, Lint};
5+
use rustc_ast::{InlineAsm, Item, ItemKind};
6+
use rustc_lint::{EarlyContext, EarlyLintPass, Lint, LintContext};
67
use rustc_session::declare_lint_pass;
8+
use rustc_span::Span;
9+
use rustc_target::asm::InlineAsmArch;
710

811
#[derive(Clone, Copy, PartialEq, Eq)]
912
enum AsmStyle {
@@ -31,8 +34,14 @@ impl std::ops::Not for AsmStyle {
3134
}
3235
}
3336

34-
fn check_expr_asm_syntax(lint: &'static Lint, cx: &EarlyContext<'_>, expr: &Expr, check_for: AsmStyle) {
35-
if let ExprKind::InlineAsm(ref inline_asm) = expr.kind {
37+
fn check_asm_syntax(
38+
lint: &'static Lint,
39+
cx: &EarlyContext<'_>,
40+
inline_asm: &InlineAsm,
41+
span: Span,
42+
check_for: AsmStyle,
43+
) {
44+
if matches!(cx.sess().asm_arch, Some(InlineAsmArch::X86 | InlineAsmArch::X86_64)) {
3645
let style = if inline_asm.options.contains(InlineAsmOptions::ATT_SYNTAX) {
3746
AsmStyle::Att
3847
} else {
@@ -43,7 +52,7 @@ fn check_expr_asm_syntax(lint: &'static Lint, cx: &EarlyContext<'_>, expr: &Expr
4352
span_lint_and_help(
4453
cx,
4554
lint,
46-
expr.span,
55+
span,
4756
&format!("{style} x86 assembly syntax used"),
4857
None,
4958
&format!("use {} x86 assembly syntax", !style),
@@ -89,7 +98,15 @@ declare_lint_pass!(InlineAsmX86IntelSyntax => [INLINE_ASM_X86_INTEL_SYNTAX]);
8998

9099
impl EarlyLintPass for InlineAsmX86IntelSyntax {
91100
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) {
92-
check_expr_asm_syntax(Self::get_lints()[0], cx, expr, AsmStyle::Intel);
101+
if let ExprKind::InlineAsm(inline_asm) = &expr.kind {
102+
check_asm_syntax(Self::get_lints()[0], cx, inline_asm, expr.span, AsmStyle::Intel);
103+
}
104+
}
105+
106+
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) {
107+
if let ItemKind::GlobalAsm(inline_asm) = &item.kind {
108+
check_asm_syntax(Self::get_lints()[0], cx, inline_asm, item.span, AsmStyle::Intel);
109+
}
93110
}
94111
}
95112

@@ -130,6 +147,14 @@ declare_lint_pass!(InlineAsmX86AttSyntax => [INLINE_ASM_X86_ATT_SYNTAX]);
130147

131148
impl EarlyLintPass for InlineAsmX86AttSyntax {
132149
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) {
133-
check_expr_asm_syntax(Self::get_lints()[0], cx, expr, AsmStyle::Att);
150+
if let ExprKind::InlineAsm(inline_asm) = &expr.kind {
151+
check_asm_syntax(Self::get_lints()[0], cx, inline_asm, expr.span, AsmStyle::Att);
152+
}
153+
}
154+
155+
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) {
156+
if let ItemKind::GlobalAsm(inline_asm) = &item.kind {
157+
check_asm_syntax(Self::get_lints()[0], cx, inline_asm, item.span, AsmStyle::Att);
158+
}
134159
}
135160
}

0 commit comments

Comments
 (0)