about summary refs log tree commit diff
path: root/clippy_lints/src/methods
AgeCommit message (Collapse)AuthorLines
2025-01-23Deprecate the `option_map_or_err_ok` lintSamuel Tardieu-69/+0
2025-01-22Fix out-of-date comment (#14040)Catherine Flores-2/+1
This comment was left behind when the method receiver was split out from the method arguments in 4bcaddeeb23544eb2c86b600c3d775e2773758c2. changelog: none
2025-01-20New lint: `unnecessary_semicolon` (#14032)llogiq-9/+9
This lint detects and removes the unnecessary semicolon after a `match` or `if` statement returning `()`. It seems to be quite a common "mistake", given the number of hits (88) we had in the Clippy sources themselves. The lint doesn't bother about loops, as `rustfmt` already removes the extra semicolon. It doesn't handle blocks either, as an extra block level, followed or not by a semicolon, is likely intentional. I propose to put the lint in `pedantic`, as putting it in `style` seems quite hazardous given the number of hits. Note: there exists a `redundant-semicolon` lint in the compiler, but it is an early lint and cannot check that the expression evaluates to `()`, so it ignores the cases we're handling here. ---- changelog: [`unnecessary_semicolon`]: new lint
2025-01-20`needless_option_take`: add autofixSamuel Tardieu-4/+14
2025-01-20Fix out-of-date commentSamuel Tardieu-2/+1
This comment was left behind when the method receiver was split out from the method arguments in 4bcaddeeb23544eb2c86b600c3d775e2773758c2.
2025-01-19Use clearer multipart suggestions for `unnecessary_map_or` lint (#13998)Timo-22/+15
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-19Apply `unnecessary_semicolon` to Clippy sourcesSamuel Tardieu-9/+9
2025-01-19Make `unnecessary_map_or` work with ref and `Deref`Samuel Tardieu-1/+1
Receivers which are references to `Option` and `Result`, or who implement `Deref` to one of those types, will be linted as well.
2025-01-19Use clearer multipart suggestions for `unnecessary_map_or` lintSamuel Tardieu-22/+15
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-16[`path_buf_push_overwrite`]: mark suggestion as `MaybeIncorrect`Samuel Tardieu-1/+1
Proposing to replace ```rust let mut x = PathBuf::from("/foo"); x.push("/bar"); ``` by ```rust let mut x = PathBuf::from("/foo"); x.push("bar"); ``` changes the content of `x` (`/bar` ⇒ `/foo/bar`).
2025-01-15add `manual_repeat_n` lintlapla-cogito-0/+69
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/+89
2025-01-12don't suggest to use `cloned` for `Cow` in `unnecessary_to_owned` (#13853)Timo-0/+3
fix #13624 changelog: [`unnecessary_to_owned`]: don't suggest to use `cloned` on `Cow` in `unnecessary_to_owned`
2025-01-09Merge commit '19e305bb57a7595f2a8d81f521c0dd8bf854e739' into ↵Philipp Krones-22/+124
clippy-subtree-update
2025-01-09Check for needless uses of str::bytes()Quentin Santos-6/+6
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-7/+5
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-09Merge remote-tracking branch 'upstream/master' into rustupPhilipp Krones-23/+126
2025-01-07Do not remove identity mapping if mandatory mutability would be lost (#13905)Alex Macleod-2/+13
Removing `.map(identity)` may result in invalid code if the receiver of `map()` is an immutable binding, and the result of `map()` is used as the receiver of a method call expecting a mutable reference. Fix #13904 changelog: [`map_identity`]: do not lint if this would cause mandatory mutability to be lost
2025-01-07Remove unneeded parentheses in `unnecessary_map_or` lint output (#13932)Alex Macleod-5/+19
When the expression is transformed into an equality, parentheses are needed only if the resulting equality is used: - as a receiver in a method call - as part of a binary or unary expression - as part of a cast In other cases, which will be the majority, no parentheses are required. This makes the lint suggestions cleaner. changelog: `none`
2025-01-07Don't emit machine applicable `map_flatten` lint if there are code comments ↵Fridtjof Stoldt-2/+7
(#13940) Fixes https://github.com/rust-lang/rust-clippy/issues/8528. Similar to #13911, if there are code comments, we don't want to remove them automatically. changelog: Don't emit machine applicable `map_flatten` lint if there are code comments r? @xFrednet
2025-01-06Don't emit machine applicable `map_flatten` lint if there are code commentsGuillaume Gomez-2/+7
2025-01-04[`needless_continue`]: lint if the last stmt in loop is `continue` ↵Alejandra González-1/+1
recurisvely (#13891) fixes: #4077 Continuation of #11546. r? @y21 if you don't mind? changelog: [`needless_continue`] lint if the last stmt in loop is `continue` recurisvely
2025-01-04turn hir::ItemKind::Fn into a named-field variantRalf Jung-1/+1
2025-01-03Remove unneeded parentheses in `unnecessary_map_or` lint outputSamuel Tardieu-5/+19
When the expression is transformed into an equality, parentheses are needed only if the resulting equality is used: - as a receiver in a method call - as part of a binary or unary expression - as part of a cast In other cases, which will be the majority, no parentheses are required. This makes the lint suggestions cleaner.
2025-01-01Dogfood double_ended_iterator_lastQuentin Santos-1/+1
2025-01-01Only complain about default Iterator::last()Quentin Santos-1/+16
2025-01-01Prefer if chain to let-elseQuentin Santos-29/+13
2025-01-01Add lint for calling last() on DoubleEndedIteratorQuentin Santos-0/+71
2024-12-29Do not remove identity mapping if mandatory mutability would be lostSamuel Tardieu-2/+13
Removing `.map(identity)` may result in invalid code if the receiver of `map()` is an immutable binding, and the result of `map()` is used as the receiver of a method call expecting a mutable reference.
2024-12-29Move more def paths into `clippy_utils::paths`Guillaume Gomez-2/+4
2024-12-29Move `format_push_string` and `format_collect` to pedanticSamuel Moelius-1/+1
2024-12-28[`needless_continue`]: lint if the last stmt in for/while/loop is ↵lengyijun-1/+1
`continue`, recursively fixes: #4077
2024-12-27Make `inconsistent_struct_constructor` "all fields are shorthand" ↵Timo-10/+10
requirement configurable (#13737) Fixes #11846. This PR has three commits: - The first commit adds an `initializer-suggestions` configuration to control suggestion applicability when initializers are present. The following are the options: - "none": do not suggest - "maybe-incorrect": suggest, but do not apply suggestions with `--fix` - "machine-applicable": suggest and apply suggestions with `--fix` - The second commit fixes suggestions to handle field attributes (problem [noticed by @samueltardieu](https://github.com/rust-lang/rust-clippy/pull/13737#discussion_r1859261645)). - The third commit adds `initializer-suggestions = "machine-applicable"` to Clippy's `clippy.toml` and applies the suggestions. (Nothing seems to break.) --- changelog: make `inconsistent_struct_constructor` "all fields are shorthand" requirement configurable
2024-12-27don't suggest to use cloned for Cow in unnecessary_to_ownedlapla-cogito-0/+3
2024-12-26Make "all fields are shorthand" requirement configurableSamuel Moelius-10/+10
Handle field attributes in suggestions Fix adjacent code Address review comments https://github.com/rust-lang/rust-clippy/pull/13737#discussion_r1861352124 Address all review comments but one This comment is not yet addressed: https://github.com/rust-lang/rust-clippy/pull/13737#discussion_r1874544907 `initializer_suggestions` -> `lint_inconsistent_struct_field_initializers`
2024-12-26Merge commit '609cd310be44677ae31d452a17b0f8207e1abfe1' into ↵Philipp Krones-50/+74
clippy-subtree-update
2024-12-17Change unnecessary_iter_cloned to use multipart_suggestionScott Gerring-8/+8
2024-12-17Don't trigger `filter_map_identity` with an iterator from an empty array ↵Jason Newcomb-0/+10
(#13826) fix #12653 changelog: [`filter_map_identity`]: don't lint for creating an iterator from an empty array
2024-12-16correct suggestion for unnecessary_sort_by in no_stdlapla-cogito-3/+5
2024-12-15Merge remote-tracking branch 'upstream/master' into rustupPhilipp Krones-40/+53
2024-12-14allow needless_option_take to report for more cases (#13684)Catherine Flores-23/+32
changelog: ``` changelog: [`needless_option_take`]: now lints for all temporary expressions of type Option<T>. ``` fixes #13671 In general, needless_option_take should report whenever take() is called on a temporary value, not just when the temporary value is created by as_ref(). Also, we stop emitting machine applicable fixes in these cases, since sometimes the intention of the user is to actually clear the original option, in cases such as `option.as_mut().take()`.
2024-12-14don't lint for creating an iterator from an empty array in ↵lapla-cogito-0/+10
filter_map_identity lint
2024-12-13Rename ty_def_id so people will stop using it by accidentMichael Goulet-3/+1
2024-12-11allow needless_option_take to report for more casesEric-23/+32
In general, needless_option_take should report whenever take() is called on a temporary value, not just when the temporary value is created by as_ref()
2024-12-10remove unnecessary notationslapla-cogito-5/+0
2024-12-06chore: use multipart_suggestions for str_splitnScott Gerring-9/+13
2024-12-05fix: various typosBD103-2/+2
2024-12-02Add more receivers to `useless_conversion`Samuel Tardieu-0/+3
- `ControlFlow::map_break()` - `ControlFlow::map_continue()` - `Iterator::map()`
2024-12-02remove `Ty::is_copy_modulo_regions`lcnr-2/+2