Skip to content

Commit

Permalink
Auto merge of rust-lang#119387 - flip1995:clippy-subtree-sync, r=matt…
Browse files Browse the repository at this point in the history
…hiaskrgr

Clippy subtree update

r? `@Manishearth`
  • Loading branch information
bors committed Dec 29, 2023
2 parents b74f5c4 + 0217ac9 commit 1a7e97f
Show file tree
Hide file tree
Showing 119 changed files with 2,536 additions and 326 deletions.
10 changes: 5 additions & 5 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b"

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

[[package]]
name = "clippy_config"
version = "0.1.76"
version = "0.1.77"
dependencies = [
"rustc-semver",
"serde",
Expand All @@ -588,7 +588,7 @@ dependencies = [

[[package]]
name = "clippy_lints"
version = "0.1.76"
version = "0.1.77"
dependencies = [
"arrayvec",
"cargo_metadata 0.15.4",
Expand All @@ -613,7 +613,7 @@ dependencies = [

[[package]]
name = "clippy_utils"
version = "0.1.76"
version = "0.1.77"
dependencies = [
"arrayvec",
"clippy_config",
Expand Down Expand Up @@ -984,7 +984,7 @@ checksum = "a0afaad2b26fa326569eb264b1363e8ae3357618c43982b3f285f0774ce76b69"

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

## Unreleased / Beta / In Rust Nightly

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

## Rust 1.75

Current stable, released 2023-12-28

[View all 69 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2023-09-25T11%3A47%3A47Z..2023-11-02T16%3A41%3A59Z+base%3Amaster)

### New Lints

* [`unused_enumerate_index`]
[#10404](https://github.com/rust-lang/rust-clippy/pull/10404)
* [`unnecessary_fallible_conversions`]
[#11669](https://github.com/rust-lang/rust-clippy/pull/11669)
* [`waker_clone_wake`]
[#11698](https://github.com/rust-lang/rust-clippy/pull/11698)
* [`struct_field_names`]
[#11496](https://github.com/rust-lang/rust-clippy/pull/11496)
* [`into_iter_without_iter`]
[#11587](https://github.com/rust-lang/rust-clippy/pull/11587)
* [`iter_without_into_iter`]
[#11527](https://github.com/rust-lang/rust-clippy/pull/11527)
* [`manual_hash_one`]
[#11556](https://github.com/rust-lang/rust-clippy/pull/11556)


### Moves and Deprecations

* Moved [`read_zero_byte_vec`] to `nursery` (Now allow-by-default)
[#11727](https://github.com/rust-lang/rust-clippy/pull/11727)
* Moved [`missing_enforced_import_renames`] to `style` (Now warn-by-default)
[#11539](https://github.com/rust-lang/rust-clippy/pull/11539)
* Moved [`needless_raw_string_hashes`] to `pedantic` (Now allow-by-default)
[#11415](https://github.com/rust-lang/rust-clippy/pull/11415)
* Moved [`needless_pass_by_ref_mut`] to `nursery` (Now allow-by-default)
[#11596](https://github.com/rust-lang/rust-clippy/pull/11596)

### Enhancements

* [`declare_interior_mutable_const`] and [`borrow_interior_mutable_const`]: Now check the
[`ignore-interior-mutability`] config value
[#11678](https://github.com/rust-lang/rust-clippy/pull/11678)

### Suggestion Fixes/Improvements

* [`items_after_test_module`]: The suggestion is now machine-applicable
[#11611](https://github.com/rust-lang/rust-clippy/pull/11611)

### ICE Fixes

* [`redundant_locals`]: No longer crashes if variables are rebound above macros
[#11623](https://github.com/rust-lang/rust-clippy/pull/11623)
* [`implicit_hasher`]: No longer lints inside macros, which could cause ICEs
[#11593](https://github.com/rust-lang/rust-clippy/pull/11593)

### Documentation Improvements

* `cargo clippy --help` now uses colors for readability :tada:

## Rust 1.74

Current stable, released 2023-11-16
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)

Expand Down Expand Up @@ -51,7 +108,7 @@ Current stable, released 2023-11-16
### Enhancements

* [`undocumented_unsafe_blocks`]: The config values [`accept-comment-above-statement`] and
[`accept-comment-above-attributes`] to `true` by default
[`accept-comment-above-attributes`] are now `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)
Expand Down Expand Up @@ -5044,6 +5101,7 @@ Released 2018-09-13
[`duplicate_mod`]: https://rust-lang.github.io/rust-clippy/master/index.html#duplicate_mod
[`duplicate_underscore_argument`]: https://rust-lang.github.io/rust-clippy/master/index.html#duplicate_underscore_argument
[`duration_subsec`]: https://rust-lang.github.io/rust-clippy/master/index.html#duration_subsec
[`eager_transmute`]: https://rust-lang.github.io/rust-clippy/master/index.html#eager_transmute
[`else_if_without_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#else_if_without_else
[`empty_drop`]: https://rust-lang.github.io/rust-clippy/master/index.html#empty_drop
[`empty_enum`]: https://rust-lang.github.io/rust-clippy/master/index.html#empty_enum
Expand Down Expand Up @@ -5177,6 +5235,8 @@ Released 2018-09-13
[`items_after_test_module`]: https://rust-lang.github.io/rust-clippy/master/index.html#items_after_test_module
[`iter_cloned_collect`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_cloned_collect
[`iter_count`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_count
[`iter_filter_is_ok`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_filter_is_ok
[`iter_filter_is_some`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_filter_is_some
[`iter_kv_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_kv_map
[`iter_next_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_next_loop
[`iter_next_slice`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_next_slice
Expand Down Expand Up @@ -5470,6 +5530,7 @@ Released 2018-09-13
[`reserve_after_initialization`]: https://rust-lang.github.io/rust-clippy/master/index.html#reserve_after_initialization
[`rest_pat_in_fully_bound_structs`]: https://rust-lang.github.io/rust-clippy/master/index.html#rest_pat_in_fully_bound_structs
[`result_expect_used`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_expect_used
[`result_filter_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_filter_map
[`result_large_err`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_large_err
[`result_map_or_into_option`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_map_or_into_option
[`result_map_unit_fn`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_map_unit_fn
Expand Down Expand Up @@ -5582,6 +5643,7 @@ Released 2018-09-13
[`type_id_on_box`]: https://rust-lang.github.io/rust-clippy/master/index.html#type_id_on_box
[`type_repetition_in_bounds`]: https://rust-lang.github.io/rust-clippy/master/index.html#type_repetition_in_bounds
[`unchecked_duration_subtraction`]: https://rust-lang.github.io/rust-clippy/master/index.html#unchecked_duration_subtraction
[`unconditional_recursion`]: https://rust-lang.github.io/rust-clippy/master/index.html#unconditional_recursion
[`undocumented_unsafe_blocks`]: https://rust-lang.github.io/rust-clippy/master/index.html#undocumented_unsafe_blocks
[`undropped_manually_drops`]: https://rust-lang.github.io/rust-clippy/master/index.html#undropped_manually_drops
[`unicode_not_nfc`]: https://rust-lang.github.io/rust-clippy/master/index.html#unicode_not_nfc
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.76"
version = "0.1.77"
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
2 changes: 1 addition & 1 deletion src/tools/clippy/book/src/lint_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ default configuration of Clippy. By default, any configuration will replace the
* `doc-valid-idents = ["ClipPy"]` would replace the default list with `["ClipPy"]`.
* `doc-valid-idents = ["ClipPy", ".."]` would append `ClipPy` to the default list.

**Default Value:** `["KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "DirectX", "ECMAScript", "GPLv2", "GPLv3", "GitHub", "GitLab", "IPv4", "IPv6", "ClojureScript", "CoffeeScript", "JavaScript", "PureScript", "TypeScript", "WebAssembly", "NaN", "NaNs", "OAuth", "GraphQL", "OCaml", "OpenGL", "OpenMP", "OpenSSH", "OpenSSL", "OpenStreetMap", "OpenDNS", "WebGL", "TensorFlow", "TrueType", "iOS", "macOS", "FreeBSD", "TeX", "LaTeX", "BibTeX", "BibLaTeX", "MinGW", "CamelCase"]`
**Default Value:** `["KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "DirectX", "ECMAScript", "GPLv2", "GPLv3", "GitHub", "GitLab", "IPv4", "IPv6", "ClojureScript", "CoffeeScript", "JavaScript", "PureScript", "TypeScript", "WebAssembly", "NaN", "NaNs", "OAuth", "GraphQL", "OCaml", "OpenGL", "OpenMP", "OpenSSH", "OpenSSL", "OpenStreetMap", "OpenDNS", "WebGL", "WebGL2", "WebGPU", "TensorFlow", "TrueType", "iOS", "macOS", "FreeBSD", "TeX", "LaTeX", "BibTeX", "BibLaTeX", "MinGW", "CamelCase"]`

---
**Affected lints:**
Expand Down
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.76"
version = "0.1.77"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
5 changes: 3 additions & 2 deletions src/tools/clippy/clippy_config/src/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const DEFAULT_DOC_VALID_IDENTS: &[&str] = &[
"OAuth", "GraphQL",
"OCaml",
"OpenGL", "OpenMP", "OpenSSH", "OpenSSL", "OpenStreetMap", "OpenDNS",
"WebGL",
"WebGL", "WebGL2", "WebGPU",
"TensorFlow",
"TrueType",
"iOS", "macOS", "FreeBSD",
Expand Down Expand Up @@ -640,7 +640,8 @@ impl Conf {
}
},
Err(error) => {
sess.dcx().err(format!("error finding Clippy's configuration file: {error}"));
sess.dcx()
.err(format!("error finding Clippy's configuration file: {error}"));
},
}

Expand Down
7 changes: 5 additions & 2 deletions src/tools/clippy/clippy_config/src/msrvs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ msrv_aliases! {
1,35,0 { OPTION_COPIED, RANGE_CONTAINS }
1,34,0 { TRY_FROM }
1,30,0 { ITERATOR_FIND_MAP, TOOL_ATTRIBUTES }
1,29,0 { ITER_FLATTEN }
1,28,0 { FROM_BOOL }
1,27,0 { ITERATOR_TRY_FOLD }
1,26,0 { RANGE_INCLUSIVE, STRING_RETAIN }
Expand Down Expand Up @@ -106,7 +107,8 @@ impl Msrv {

if let Some(msrv_attr) = msrv_attrs.next() {
if let Some(duplicate) = msrv_attrs.last() {
sess.dcx().struct_span_err(duplicate.span, "`clippy::msrv` is defined multiple times")
sess.dcx()
.struct_span_err(duplicate.span, "`clippy::msrv` is defined multiple times")
.span_note(msrv_attr.span, "first definition found here")
.emit();
}
Expand All @@ -116,7 +118,8 @@ impl Msrv {
return Some(version);
}

sess.dcx().span_err(msrv_attr.span, format!("`{msrv}` is not a valid Rust version"));
sess.dcx()
.span_err(msrv_attr.span, format!("`{msrv}` is not a valid Rust version"));
} else {
sess.dcx().span_err(msrv_attr.span, "bad clippy attribute");
}
Expand Down
2 changes: 1 addition & 1 deletion 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.76"
version = "0.1.77"
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
15 changes: 12 additions & 3 deletions src/tools/clippy/clippy_lints/src/assertions_on_constants.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use clippy_utils::consts::{constant, Constant};
use clippy_utils::consts::{constant_with_source, Constant, ConstantSource};
use clippy_utils::diagnostics::span_lint_and_help;
use clippy_utils::macros::{find_assert_args, root_macro_call_first_node, PanicExpn};
use rustc_hir::Expr;
use rustc_hir::{Expr, Item, ItemKind, Node};
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::declare_lint_pass;
use rustc_span::sym;
Expand Down Expand Up @@ -42,9 +42,18 @@ impl<'tcx> LateLintPass<'tcx> for AssertionsOnConstants {
let Some((condition, panic_expn)) = find_assert_args(cx, e, macro_call.expn) else {
return;
};
let Some(Constant::Bool(val)) = constant(cx, cx.typeck_results(), condition) else {
let Some((Constant::Bool(val), source)) = constant_with_source(cx, cx.typeck_results(), condition) else {
return;
};
if let ConstantSource::Constant = source
&& let Some(node) = cx.tcx.hir().find_parent(e.hir_id)
&& let Node::Item(Item {
kind: ItemKind::Const(..),
..
}) = node
{
return;
}
if val {
span_lint_and_help(
cx,
Expand Down
4 changes: 1 addition & 3 deletions src/tools/clippy/clippy_lints/src/async_yields_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ use clippy_utils::diagnostics::span_lint_hir_and_then;
use clippy_utils::source::snippet;
use clippy_utils::ty::implements_trait;
use rustc_errors::Applicability;
use rustc_hir::{
Closure, ClosureKind, CoroutineDesugaring, CoroutineKind, CoroutineSource, Expr, ExprKind, QPath,
};
use rustc_hir::{Closure, ClosureKind, CoroutineDesugaring, CoroutineKind, CoroutineSource, Expr, ExprKind, QPath};
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::declare_lint_pass;

Expand Down
5 changes: 5 additions & 0 deletions src/tools/clippy/clippy_lints/src/declared_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,8 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
crate::methods::ITERATOR_STEP_BY_ZERO_INFO,
crate::methods::ITER_CLONED_COLLECT_INFO,
crate::methods::ITER_COUNT_INFO,
crate::methods::ITER_FILTER_IS_OK_INFO,
crate::methods::ITER_FILTER_IS_SOME_INFO,
crate::methods::ITER_KV_MAP_INFO,
crate::methods::ITER_NEXT_SLICE_INFO,
crate::methods::ITER_NTH_INFO,
Expand Down Expand Up @@ -419,6 +421,7 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
crate::methods::READ_LINE_WITHOUT_TRIM_INFO,
crate::methods::REDUNDANT_AS_STR_INFO,
crate::methods::REPEAT_ONCE_INFO,
crate::methods::RESULT_FILTER_MAP_INFO,
crate::methods::RESULT_MAP_OR_INTO_OPTION_INFO,
crate::methods::SEARCH_IS_SOME_INFO,
crate::methods::SEEK_FROM_CURRENT_INFO,
Expand Down Expand Up @@ -650,6 +653,7 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
crate::trait_bounds::TRAIT_DUPLICATION_IN_BOUNDS_INFO,
crate::trait_bounds::TYPE_REPETITION_IN_BOUNDS_INFO,
crate::transmute::CROSSPOINTER_TRANSMUTE_INFO,
crate::transmute::EAGER_TRANSMUTE_INFO,
crate::transmute::TRANSMUTES_EXPRESSIBLE_AS_PTR_CASTS_INFO,
crate::transmute::TRANSMUTE_BYTES_TO_STR_INFO,
crate::transmute::TRANSMUTE_FLOAT_TO_INT_INFO,
Expand All @@ -676,6 +680,7 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
crate::types::REDUNDANT_ALLOCATION_INFO,
crate::types::TYPE_COMPLEXITY_INFO,
crate::types::VEC_BOX_INFO,
crate::unconditional_recursion::UNCONDITIONAL_RECURSION_INFO,
crate::undocumented_unsafe_blocks::UNDOCUMENTED_UNSAFE_BLOCKS_INFO,
crate::undocumented_unsafe_blocks::UNNECESSARY_SAFETY_COMMENT_INFO,
crate::unicode::INVISIBLE_CHARACTERS_INFO,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ declare_clippy_lint! {
#[clippy::version = "1.71.0"]
pub DEFAULT_CONSTRUCTED_UNIT_STRUCTS,
complexity,
"unit structs can be contructed without calling `default`"
"unit structs can be constructed without calling `default`"
}
declare_lint_pass!(DefaultConstructedUnitStructs => [DEFAULT_CONSTRUCTED_UNIT_STRUCTS]);

Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/format_push_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fn is_format(cx: &LateContext<'_>, e: &Expr<'_>) -> bool {
Some(higher::IfLetOrMatch::Match(_, arms, MatchSource::Normal)) => {
arms.iter().any(|arm| is_format(cx, arm.body))
},
Some(higher::IfLetOrMatch::IfLet(_, _, then, r#else)) => {
Some(higher::IfLetOrMatch::IfLet(_, _, then, r#else, _)) => {
is_format(cx, then) || r#else.is_some_and(|e| is_format(cx, e))
},
_ => false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ fn try_resolve_type<'tcx>(

/// This function tries to, for all generic type parameters in a supertrait predicate `trait ...<U>:
/// GenericTrait<U>`, check if the substituted type in the implied-by bound matches with what's
/// subtituted in the implied bound.
/// substituted in the implied bound.
///
/// Consider this example.
/// ```rust,ignore
Expand Down
18 changes: 17 additions & 1 deletion src/tools/clippy/clippy_lints/src/indexing_slicing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,23 @@ impl<'tcx> LateLintPass<'tcx> for IndexingSlicing {
return;
}
// Index is a constant uint.
if constant(cx, cx.typeck_results(), index).is_some() {
if let Some(constant) = constant(cx, cx.typeck_results(), index) {
// only `usize` index is legal in rust array index
// leave other type to rustc
if let Constant::Int(off) = constant
&& let ty::Uint(utype) = cx.typeck_results().expr_ty(index).kind()
&& *utype == ty::UintTy::Usize
&& let ty::Array(_, s) = ty.kind()
&& let Some(size) = s.try_eval_target_usize(cx.tcx, cx.param_env)
{
// get constant offset and check whether it is in bounds
let off = usize::try_from(off).unwrap();
let size = usize::try_from(size).unwrap();

if off >= size {
span_lint(cx, OUT_OF_BOUNDS_INDEXING, expr.span, "index is out of bounds");
}
}
// Let rustc's `const_err` lint handle constant `usize` indexing on arrays.
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ declare_clippy_lint! {
///
/// ### Why is this bad?
/// `.append(true)` already enables `write(true)`, making this one
/// superflous.
/// superfluous.
///
/// ### Example
/// ```no_run
Expand Down
4 changes: 2 additions & 2 deletions src/tools/clippy/clippy_lints/src/iter_without_into_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ declare_clippy_lint! {
/// }
/// }
/// ```
#[clippy::version = "1.74.0"]
#[clippy::version = "1.75.0"]
pub ITER_WITHOUT_INTO_ITER,
pedantic,
"implementing `iter(_mut)` without an associated `IntoIterator for (&|&mut) Type` impl"
Expand Down Expand Up @@ -101,7 +101,7 @@ declare_clippy_lint! {
/// }
/// }
/// ```
#[clippy::version = "1.74.0"]
#[clippy::version = "1.75.0"]
pub INTO_ITER_WITHOUT_ITER,
pedantic,
"implementing `IntoIterator for (&|&mut) Type` without an inherent `iter(_mut)` method"
Expand Down
Loading

0 comments on commit 1a7e97f

Please sign in to comment.