Skip to content

Clippy subtree update #119387

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 81 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
bafc1a2
fix: broken GitHub corner, with working dark/light
hamirmahal Dec 10, 2023
3168bcf
refactor: use CSS vars for GitHub Corner colors
hamirmahal Dec 11, 2023
bd38ff3
Add new `unconditional_recursion` lint
GuillaumeGomez Dec 8, 2023
2c867ce
Add ui tests for `unconditional_recursion` lint
GuillaumeGomez Dec 8, 2023
91fd01c
Add changelog for `unconditional_recursion`
GuillaumeGomez Dec 8, 2023
677ccca
Don't pass lint back out of lint decorator
compiler-errors Dec 8, 2023
d47b7bb
Appease the tools: clippy, rustdoc
compiler-errors Nov 28, 2023
058b74f
Do not lint `assertions_on_constants` for `const _: () = assert!(expr)`
StackOverflowExcept1on Dec 15, 2023
90ece56
simplify pattern
StackOverflowExcept1on Dec 15, 2023
e52405a
Do not consider `async { (impl IntoFuture).await }` as redundant
samueltardieu Dec 15, 2023
d517ae6
Rollup merge of #118727 - compiler-errors:lint-decorate, r=WaffleLapkin
workingjubilee Dec 15, 2023
8892420
New Lint: `Result_filter_map`
PartiallyUntyped Dec 4, 2023
3596d44
Merge commit 'a859e5cc1ce100df22346a1005da30532d04de59' into clippyup
flip1995 Dec 16, 2023
850d77e
[`redundant_pattern_matching`]: catch `if let true`
y21 Dec 16, 2023
bc22407
add tests, lint on `while let true` and `matches!(.., true)`
y21 Dec 16, 2023
6b444f3
Also check code generated by macros
GuillaumeGomez Dec 16, 2023
b918434
Auto merge of #11974 - y21:if_let_true, r=llogiq
bors Dec 16, 2023
9907b90
Auto merge of #11938 - GuillaumeGomez:unconditional_recursion, r=llogiq
bors Dec 16, 2023
b5169ae
don't visit any nested bodies in `is_const_evaluatable`
y21 Dec 16, 2023
fff484d
Auto merge of #11977 - y21:is_const_evaluatable_ice, r=Manishearth
bors Dec 16, 2023
f9b5def
Auto merge of #11869 - PartiallyTyped:result-filter-map, r=Alexendoo
bors Dec 16, 2023
dd857f8
Auto merge of #11966 - StackOverflowExcept1on:issue-8159, r=Jarcho
bors Dec 17, 2023
7e650b7
Auto merge of #11947 - hamirmahal:fix/broken-GitHub-corner, r=blyxyas…
bors Dec 17, 2023
22e769c
Rename `Handler` as `DiagCtxt`.
nnethercote Dec 17, 2023
42729d6
Rename `EarlyErrorHandler` as `EarlyDiagCtxt`.
nnethercote Dec 17, 2023
bc3a3bc
Rename `ParseSess::with_span_handler` as `ParseSess::with_dcx`.
nnethercote Dec 17, 2023
d165a38
Rename many `DiagCtxt` and `EarlyDiagCtxt` locals.
nnethercote Dec 18, 2023
71ea36b
Extend `UNNECESSARY_TO_OWNED` to handle `split`
GuillaumeGomez Nov 25, 2023
238c5f9
Add ui tests for `UNNECESSARY_TO_OWNED` on `split`
GuillaumeGomez Nov 25, 2023
212ea03
Plumb awaitness of for loops
eholk Dec 8, 2023
0628454
Give `VariantData::Struct` named fields, to clairfy `recovered`.
aDotInTheVoid Dec 19, 2023
25b9ca3
New lints `iter_filter_is_some` and `iter_filter_is_ok`
PartiallyUntyped Dec 20, 2023
a556d00
stop [`bool_comparison`]'s suggestion from consuming parentheses
J-ZhengLi Dec 21, 2023
dc97526
Auto merge of #11991 - J-ZhengLi:issue9911, r=llogiq
bors Dec 21, 2023
d020196
Add check for illegal accessing known length array with a constant index
cocodery Dec 22, 2023
18eb406
Add test for indexing_slicing_index and modify related test
cocodery Dec 22, 2023
4ad06d1
Auto merge of #118847 - eholk:for-await, r=compiler-errors
bors Dec 22, 2023
e0b25c5
Auto merge of #11998 - cocodery:fix/issue11762, r=llogiq
bors Dec 22, 2023
67a33e8
fix typo in infinite loop lint
Takashiidobe Dec 22, 2023
9c2be20
fix typos in default constructed unit structs, implied bounds, ineffe…
Takashiidobe Dec 22, 2023
5a9c25c
Split coroutine desugaring kind from source
compiler-errors Dec 21, 2023
3a4d99e
run cargo uibless
Takashiidobe Dec 23, 2023
d72771f
bool->enum for ast::PatKind::Struct presence of `..`
aDotInTheVoid Dec 22, 2023
2ddcfb8
Auto merge of #12000 - Takashiidobe:fix-some-typos, r=llogiq
bors Dec 23, 2023
858d96d
Auto merge of #11871 - GuillaumeGomez:UNNECESSARY_TO_OWNED-split, r=l…
bors Dec 23, 2023
618fd4b
Auto merge of #11999 - Takashiidobe:fix-typo-in-infinite-loop-lint, r…
bors Dec 23, 2023
dfb4ff8
[`question_mark`]: also trigger on `return` statements
y21 Dec 21, 2023
e44caea
respect comments in `question_mark`
y21 Dec 23, 2023
870a5d9
Rollup merge of #119231 - aDotInTheVoid:PatKind-struct-bool-docs, r=c…
matthiaskrgr Dec 23, 2023
1576ecc
Move uninhabited_references to nursery
TethysSvensson Dec 22, 2023
830f1c5
Auto merge of #11994 - y21:issue11993-fn, r=xFrednet
bors Dec 23, 2023
370615b
Auto merge of #11997 - TethysSvensson:uninhabited-references-pedantic…
bors Dec 23, 2023
620a1e4
Remove `Session` methods that duplicate `DiagCtxt` methods.
nnethercote Dec 18, 2023
4b1ac31
Added MSRV and more tests, improved wording
PartiallyUntyped Dec 24, 2023
2177f2c
formatting
PartiallyUntyped Dec 24, 2023
85e1646
more tests
PartiallyUntyped Dec 24, 2023
c1c52e9
Remove blyxyas from users_on_vacation
blyxyas Dec 25, 2023
5ab2319
Auto merge of #12011 - blyxyas:not-on-vacation, r=blyxyas
bors Dec 25, 2023
99c7838
Auto merge of #11967 - samueltardieu:issue-11959, r=llogiq
bors Dec 25, 2023
e0097f5
Fix clippy's usage of Body's coroutine_kind
compiler-errors Dec 25, 2023
90a59d4
Make some non-diagnostic-affecting QPath::LangItem into regular qpaths
compiler-errors Dec 23, 2023
91859ed
Auto merge of #119258 - compiler-errors:closure-kind, r=eholk
bors Dec 26, 2023
8990153
Update version attribute for 1.75 lints
xFrednet Dec 26, 2023
2087e24
Changelog for Rust 1.75 :christmas_tree:
xFrednet Dec 26, 2023
9dd2252
Auto merge of #12004 - PartiallyTyped:11843, r=xFrednet
bors Dec 26, 2023
2230add
Rollup merge of #119240 - compiler-errors:lang-item-more, r=petrochenkov
compiler-errors Dec 26, 2023
eb679c7
Auto merge of #12019 - xFrednet:changelog-1-75, r=flip1995
bors Dec 26, 2023
ae4ab9e
Fix typo in changelog for 1.75
xFrednet Dec 26, 2023
cda1701
Auto merge of #12022 - xFrednet:changelog-1-75, r=llogiq
bors Dec 26, 2023
f48b850
[doc_markdown]: Add "WebGL2", "WebGPU" to default `doc_valid_idents`
waywardmonkeys Dec 26, 2023
677f8d8
Auto merge of #12018 - waywardmonkeys:doc-markdown-allow-webgpu-webgl…
bors Dec 27, 2023
08d8ca9
new lint: `eager_int_transmute`
y21 Dec 18, 2023
c689d32
Auto merge of #11981 - y21:eager_int_transmute, r=llogiq
bors Dec 27, 2023
ebc0588
6459: Check for redundant `matches!` with `Ready`, `Pending`, `V4`, `V6`
torfsen Dec 27, 2023
7343db9
Auto merge of #12029 - torfsen:6459-more-cases-for-redundant-matches!…
bors Dec 27, 2023
9ff84af
Merge remote-tracking branch 'upstream/master' into rustup
flip1995 Dec 28, 2023
887278c
Bump nightly version -> 2023-12-28
flip1995 Dec 28, 2023
2a4c7d2
Bump Clippy version -> 0.1.77
flip1995 Dec 28, 2023
ac4c209
Auto merge of #12038 - flip1995:rustup, r=flip1995
bors Dec 28, 2023
379b00a
Merge commit 'ac4c2094a6030530661bee3876e0228ddfeb6b8b' into clippy-s…
flip1995 Dec 28, 2023
0217ac9
Update Cargo.lock
flip1995 Dec 28, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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