about summary refs log tree commit diff
path: root/clippy_lints/src
AgeCommit message (Collapse)AuthorLines
2025-03-10make `never_loop` applicability more flexiblelapla-cogito-4/+21
2025-02-21rename `MANUAL_DIV_CEIL` MSRV alias and add missing conf info for ↵Alejandra González-1/+1
`manual_div_ceil` (#14263) - The name of an MSRV alias should describe its functionality, and it is not appropriate for it to be the same as the name of the lint that uses it. - Additionally, while `manual_div_ceil` allows setting MSRV, this is not correctly reflected in the configuration information. changelog: none
2025-02-21Represent the capability instead of the lint name in msrv aliasesSamuel Tardieu-1/+1
`INTEGER_BITS` better represents the addition of the `BITS` value on the primitive integer types.
2025-02-20Remove obsolete comment and simplify codeSamuel Tardieu-20/+14
The `IoBufRead` diagnostic has been added during the latest rustup.
2025-02-20Rustup (#14262)Philipp Krones-742/+808
r? @ghost changelog: none
2025-02-20add `owned_cow` lint (#13948)Timo-1/+128
Closes #13697. --- changelog: add [`owned_cow`] lint
2025-02-20Changelog for Clippy 1.85 🦜 (#14229)Fridtjof Stoldt-4/+4
Roses are red, Biolets are blue, A typo happened, too late now You might be asking, what are Biolets now? And to be honest, I have no clue --- The cat of this release is `Vera` nominated by @and-reas-se <img height=500 src="https://github.com/user-attachments/assets/82e6fccc-1f6d-4d29-b6bb-0bd4f3584593" alt="The cats of this Clippy release" /> Cats for the next release can be nominated in the comments :D --- changelog: none
2025-02-20rename the MSRV alias `MANUAL_DIV_CEIL` to `DIV_CEIL`lapla-cogito-1/+1
2025-02-20Merge remote-tracking branch 'upstream/master' into rustupPhilipp Krones-369/+885
2025-02-19add `owned_cow` lintAndre Bogus-1/+128
2025-02-19fix: `map_entry` FP on struct member (#14151)Catherine Flores-1/+16
fixes #13934 I modified the part for checking if the map is used so that it can check field and index exprs. changelog: [`map_entry`]: fix FP on struct member
2025-02-19`.last()` to `.next_back()` requires a mutable receiver (#14140)Catherine Flores-20/+43
In the case where `iter` is a `DoubleEndedIterator`, replacing a call to `iter.last()` (which consumes `iter`) by `iter.next_back()` (which requires a mutable reference to `iter`) cannot be done when `iter` is a non-mutable binding which is not a mutable reference. When possible, a local immutable binding is made into a mutable one. Also, the applicability is switched to `MaybeIncorrect` and a note is added to the output when the element types have a significant drop, because the drop order will potentially be modified because `.next_back()` does not consume the iterator nor the elements before the last one. Fix #14139 changelog: [`double_ended_iterator_last`]: do not trigger on non-reference immutable receiver, and warn about possible drop order change
2025-02-19`double_ended_iterator_last`: note when drop order is changedSamuel Tardieu-0/+7
`iter.last()` will drop all elements of `iter` in order, while `iter.next_back()` will drop the non-last elements of `iter` when `iter` goes out of scope since `.next_back()` does not consume its argument. When the transformation proposed by `double_ended_iterator_last` would concern an iterator whose element type has a significant drop, a note is added to warn about the possible drop order change, and the suggestion is switched from `MachineApplicable` to `MaybeIncorrect`.
2025-02-19fix: `map_entry` FP on struct memberyanglsh-1/+16
2025-02-18add a preferred fix for `cast_possible_wrap` description (#14225)Alejandra González-1/+7
close #9250 changelog: none
2025-02-18`.last()` to `.next_back()` requires a mutable receiverSamuel Tardieu-8/+34
In the case where `iter` is a `DoubleEndedIterator`, replacing a call to `iter.last()` (which consumes `iter`) by `iter.next_back()` (which requires a mutable reference to `iter`) cannot be done when `iter` Is not a mutable binding or a mutable reference. When `iter` is a local binding, it can be made mutable by fixing its definition site.
2025-02-18remove an unneeded `#![feature]`cyrgani-1/+0
2025-02-18Move methods from `Map` to `TyCtxt`, part 2.Nicholas Nethercote-35/+29
Continuing the work started in #136466. Every method gains a `hir_` prefix, though for the ones that already have a `par_` or `try_par_` prefix I added the `hir_` after that.
2025-02-17Update mention of `ref_to_mut` to `invalid_reference_casting` (#14241)Manish Goregaokar-6/+18
This lint was renamed in 50da77521e922f17735b9d97461925ca0f3dec1c. While I'm here convert the list of separate lints into a proper list for ease of use. changelog: none
2025-02-17Update mention of `ref_to_mut` to `invalid_reference_casting`Tamir Duberstein-6/+18
This lint was renamed in 50da77521e922f17735b9d97461925ca0f3dec1c. While I'm here convert the list of separate lints into a proper list for ease of use and clarify which lints are in clippy and which are in rustc.
2025-02-17`manual_ok_err`: blockify the replacement of an `else if …`Samuel Tardieu-2/+13
If the part being replaced is an `if` expression following an `else`, the replacement expression must be blockified.
2025-02-17Rollup merge of #137101 - GrigorenkoPV:str-inherent-lint, r=UrgauMatthias Krüger-4/+5
`invalid_from_utf8[_unchecked]`: also lint inherent methods Addressing https://github.com/rust-lang/rust/issues/131114#issuecomment-2646663535 Also corrected a typo: "_an_ invalid literal", not "_a_ invalid literal".
2025-02-17Overhaul the `intravisit::Map` trait.Nicholas Nethercote-50/+47
First of all, note that `Map` has three different relevant meanings. - The `intravisit::Map` trait. - The `map::Map` struct. - The `NestedFilter::Map` associated type. The `intravisit::Map` trait is impl'd twice. - For `!`, where the methods are all unreachable. - For `map::Map`, which gets HIR stuff from the `TyCtxt`. As part of getting rid of `map::Map`, this commit changes `impl intravisit::Map for map::Map` to `impl intravisit::Map for TyCtxt`. It's fairly straightforward except various things are renamed, because the existing names would no longer have made sense. - `trait intravisit::Map` becomes `trait intravisit::HirTyCtxt`, so named because it gets some HIR stuff from a `TyCtxt`. - `NestedFilter::Map` assoc type becomes `NestedFilter::MaybeTyCtxt`, because it's always `!` or `TyCtxt`. - `Visitor::nested_visit_map` becomes `Visitor::maybe_tcx`. I deliberately made the new trait and associated type names different to avoid the old `type Map: Map` situation, which I found confusing. We now have `type MaybeTyCtxt: HirTyCtxt`.
2025-02-17Move some `Map` methods onto `TyCtxt`.Nicholas Nethercote-121/+119
The end goal is to eliminate `Map` altogether. I added a `hir_` prefix to all of them, that seemed simplest. The exceptions are `module_items` which became `hir_module_free_items` because there was already a `hir_module_items`, and `items` which became `hir_free_items` for consistency with `hir_module_free_items`.
2025-02-16clippy: string_from_utf8_as_bytes: also detect inherent `from_utf8`Pavel Grigorenko-4/+5
2025-02-16Update version attribute for 1.85 clippy lintsxFrednet-4/+4
2025-02-16add suggestion example for `cast_possible_wrap`lapla-cogito-1/+7
2025-02-16apply `manual_contains` to Clippy sourceslapla-cogito-4/+4
2025-02-16add `manual_contains` lintlapla-cogito-0/+144
2025-02-15Use `clippy_utils::is_mutable()` in `unnecessary_struct_initialization`Samuel Tardieu-12/+2
2025-02-15Add example for macro_usealexey semenyuk-1/+15
2025-02-15Fix `used_underscore_items` lint uses of foreign functions (#14205)Jason Newcomb-2/+2
Fixed #14156 changelog: none
2025-02-15`unnecessary_map_or`: do not consume the comparison value if it does not ↵Jason Newcomb-2/+4
implement `Copy` (#14207) Fix #14201 changelog: [`unnecessary_map_or`]: do not consume the comparison value if it does not implement `Copy`
2025-02-14doc_link_code: add check for links with code spans that render weird (#14121)Catherine Flores-0/+99
This is the lint described at https://github.com/rust-lang/rust/pull/136308#issuecomment-2625485331 that recommends using HTML to nest links inside code. changelog: [`doc_link_code`]: warn when a link with code and a code span are back-to-back
2025-02-13Fix `literal_string_with_formatting_args` lint emitted when it should not ↵Timo-4/+12
(#13953) Fixes #13885. Fixes https://github.com/rust-lang/rust-clippy/issues/14007. Problem was that I forgot to check whether or not the `span` was a "real" one. Because if not, then it starts pointing to pretty much only wrong content, hence the problems we saw with clippy linting on `clippy.toml`. changelog: Fix `literal_string_with_formatting_args` lint emitted when it should not r? @samueltardieu
2025-02-13Auto merge of #136593 - lukas-code:ty-value-perf, r=oli-obkbors-3/+4
valtree performance tuning Summary: This PR makes type checking of code with many type-level constants faster. After https://github.com/rust-lang/rust/pull/136180 was merged, we observed a small perf regression (https://github.com/rust-lang/rust/pull/136318#issuecomment-2635562821). This happened because that PR introduced additional copies in the fast reject code path for consts, which is very hot for certain crates: https://github.com/rust-lang/rust/blob/6c1d960d88dd3755548b3818630acb63fa98187e/compiler/rustc_type_ir/src/fast_reject.rs#L486-L487 This PR improves the performance again by properly interning the valtrees so that copying and comparing them becomes faster. This will become especially useful with `feature(adt_const_params)`, so the fast reject code doesn't have to do a deep compare of the valtrees. Note that we can't just compare the interned consts themselves in the fast reject, because sometimes `'static` lifetimes in the type are be replaced with inference variables (due to canonicalization) on one side but not the other. A less invasive alternative that I considered is simply avoiding copies introduced by https://github.com/rust-lang/rust/pull/136180 and comparing the valtrees it in-place (see commit: https://github.com/rust-lang/rust/commit/9e91e50ac5920f0b9b4a3b1e0880c85336ba5c64 / perf results: https://github.com/rust-lang/rust/pull/136593#issuecomment-2642303245), however that was still measurably slower than interning. There are some minor regressions in secondary benchmarks: These happen due to changes in memory allocations and seem acceptable to me. The crates that make heavy use of valtrees show no significant changes in memory usage.
2025-02-13`unnecessary_map_or`: do not consume the non-`Copy` comparison valueSamuel Tardieu-2/+4
2025-02-13intern valtreesLukas Markeffsky-3/+4
2025-02-12New lint: `mem_replace_option_with_some` (#14197)llogiq-38/+113
`mem::replace(opt, Some(v))` can be replaced by `opt.replace(v)`. Close #14195 changelog: [`mem_replace_option_with_some`]: new lint
2025-02-12New lint: `mem_replace_option_with_some`Samuel Tardieu-2/+63
`mem::replace(opt, Some(v))` can be replaced by `opt.replace(v)`.
2025-02-13Fix `used_underscore_items` lint uses of foreign functionsWeiTheShinobi-2/+2
2025-02-12Reorganize code in `mem_replace.rs`Samuel Tardieu-36/+50
Make each lint be more self-contained, and trigger only the next lint when the previous one didn't already rewrite the expression.
2025-02-12New lint: `unbuffered_bytes` (#14089)Jason Newcomb-0/+62
Checks for `Read::bytes()` on an unbuffered Read type. The default implementation calls `read` for each byte, which can be very inefficient for data that’s not in memory, such as `File`. Considerations which I'd like to have feedback on: * Currently this lint triggers when `.bytes()` is called on any type that implements `std::io::Read` but not `std::io::BufRead`. This is quite aggressive and in and may result in false positives. Alternatives: * Only trigger on concrete types, not generic types. This does mean that cases where a function is generic over a `R: Read` and calls `.bytes()` are not caught by the lint, which could be quite a nasty case of this bug. * Only trigger on an allowlist of stdlib types * Compromise: Is it possible to make this lint `pedantic` on types that are not on a allowlist? * Theoretically, a trait implementation of `Read` could override `.bytes()` with an efficient implementation. I'm not sure how to add this check to the lint, and I can't find any cases of this being done in practice. * I don't think an automatic fix for this lint is possible, but I'd love to be proven wrong * This is my first time contributing to clippy, please let me know if I did anything wrong Fixes #14087 ``` changelog: [`unbuffered_bytes`]: new lint ```
2025-02-12add index checks for the slice in `manual_slice_fill` (#14193)Jason Newcomb-1/+6
fix #14192 changelog: [`manual_slice_fill`]: resolve FP caused by missing index checks for the slice
2025-02-12New lint: `unbuffered_bytes`jonathan-0/+62
2025-02-11`{expect,unwrap}_used`: add options to lint at compilation timeSamuel Tardieu-1/+15
By default, do not lint `.unwrap()` and `.expect(…)` in always const contexts, as a failure would be detected at compile time anyway. New options `allow_expect_in_consts` and `allow_unwrap_in_consts`, defaulting to `true`, can be turned unset to still lint in always const contexts.
2025-02-11just_underscores_and_digits: fix false positive in error recovery scenario ↵Alejandra González-1/+2
(#14168) Fixes #12302 changelog: [`just_underscores_and_digits`]: fix false positive in error recovery scenario
2025-02-11just_underscores_and_digits: ignore empty identMichael Howell-1/+2
Empty idents come from error recovery, and should imply that a better error has already been emitted.
2025-02-11`declare_interior_mutable_const`, `borrow_interior_mutable_const`: resolve ↵Alejandra González-0/+6
`<T as Trait>::AssocT` projections (#14125) changelog: [`declare_interior_mutable_const`, `borrow_interior_mutable_const`]: resolve `<T as Trait>::AssocT` projections --- This came up during https://github.com/rust-lang/rust/pull/130543 where we have `<T as AtomicPrimitive>::Assoc = AtomicT` instead of just `AtomicT` and clippy failed to resolve that properly. This really needs a review, because - I don't know if `try_normalize_erasing_regions` is the right thing to call here. - I'm not sure if I peel off the correct amount of `ValTree::Branch` layers (I think I do). Also, shouldn't this lint's infrastructure rely on `Freeze` trait (https://github.com/rust-lang/rust/issues/121675) instead of hardcoding a list of known-to-be-interior-mutable types? --- Previously filed this in the main rust repo (https://github.com/rust-lang/rust/pull/136369), was asked to do it here instead (https://github.com/rust-lang/rust/pull/136369#issuecomment-2628527774).
2025-02-11add index checks for the slice in `manual_slice_fill`lapla-cogito-1/+6