Avoid generating files via doctest
When we run `cargo test` in `clippy_lints` directory, it will generate [`foo.txt`](https://github.com/rust-lang/rust-clippy/blob/master/clippy_lints/foo.txt) in the directory.
In order to avoid that, this PR adds `no_run` to rustdoc which contains `File::create`.
changelog: none
When we run `cargo test` in `clippy_lints` directory, it will generate
`foo.txt` in the directory.
In order to avoid that, add `no_run` to rustdoc which contains
`File::create`.
feat: lint unchecked subtraction of a 'Duration' from an 'Instant'
Hello all, I tried to tackle the open issue #9371 and this is what I came up with.
I have a difficulty currently - some tests are failing:
```
failures:
[ui] ui/manual_instant_elapsed.rs
```
The `manual_instant_elapsed` is failing because of `Instant::now() - duration` test, this now gets also picked by `unchecked_duration_subtraction` lint.
What is the correct way to proceed in this case? Simply update the `.stderr` file for `manual_instant_elapsed` lint?
changelog: [`unchecked_duration_subtraction`]: Add lint for unchecked subtraction of a `Duration` from an `Instant`.
fixes#9371
Fix `vec-box-size-threshold` off-by-one error
The docs for `vec-box-size-threshold` say "The size of the boxed type in bytes, where boxing in a `Vec` is allowed", but previously a boxed type of exactly that size wasn't allowed in `Vec`.
changelog: [`vec_box`]: Fix off-by-one error for `vec-box-size-threshold` configuration.
Make it clear that `or_fun_call` can be a false-positive
Also move it to nursery so that the false-positives can be dealt with.
CC #8574
changelog: [`or_fun_call`]: Mention false-positives, move to nursery.
Add `unnecessary_safety_doc` lint
changelog: [`unnecessary_safety_doc`]: Add `unnecessary_safety_doc` lint
fixes https://github.com/rust-lang/rust-clippy/issues/6880
This lint does not trigger for private functions, just like `missing_safety_docs`. Reason for that was implementation simplicity and because I figured asking first would make more sense, so if it should trigger for private functions as well let me know and I'll fix that up as well.
[`fn_params_excessive_bools`] Make it possible to allow the lint at the method level
changelog: FP: [`fn_params_excessive_bools`]: `#[allow]` now works on methods
fix https://github.com/rust-lang/rust-clippy/issues/9687
Tested without committing but `#[allow]`ing now works. Also rewrote the lint to be a late lint while at it :)
r? `@xFrednet`
Fix is_async_fn to check FnKind::Method
This is a follow-up PR of https://github.com/rust-lang/rust-clippy/pull/9828 to support also async methods.
changelog: [`cognitive_complexity`] support async method
r? `@Alexendoo`
Make `bool_to_int_with_if` a pedantic lint
In all the cases I've observed, it did not make the code clearer. Using bools as integer is frowned upon in some languages, in others it's simply not possible.
You can find comments on the original pull request #8131 that agree with this point of view.
changelog: [`bool_to_int_with_if`]: Change the categorization to pedantic
In all the cases I've observed, it did not make the code clearer. Using
bools as integer is frowned upon in some languages, in others it's
simply not possible.
You can find comments on the original pull request #8131 that agree with
this point of view.
Fix `explicit_auto_deref` fp
fixes#9763fixes#9811
changelog: `explicit_auto_deref`: Don't lint when the target type is a projection with generic arguments
Update lint example for `collapsible_str_replace`
To fix this warning:
```
warning: the borrowed expression implements the required traits
--> src/fixes/quote_character.rs:16:43
|
16 | let hello = "hesuo worpd".replace(&['s', 'u', 'p'], "l");
| ^^^^^^^^^^^^^^^^ help: change this to: `['s', 'u', 'p']`
|
= note: `#[warn(clippy::needless_borrow)]` on by default
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
```
*Please write a short comment explaining your change (or "none" for internal only changes)*
changelog: none
Address issues 9739 and 9782
This PR fixes#9739 in the manner I suggested in https://github.com/rust-lang/rust-clippy/issues/9739#issuecomment-1296802376.
This PR also fixes the compilation failures in #9782 (but doesn't address `@e00E's` other objections).
Fixes#9739
r? `@Jarcho`
changelog: Fix two `needless_borrow` false positives, one involving borrows in `if`-`else`s, the other involving qualified function calls
Add `manual_is_ascii_check` lint
Addresses https://github.com/rust-lang/rust-clippy/issues/9290
This PR adds new lint `manual_is_ascii_check`, which detects comparison with ascii ranges using `matches!` macros.
As I mentioned as following in the Issue;
> Yes, that's true. we'll start small and then grow it.
> So I'll try to handle matches! macro with single range as suggested above.
However during writing first version, I was thinking that the changes to support alphabetic and digits will be small patch, so I made a single PR in hope review cost can be reduced.
changelog: add new lint [`manual_is_ascii_check`]
r? `@xFrednet`
Extend `needless_collect`
Extends when `is_empty` and `contains` are linted.
`is_empty` will be linted when `<IterTy as Iterator>::Item` is the same as `<CollectTy as IntoIterator>::Item`. This can be a false positive if the `FromIterator` implementation filters out items, but I don't know of any which do that also implement `IntoIterator` with a matching `Item` type.
`contains` will be linted when the argument type is `&<IterTy as Iterator>::Item`. It has the same false positives as `is_empty` with the same note that I know of nothing that actually causes that in practice.
changelog: Lint `needless_collect` when `is_empty` or `contains` is called on some non-std types