Skip to content

Commit

Permalink
Auto merge of rust-lang#117979 - flip1995:clippyup, r=matthiaskrgr
Browse files Browse the repository at this point in the history
Clippy subtree sync

r? `@Manishearth`
  • Loading branch information
bors committed Nov 16, 2023
2 parents 820f06b + 2ac2b26 commit a577704
Show file tree
Hide file tree
Showing 327 changed files with 10,343 additions and 10,376 deletions.
12 changes: 5 additions & 7 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b"

[[package]]
name = "clippy"
version = "0.1.75"
version = "0.1.76"
dependencies = [
"anstream",
"clippy_config",
Expand Down Expand Up @@ -581,7 +581,7 @@ dependencies = [

[[package]]
name = "clippy_config"
version = "0.1.75"
version = "0.1.76"
dependencies = [
"rustc-semver",
"serde",
Expand All @@ -604,14 +604,13 @@ dependencies = [

[[package]]
name = "clippy_lints"
version = "0.1.75"
version = "0.1.76"
dependencies = [
"arrayvec",
"cargo_metadata 0.15.4",
"clippy_config",
"clippy_utils",
"declare_clippy_lint",
"if_chain",
"itertools",
"quine-mc_cluskey",
"regex",
Expand All @@ -630,11 +629,10 @@ dependencies = [

[[package]]
name = "clippy_utils"
version = "0.1.75"
version = "0.1.76"
dependencies = [
"arrayvec",
"clippy_config",
"if_chain",
"itertools",
"rustc-semver",
]
Expand Down Expand Up @@ -1016,7 +1014,7 @@ checksum = "a0afaad2b26fa326569eb264b1363e8ae3357618c43982b3f285f0774ce76b69"

[[package]]
name = "declare_clippy_lint"
version = "0.1.75"
version = "0.1.76"
dependencies = [
"itertools",
"quote",
Expand Down
64 changes: 62 additions & 2 deletions src/tools/clippy/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,70 @@ document.

## Unreleased / Beta / In Rust Nightly

[1e8fdf49...master](https://github.com/rust-lang/rust-clippy/compare/1e8fdf49...master)
[7671c283...master](https://github.com/rust-lang/rust-clippy/compare/7671c283...master)

## Rust 1.74

Current stable, released 2023-11-16

[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)

### New Lints

* [`redundant_as_str`]
[#11526](https://github.com/rust-lang/rust-clippy/pull/11526)
* [`needless_borrows_for_generic_args`]
[#11511](https://github.com/rust-lang/rust-clippy/pull/11511)
* [`path_ends_with_ext`]
[#11483](https://github.com/rust-lang/rust-clippy/pull/11483)
* [`unnecessary_map_on_constructor`]
[#11413](https://github.com/rust-lang/rust-clippy/pull/11413)
* [`missing_asserts_for_indexing`]
[#10692](https://github.com/rust-lang/rust-clippy/pull/10692)
* [`iter_out_of_bounds`]
[#11396](https://github.com/rust-lang/rust-clippy/pull/11396)
* [`implied_bounds_in_impls`]
[#11362](https://github.com/rust-lang/rust-clippy/pull/11362)
* [`reserve_after_initialization`]
[#11373](https://github.com/rust-lang/rust-clippy/pull/11373)
* [`should_panic_without_expect`]
[#11204](https://github.com/rust-lang/rust-clippy/pull/11204)

### Moves and Deprecations

* Renamed `incorrect_clone_impl_on_copy_type` to [`non_canonical_clone_impl`]
[#11358](https://github.com/rust-lang/rust-clippy/pull/11358)
* Renamed `incorrect_partial_ord_impl_on_ord_type` to [`non_canonical_partial_ord_impl`]
[#11358](https://github.com/rust-lang/rust-clippy/pull/11358)
* Moved [`non_canonical_clone_impl`] to `suspicious` (Now warn-by-default)
[#11358](https://github.com/rust-lang/rust-clippy/pull/11358)
* Moved [`non_canonical_partial_ord_impl`] to `suspicious` (Now warn-by-default)
[#11358](https://github.com/rust-lang/rust-clippy/pull/11358)
* Moved [`needless_pass_by_ref_mut`] to `nursery` (Now allow-by-default)
[#11596](https://github.com/rust-lang/rust-clippy/pull/11596)

### Enhancements

* [`undocumented_unsafe_blocks`]: The config values [`accept-comment-above-statement`] and
[`accept-comment-above-attributes`] to `true` by default
[#11170](https://github.com/rust-lang/rust-clippy/pull/11170)
* [`explicit_iter_loop`]: Added [`enforce-iter-loop-reborrow`] to disable reborrow linting by default
[#11418](https://github.com/rust-lang/rust-clippy/pull/11418)

### ICE Fixes

* [`enum_variant_names`]: No longer crashes if the threshold is 0 and the enum has no variants
[#11552](https://github.com/rust-lang/rust-clippy/pull/11552)
* [`cast_possible_truncation`]: No longer crashes on values larger than `u64::MAX`
[#11517](https://github.com/rust-lang/rust-clippy/pull/11517)
* [`tuple_array_conversions`]: No longer crashes if the array length is not usize
[#11379](https://github.com/rust-lang/rust-clippy/pull/11379)
* [`useless_conversion`]: No longer crashes, when the receiver is a non-fn item
[#11070](https://github.com/rust-lang/rust-clippy/pull/11070)

## Rust 1.73

Current stable, released 2023-10-05
Released 2023-10-05

[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)

Expand Down Expand Up @@ -5123,6 +5182,7 @@ Released 2018-09-13
[`iter_on_empty_collections`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_on_empty_collections
[`iter_on_single_items`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_on_single_items
[`iter_out_of_bounds`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_out_of_bounds
[`iter_over_hash_type`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_over_hash_type
[`iter_overeager_cloned`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_overeager_cloned
[`iter_skip_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_skip_next
[`iter_skip_zero`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_skip_zero
Expand Down
8 changes: 1 addition & 7 deletions src/tools/clippy/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,10 @@ For example, the [`else_if_without_else`][else_if_without_else] lint is register
pub mod else_if_without_else;
// ...

pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: &Conf) {
pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) {
// ...
store.register_early_pass(|| Box::new(else_if_without_else::ElseIfWithoutElse));
// ...

store.register_group(true, "clippy::restriction", Some("clippy_restriction"), vec![
// ...
LintId::of(&else_if_without_else::ELSE_IF_WITHOUT_ELSE),
// ...
]);
}
```

Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "clippy"
version = "0.1.75"
version = "0.1.76"
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
repository = "https://github.com/rust-lang/rust-clippy"
readme = "README.md"
Expand Down
12 changes: 6 additions & 6 deletions src/tools/clippy/book/src/development/adding_lints.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ When using `cargo dev new_lint`, the lint is automatically registered and
nothing more has to be done.

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

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

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

```rust
Expand Down Expand Up @@ -506,7 +506,7 @@ fn msrv_1_45() {
```

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

```rust
define_Conf! {
Expand All @@ -516,7 +516,7 @@ define_Conf! {
}
```

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

## Author lint

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

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

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

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

[`clippy_lints::utils::conf`]: https://github.com/rust-lang/rust-clippy/blob/master/clippy_lints/src/utils/conf.rs
[`clippy_config::conf`]: https://github.com/rust-lang/rust-clippy/blob/master/clippy_config/src/conf.rs
[`clippy_lints` lib file]: https://github.com/rust-lang/rust-clippy/blob/master/clippy_lints/src/lib.rs
[`tests/ui`]: https://github.com/rust-lang/rust-clippy/blob/master/tests/ui
[`tests/ui-toml`]: https://github.com/rust-lang/rust-clippy/blob/master/tests/ui-toml
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/book/src/development/defining_lints.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ However, sometimes we might want to declare a new lint by hand. In this case,
we'd use `cargo dev update_lints` command afterwards.

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

```rust
store.register_late_pass(|_| Box::new(foo_functions::FooFunctions));
Expand Down
6 changes: 6 additions & 0 deletions src/tools/clippy/clippy.toml
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
avoid-breaking-exported-api = false

# use the various `span_lint_*` methods instead, which also add a link to the docs
disallowed-methods = [
"rustc_lint::context::LintContext::struct_span_lint",
"rustc_middle::ty::context::TyCtxt::struct_span_lint_hir"
]
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_config/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "clippy_config"
version = "0.1.75"
version = "0.1.76"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
24 changes: 5 additions & 19 deletions src/tools/clippy/clippy_config/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use serde::de::{self, Deserializer, Visitor};
use serde::{ser, Deserialize, Serialize};
use std::fmt;
use std::hash::{Hash, Hasher};

#[derive(Clone, Debug, Deserialize)]
pub struct Rename {
Expand Down Expand Up @@ -33,32 +32,19 @@ impl DisallowedPath {
}
}

#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Deserialize, Serialize)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize, Serialize)]
pub enum MatchLintBehaviour {
AllTypes,
WellKnownTypes,
Never,
}

#[derive(Clone, Debug)]
#[derive(Debug)]
pub struct MacroMatcher {
pub name: String,
pub braces: (String, String),
pub braces: (char, char),
}

impl Hash for MacroMatcher {
fn hash<H: Hasher>(&self, state: &mut H) {
self.name.hash(state);
}
}

impl PartialEq for MacroMatcher {
fn eq(&self, other: &Self) -> bool {
self.name == other.name
}
}
impl Eq for MacroMatcher {}

impl<'de> Deserialize<'de> for MacroMatcher {
fn deserialize<D>(deser: D) -> Result<Self, D::Error>
where
Expand All @@ -83,7 +69,7 @@ impl<'de> Deserialize<'de> for MacroMatcher {
V: de::MapAccess<'de>,
{
let mut name = None;
let mut brace: Option<String> = None;
let mut brace: Option<char> = None;
while let Some(key) = map.next_key()? {
match key {
Field::Name => {
Expand All @@ -104,7 +90,7 @@ impl<'de> Deserialize<'de> for MacroMatcher {
let brace = brace.ok_or_else(|| de::Error::missing_field("brace"))?;
Ok(MacroMatcher {
name,
braces: [("(", ")"), ("{", "}"), ("[", "]")]
braces: [('(', ')'), ('{', '}'), ('[', ']')]
.into_iter()
.find(|b| b.0 == brace)
.map(|(o, c)| (o.to_owned(), c.to_owned()))
Expand Down
4 changes: 2 additions & 2 deletions src/tools/clippy/clippy_dev/src/new_lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,8 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
extract_msrv_attr!({context_import});
}}
// TODO: Add MSRV level to `clippy_utils/src/msrvs.rs` if needed.
// TODO: Update msrv config comment in `clippy_lints/src/utils/conf.rs`
// TODO: Add MSRV level to `clippy_config/src/msrvs.rs` if needed.
// TODO: Update msrv config comment in `clippy_config/src/conf.rs`
"#
)
} else {
Expand Down
3 changes: 1 addition & 2 deletions src/tools/clippy/clippy_lints/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "clippy_lints"
version = "0.1.75"
version = "0.1.76"
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
repository = "https://github.com/rust-lang/rust-clippy"
readme = "README.md"
Expand All @@ -14,7 +14,6 @@ cargo_metadata = "0.15.3"
clippy_config = { path = "../clippy_config" }
clippy_utils = { path = "../clippy_utils" }
declare_clippy_lint = { path = "../declare_clippy_lint" }
if_chain = "1.0"
itertools = "0.10.1"
quine-mc_cluskey = "0.2"
regex-syntax = "0.7"
Expand Down
34 changes: 16 additions & 18 deletions src/tools/clippy/clippy_lints/src/allow_attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,22 @@ declare_lint_pass!(AllowAttribute => [ALLOW_ATTRIBUTES]);
impl LateLintPass<'_> for AllowAttribute {
// Separate each crate's features.
fn check_attribute<'cx>(&mut self, cx: &LateContext<'cx>, attr: &'cx Attribute) {
if_chain! {
if !in_external_macro(cx.sess(), attr.span);
if cx.tcx.features().lint_reasons;
if let AttrStyle::Outer = attr.style;
if let Some(ident) = attr.ident();
if ident.name == rustc_span::symbol::sym::allow;
if !is_from_proc_macro(cx, &attr);
then {
span_lint_and_sugg(
cx,
ALLOW_ATTRIBUTES,
ident.span,
"#[allow] attribute found",
"replace it with",
"expect".into(),
Applicability::MachineApplicable,
);
}
if !in_external_macro(cx.sess(), attr.span)
&& cx.tcx.features().lint_reasons
&& let AttrStyle::Outer = attr.style
&& let Some(ident) = attr.ident()
&& ident.name == rustc_span::symbol::sym::allow
&& !is_from_proc_macro(cx, &attr)
{
span_lint_and_sugg(
cx,
ALLOW_ATTRIBUTES,
ident.span,
"#[allow] attribute found",
"replace it with",
"expect".into(),
Applicability::MachineApplicable,
);
}
}
}
Loading

0 comments on commit a577704

Please sign in to comment.