about summary refs log tree commit diff
path: root/clippy_lints/src/methods/mod.rs
AgeCommit message (Collapse)AuthorLines
2025-02-20Merge remote-tracking branch 'upstream/master' into rustupPhilipp Krones-29/+70
2025-02-17Move some `Map` methods onto `TyCtxt`.Nicholas Nethercote-2/+2
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-16add `manual_contains` lintlapla-cogito-0/+30
2025-02-12New lint: `unbuffered_bytes`jonathan-0/+30
2025-02-11`{expect,unwrap}_used`: add options to lint at compilation timeSamuel Tardieu-0/+9
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-07clippy: directly use rustc_abi instead of reexportsJubilee Young-1/+2
2025-02-07Deprecate redundant lint `option_map_or_err_ok` and take `manual_ok_or` out ↵dswij-29/+1
of pedantic (#14027) While extending the `option_map_or_err_ok` lint (warn by default, "style") to recognize η-expanded forms of `Ok`, as in ```rust // Should suggest `opt.ok_or("foobar")` let _ = opt.map_or(Err("foobar"), |x| Ok(x)); ``` I discovered that the `manual_ok_or` lint (allow by default, "pedantic") already covered exactly the cases handled by `option_map_or_err_ok`, including the one I was adding. Apparently, `option_map_or_err_ok` was added without realizing that the lint already existed under the `manual_ok_or` name. As a matter of fact, artifacts of this second lint were even present in the first lint `stderr` file and went unnoticed for more than a year. This PR: - deprecates `option_map_or_err_ok` with a message saying to use `manual_ok_or` - moves `manual_ok_or` from "pedantic" to "style" (the category in which `option_map_or_err_ok` was) In addition, I think that this lint, which is short, machine applicable, and leads to shorter and clearer code with less arguments (`Ok` disappears) and the removal of one level of call (`Err(x)` is replaced by `x`), is a reason by itself to be in "style". changelog: [`option_map_or_err_ok` and `manual_ok_or`]: move `manual_ok_or` from "pedantic" to "style", and deprecate the redundant style lint `option_map_or_err_ok`.
2025-02-06Merge commit '3e3715c31236bff56f1c63a1de2c7bbdfcfb0923' into ↵Philipp Krones-8/+60
clippy-subtree-update
2025-02-06Merge remote-tracking branch 'upstream/master' into rustupPhilipp Krones-8/+60
2025-02-02Convert two `rustc_middle::lint` functions to `Span` methods.Nicholas Nethercote-3/+2
`rustc_middle` is a huge crate and it's always good to move stuff out of it. There are lots of similar methods already on `Span`, so these two functions, `in_external_macro` and `is_from_async_await`, fit right in. The diff is big because `in_external_macro` is used a lot by clippy lints.
2025-01-30`sliced_string_as_bytes`: fix typo in lint descriptionSamuel Tardieu-1/+1
2025-01-29Add new lint `return_and_then`Aaron Ang-3/+52
2025-01-28Move `format_push_string` and `format_collect` to pedantic (#13894)Catherine Flores-1/+1
Closes #11434 by moving `format_push_string` and `format_collect` to pedantic. changelog: Move `format_push_string` and `format_collect` to pedantic
2025-01-28Merge commit '51d49c1ae2785b24ef18a46ef233fc1d91844666' into ↵Philipp Krones-9/+96
clippy-subtree-update
2025-01-28Merge remote-tracking branch 'upstream/master' into rustupPhilipp Krones-9/+96
2025-01-27New lint `sliced_string_as_bytes` (#14002)Manish Goregaokar-0/+31
resurrection of https://github.com/rust-lang/rust-clippy/pull/10984 fixes https://github.com/rust-lang/rust-clippy/issues/10981 changelog: [`sliced_string_as_bytes`]: add new lint `sliced_string_as_bytes`
2025-01-25trigger `obfuscated_if_else` for `.then(..).unwrap_or(..)` (#14021)llogiq-4/+4
part of https://github.com/rust-lang/rust-clippy/issues/9100 The `obfuscated_if_else` lint currently only triggers for the pattern `.then_some(..).unwrap_or(..)`, but there're other cases where this lint should be triggered, one of which is `.then(..).unwrap_or(..)`. changelog: [`obfuscated_if_else`]: trigger lint for the `.then(..).unwrap_or(..)` pattern as well
2025-01-25slice-as-bytes: pedantic -> perfwowinter13-1/+1
2025-01-25Rename slice_as_bytes -> sliced_string_as_byteswowinter13-5/+5
2025-01-25New lintwowinter13-0/+31
2025-01-25trigger `obfuscated_if_else` for `.then(..).unwrap_or(..)`lapla-cogito-4/+4
2025-01-23Move `manual_ok_or` from pedantic to styleSamuel Tardieu-1/+1
`manual_ok_or` covers the same case that were covered by `option_map_or_err_ok` which is not deprecated. The latter was in the "style" category. Also, the lint is machine applicable, and leads to shorter and more readable code, so "style" is appropriate. The only difference is that the η-expanded form of `Result::Ok()` was not covered by `option_map_or_err_ok` while it is by `manual_ok_or`, so the category change may expose some new occurrences.
2025-01-23Deprecate the `option_map_or_err_ok` lintSamuel Tardieu-28/+0
2025-01-19Use clearer multipart suggestions for `unnecessary_map_or` lint (#13998)Timo-1/+1
A multipart suggestion will be used whenever the method call can be replaced by another one with the first argument removed. It helps place the new method call in context, especially when it is part of a larger expression. This fixes #13995 by applying a suggestion made by @y21. r? @y21 changelog: [`unnecessary_map_or`]: better representation of suggestions by placing them in context
2025-01-19Use clearer multipart suggestions for `unnecessary_map_or` lintSamuel Tardieu-1/+1
A multipart suggestion will be used whenever the method call can be replaced by another one with the first argument removed. It helps place the new method call in context, especially when it is part of a larger expression.
2025-01-15add `manual_repeat_n` lintlapla-cogito-0/+26
2025-01-14Add hir::HeaderSafety to make follow up commits simplerOli Scherer-1/+1
2025-01-13New lint `useless-nonzero-new_unchecked`Samuel Tardieu-0/+30
2025-01-09Merge commit '19e305bb57a7595f2a8d81f521c0dd8bf854e739' into ↵Philipp Krones-0/+29
clippy-subtree-update
2025-01-09Check for needless uses of str::bytes()Quentin Santos-4/+4
This builds upon the lint for `str::as_bytes()`, and also covers needless uses of the iterator version `str::bytes()`.
2025-01-09Remove needless check of returned typeQuentin Santos-2/+2
We are checking that we are calling the `as_bytes()` method of `String` or `str`. Checking that it returns a `slice()` does not add anything.
2025-01-01Add lint for calling last() on DoubleEndedIteratorQuentin Santos-0/+29
2024-12-29Move `format_push_string` and `format_collect` to pedanticSamuel Moelius-1/+1
2024-12-26Merge commit '609cd310be44677ae31d452a17b0f8207e1abfe1' into ↵Philipp Krones-6/+5
clippy-subtree-update
2024-12-10remove unnecessary notationslapla-cogito-5/+0
2024-12-05fix: various typosBD103-1/+1
2024-12-02Add more receivers to `useless_conversion`Samuel Tardieu-0/+3
- `ControlFlow::map_break()` - `ControlFlow::map_continue()` - `Iterator::map()`
2024-11-30Add more cases to the `useless_conversion` lintSamuel Tardieu-0/+1
The new cases are `x.map(f)` and `x.map_err(f)` when `f` is `Into::into` or `From::from` with the same input and output types.
2024-11-28Merge commit 'ff4a26d442bead94a4c96fb1de967374bc4fbd8e' into ↵Philipp Krones-8/+16
clippy-subtree-update
2024-11-26unnecessary_map_or: fix version for lint additionSamuel Tardieu-1/+1
2024-11-16unnecessary_map_or: lint `.map_or(true, …)` as wellSamuel Tardieu-5/+13
2024-11-16Simplify instances of `Option::map_or(true, …)` in Clippy sourcesSamuel Tardieu-1/+1
2024-11-15Rename all clippy_config::msrvs -> clippy_utils::msrvsPhilipp Krones-1/+1
2024-11-14Merge commit '786fbd6d683933cd0e567fdcd25d449a69b4320c' into ↵Philipp Krones-1/+31
clippy-subtree-update
2024-11-12new lint `unnecessary_map_or`Jacherr-1/+31
2024-11-07Merge commit 'f712eb5cdccd121d0569af12f20e6a0fabe4364d' into ↵Philipp Krones-12/+122
clippy-subtree-update
2024-11-07Merge remote-tracking branch 'upstream/master' into rustupPhilipp Krones-12/+122
2024-10-29Add new `map_with_unused_argument_over_ranges` lintRobert Spencer-0/+37
This lint checks for code that looks like ```rust let something : Vec<_> = (0..100).map(|_| { 1 + 2 + 3 }).collect(); ``` which is more clear as ```rust let something : Vec<_> = std::iter::repeat_with(|| { 1 + 2 + 3 }).take(100).collect(); ``` or ```rust let something : Vec<_> = std::iter::repeat_n(1 + 2 + 3, 100) .collect(); ``` That is, a map over a range which does nothing with the parameter passed to it is simply a function (or closure) being called `n` times and could be more semantically expressed using `take`.
2024-10-29Add new lint: `map_all_any_identity`Samuel Tardieu-19/+55
2024-10-28New lint `needless_as_bytes`Samuel Tardieu-2/+40