Skip to content

Commit a577704

Browse files
committed
Auto merge of rust-lang#117979 - flip1995:clippyup, r=matthiaskrgr
Clippy subtree sync r? `@Manishearth`
2 parents 820f06b + 2ac2b26 commit a577704

File tree

327 files changed

+10343
-10376
lines changed

Some content is hidden

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

327 files changed

+10343
-10376
lines changed

Cargo.lock

+5-7
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b"
553553

554554
[[package]]
555555
name = "clippy"
556-
version = "0.1.75"
556+
version = "0.1.76"
557557
dependencies = [
558558
"anstream",
559559
"clippy_config",
@@ -581,7 +581,7 @@ dependencies = [
581581

582582
[[package]]
583583
name = "clippy_config"
584-
version = "0.1.75"
584+
version = "0.1.76"
585585
dependencies = [
586586
"rustc-semver",
587587
"serde",
@@ -604,14 +604,13 @@ dependencies = [
604604

605605
[[package]]
606606
name = "clippy_lints"
607-
version = "0.1.75"
607+
version = "0.1.76"
608608
dependencies = [
609609
"arrayvec",
610610
"cargo_metadata 0.15.4",
611611
"clippy_config",
612612
"clippy_utils",
613613
"declare_clippy_lint",
614-
"if_chain",
615614
"itertools",
616615
"quine-mc_cluskey",
617616
"regex",
@@ -630,11 +629,10 @@ dependencies = [
630629

631630
[[package]]
632631
name = "clippy_utils"
633-
version = "0.1.75"
632+
version = "0.1.76"
634633
dependencies = [
635634
"arrayvec",
636635
"clippy_config",
637-
"if_chain",
638636
"itertools",
639637
"rustc-semver",
640638
]
@@ -1016,7 +1014,7 @@ checksum = "a0afaad2b26fa326569eb264b1363e8ae3357618c43982b3f285f0774ce76b69"
10161014

10171015
[[package]]
10181016
name = "declare_clippy_lint"
1019-
version = "0.1.75"
1017+
version = "0.1.76"
10201018
dependencies = [
10211019
"itertools",
10221020
"quote",

src/tools/clippy/CHANGELOG.md

+62-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,70 @@ document.
66

77
## Unreleased / Beta / In Rust Nightly
88

9-
[1e8fdf49...master](https://github.com/rust-lang/rust-clippy/compare/1e8fdf49...master)
9+
[7671c283...master](https://github.com/rust-lang/rust-clippy/compare/7671c283...master)
10+
11+
## Rust 1.74
12+
13+
Current stable, released 2023-11-16
14+
15+
[View all 94 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2023-08-11T15%3A29%3A18Z..2023-09-25T08%3A48%3A22Z+base%3Amaster)
16+
17+
### New Lints
18+
19+
* [`redundant_as_str`]
20+
[#11526](https://github.com/rust-lang/rust-clippy/pull/11526)
21+
* [`needless_borrows_for_generic_args`]
22+
[#11511](https://github.com/rust-lang/rust-clippy/pull/11511)
23+
* [`path_ends_with_ext`]
24+
[#11483](https://github.com/rust-lang/rust-clippy/pull/11483)
25+
* [`unnecessary_map_on_constructor`]
26+
[#11413](https://github.com/rust-lang/rust-clippy/pull/11413)
27+
* [`missing_asserts_for_indexing`]
28+
[#10692](https://github.com/rust-lang/rust-clippy/pull/10692)
29+
* [`iter_out_of_bounds`]
30+
[#11396](https://github.com/rust-lang/rust-clippy/pull/11396)
31+
* [`implied_bounds_in_impls`]
32+
[#11362](https://github.com/rust-lang/rust-clippy/pull/11362)
33+
* [`reserve_after_initialization`]
34+
[#11373](https://github.com/rust-lang/rust-clippy/pull/11373)
35+
* [`should_panic_without_expect`]
36+
[#11204](https://github.com/rust-lang/rust-clippy/pull/11204)
37+
38+
### Moves and Deprecations
39+
40+
* Renamed `incorrect_clone_impl_on_copy_type` to [`non_canonical_clone_impl`]
41+
[#11358](https://github.com/rust-lang/rust-clippy/pull/11358)
42+
* Renamed `incorrect_partial_ord_impl_on_ord_type` to [`non_canonical_partial_ord_impl`]
43+
[#11358](https://github.com/rust-lang/rust-clippy/pull/11358)
44+
* Moved [`non_canonical_clone_impl`] to `suspicious` (Now warn-by-default)
45+
[#11358](https://github.com/rust-lang/rust-clippy/pull/11358)
46+
* Moved [`non_canonical_partial_ord_impl`] to `suspicious` (Now warn-by-default)
47+
[#11358](https://github.com/rust-lang/rust-clippy/pull/11358)
48+
* Moved [`needless_pass_by_ref_mut`] to `nursery` (Now allow-by-default)
49+
[#11596](https://github.com/rust-lang/rust-clippy/pull/11596)
50+
51+
### Enhancements
52+
53+
* [`undocumented_unsafe_blocks`]: The config values [`accept-comment-above-statement`] and
54+
[`accept-comment-above-attributes`] to `true` by default
55+
[#11170](https://github.com/rust-lang/rust-clippy/pull/11170)
56+
* [`explicit_iter_loop`]: Added [`enforce-iter-loop-reborrow`] to disable reborrow linting by default
57+
[#11418](https://github.com/rust-lang/rust-clippy/pull/11418)
58+
59+
### ICE Fixes
60+
61+
* [`enum_variant_names`]: No longer crashes if the threshold is 0 and the enum has no variants
62+
[#11552](https://github.com/rust-lang/rust-clippy/pull/11552)
63+
* [`cast_possible_truncation`]: No longer crashes on values larger than `u64::MAX`
64+
[#11517](https://github.com/rust-lang/rust-clippy/pull/11517)
65+
* [`tuple_array_conversions`]: No longer crashes if the array length is not usize
66+
[#11379](https://github.com/rust-lang/rust-clippy/pull/11379)
67+
* [`useless_conversion`]: No longer crashes, when the receiver is a non-fn item
68+
[#11070](https://github.com/rust-lang/rust-clippy/pull/11070)
1069

1170
## Rust 1.73
1271

13-
Current stable, released 2023-10-05
72+
Released 2023-10-05
1473

1574
[View all 103 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2023-07-02T12%3A24%3A40Z..2023-08-11T11%3A09%3A56Z+base%3Amaster)
1675

@@ -5123,6 +5182,7 @@ Released 2018-09-13
51235182
[`iter_on_empty_collections`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_on_empty_collections
51245183
[`iter_on_single_items`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_on_single_items
51255184
[`iter_out_of_bounds`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_out_of_bounds
5185+
[`iter_over_hash_type`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_over_hash_type
51265186
[`iter_overeager_cloned`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_overeager_cloned
51275187
[`iter_skip_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_skip_next
51285188
[`iter_skip_zero`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_skip_zero

src/tools/clippy/CONTRIBUTING.md

+1-7
Original file line numberDiff line numberDiff line change
@@ -146,16 +146,10 @@ For example, the [`else_if_without_else`][else_if_without_else] lint is register
146146
pub mod else_if_without_else;
147147
// ...
148148

149-
pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: &Conf) {
149+
pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) {
150150
// ...
151151
store.register_early_pass(|| Box::new(else_if_without_else::ElseIfWithoutElse));
152152
// ...
153-
154-
store.register_group(true, "clippy::restriction", Some("clippy_restriction"), vec![
155-
// ...
156-
LintId::of(&else_if_without_else::ELSE_IF_WITHOUT_ELSE),
157-
// ...
158-
]);
159153
}
160154
```
161155

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.75"
3+
version = "0.1.76"
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/book/src/development/adding_lints.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ When using `cargo dev new_lint`, the lint is automatically registered and
270270
nothing more has to be done.
271271

272272
When declaring a new lint by hand and `cargo dev update_lints` is used, the lint
273-
pass may have to be registered manually in the `register_plugins` function in
273+
pass may have to be registered manually in the `register_lints` function in
274274
`clippy_lints/src/lib.rs`:
275275

276276
```rust,ignore
@@ -436,7 +436,7 @@ need to ensure that the MSRV configured for the project is >= the MSRV of the
436436
required Rust feature. If multiple features are required, just use the one with
437437
a lower MSRV.
438438

439-
First, add an MSRV alias for the required feature in [`clippy_utils::msrvs`].
439+
First, add an MSRV alias for the required feature in [`clippy_config::msrvs`].
440440
This can be accessed later as `msrvs::STR_STRIP_PREFIX`, for example.
441441

442442
```rust
@@ -506,7 +506,7 @@ fn msrv_1_45() {
506506
```
507507

508508
As a last step, the lint should be added to the lint documentation. This is done
509-
in `clippy_lints/src/utils/conf.rs`:
509+
in `clippy_config/src/conf.rs`:
510510

511511
```rust
512512
define_Conf! {
@@ -516,7 +516,7 @@ define_Conf! {
516516
}
517517
```
518518

519-
[`clippy_utils::msrvs`]: https://doc.rust-lang.org/nightly/nightly-rustc/clippy_utils/msrvs/index.html
519+
[`clippy_config::msrvs`]: https://doc.rust-lang.org/nightly/nightly-rustc/clippy_config/msrvs/index.html
520520

521521
## Author lint
522522

@@ -657,7 +657,7 @@ Adding a configuration to a lint can be useful for
657657
thresholds or to constrain some behavior that can be seen as a false positive
658658
for some users. Adding a configuration is done in the following steps:
659659

660-
1. Adding a new configuration entry to [`clippy_lints::utils::conf`] like this:
660+
1. Adding a new configuration entry to [`clippy_config::conf`] like this:
661661

662662
```rust,ignore
663663
/// Lint: LINT_NAME.
@@ -736,7 +736,7 @@ for some users. Adding a configuration is done in the following steps:
736736

737737
Run `cargo collect-metadata` to generate documentation changes for the book.
738738

739-
[`clippy_lints::utils::conf`]: https://github.com/rust-lang/rust-clippy/blob/master/clippy_lints/src/utils/conf.rs
739+
[`clippy_config::conf`]: https://github.com/rust-lang/rust-clippy/blob/master/clippy_config/src/conf.rs
740740
[`clippy_lints` lib file]: https://github.com/rust-lang/rust-clippy/blob/master/clippy_lints/src/lib.rs
741741
[`tests/ui`]: https://github.com/rust-lang/rust-clippy/blob/master/tests/ui
742742
[`tests/ui-toml`]: https://github.com/rust-lang/rust-clippy/blob/master/tests/ui-toml

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ However, sometimes we might want to declare a new lint by hand. In this case,
186186
we'd use `cargo dev update_lints` command afterwards.
187187

188188
When a lint is manually declared, we might need to register the lint pass
189-
manually in the `register_plugins` function in `clippy_lints/src/lib.rs`:
189+
manually in the `register_lints` function in `clippy_lints/src/lib.rs`:
190190

191191
```rust
192192
store.register_late_pass(|_| Box::new(foo_functions::FooFunctions));

src/tools/clippy/clippy.toml

+6
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
11
avoid-breaking-exported-api = false
2+
3+
# use the various `span_lint_*` methods instead, which also add a link to the docs
4+
disallowed-methods = [
5+
"rustc_lint::context::LintContext::struct_span_lint",
6+
"rustc_middle::ty::context::TyCtxt::struct_span_lint_hir"
7+
]

src/tools/clippy/clippy_config/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy_config"
3-
version = "0.1.75"
3+
version = "0.1.76"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

src/tools/clippy/clippy_config/src/types.rs

+5-19
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use serde::de::{self, Deserializer, Visitor};
22
use serde::{ser, Deserialize, Serialize};
33
use std::fmt;
4-
use std::hash::{Hash, Hasher};
54

65
#[derive(Clone, Debug, Deserialize)]
76
pub struct Rename {
@@ -33,32 +32,19 @@ impl DisallowedPath {
3332
}
3433
}
3534

36-
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Deserialize, Serialize)]
35+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize, Serialize)]
3736
pub enum MatchLintBehaviour {
3837
AllTypes,
3938
WellKnownTypes,
4039
Never,
4140
}
4241

43-
#[derive(Clone, Debug)]
42+
#[derive(Debug)]
4443
pub struct MacroMatcher {
4544
pub name: String,
46-
pub braces: (String, String),
45+
pub braces: (char, char),
4746
}
4847

49-
impl Hash for MacroMatcher {
50-
fn hash<H: Hasher>(&self, state: &mut H) {
51-
self.name.hash(state);
52-
}
53-
}
54-
55-
impl PartialEq for MacroMatcher {
56-
fn eq(&self, other: &Self) -> bool {
57-
self.name == other.name
58-
}
59-
}
60-
impl Eq for MacroMatcher {}
61-
6248
impl<'de> Deserialize<'de> for MacroMatcher {
6349
fn deserialize<D>(deser: D) -> Result<Self, D::Error>
6450
where
@@ -83,7 +69,7 @@ impl<'de> Deserialize<'de> for MacroMatcher {
8369
V: de::MapAccess<'de>,
8470
{
8571
let mut name = None;
86-
let mut brace: Option<String> = None;
72+
let mut brace: Option<char> = None;
8773
while let Some(key) = map.next_key()? {
8874
match key {
8975
Field::Name => {
@@ -104,7 +90,7 @@ impl<'de> Deserialize<'de> for MacroMatcher {
10490
let brace = brace.ok_or_else(|| de::Error::missing_field("brace"))?;
10591
Ok(MacroMatcher {
10692
name,
107-
braces: [("(", ")"), ("{", "}"), ("[", "]")]
93+
braces: [('(', ')'), ('{', '}'), ('[', ']')]
10894
.into_iter()
10995
.find(|b| b.0 == brace)
11096
.map(|(o, c)| (o.to_owned(), c.to_owned()))

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,8 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
320320
extract_msrv_attr!({context_import});
321321
}}
322322
323-
// TODO: Add MSRV level to `clippy_utils/src/msrvs.rs` if needed.
324-
// TODO: Update msrv config comment in `clippy_lints/src/utils/conf.rs`
323+
// TODO: Add MSRV level to `clippy_config/src/msrvs.rs` if needed.
324+
// TODO: Update msrv config comment in `clippy_config/src/conf.rs`
325325
"#
326326
)
327327
} else {

src/tools/clippy/clippy_lints/Cargo.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy_lints"
3-
version = "0.1.75"
3+
version = "0.1.76"
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"
@@ -14,7 +14,6 @@ cargo_metadata = "0.15.3"
1414
clippy_config = { path = "../clippy_config" }
1515
clippy_utils = { path = "../clippy_utils" }
1616
declare_clippy_lint = { path = "../declare_clippy_lint" }
17-
if_chain = "1.0"
1817
itertools = "0.10.1"
1918
quine-mc_cluskey = "0.2"
2019
regex-syntax = "0.7"

src/tools/clippy/clippy_lints/src/allow_attributes.rs

+16-18
Original file line numberDiff line numberDiff line change
@@ -52,24 +52,22 @@ declare_lint_pass!(AllowAttribute => [ALLOW_ATTRIBUTES]);
5252
impl LateLintPass<'_> for AllowAttribute {
5353
// Separate each crate's features.
5454
fn check_attribute<'cx>(&mut self, cx: &LateContext<'cx>, attr: &'cx Attribute) {
55-
if_chain! {
56-
if !in_external_macro(cx.sess(), attr.span);
57-
if cx.tcx.features().lint_reasons;
58-
if let AttrStyle::Outer = attr.style;
59-
if let Some(ident) = attr.ident();
60-
if ident.name == rustc_span::symbol::sym::allow;
61-
if !is_from_proc_macro(cx, &attr);
62-
then {
63-
span_lint_and_sugg(
64-
cx,
65-
ALLOW_ATTRIBUTES,
66-
ident.span,
67-
"#[allow] attribute found",
68-
"replace it with",
69-
"expect".into(),
70-
Applicability::MachineApplicable,
71-
);
72-
}
55+
if !in_external_macro(cx.sess(), attr.span)
56+
&& cx.tcx.features().lint_reasons
57+
&& let AttrStyle::Outer = attr.style
58+
&& let Some(ident) = attr.ident()
59+
&& ident.name == rustc_span::symbol::sym::allow
60+
&& !is_from_proc_macro(cx, &attr)
61+
{
62+
span_lint_and_sugg(
63+
cx,
64+
ALLOW_ATTRIBUTES,
65+
ident.span,
66+
"#[allow] attribute found",
67+
"replace it with",
68+
"expect".into(),
69+
Applicability::MachineApplicable,
70+
);
7371
}
7472
}
7573
}

0 commit comments

Comments
 (0)