Commit graph

943 commits

Author SHA1 Message Date
royrustdev b083a39190 add boxed_void lint 2022-10-23 22:43:41 +05:30
bors 4612fdfa7b Auto merge of #9670 - Alexendoo:missing-trait-methods, r=Jarcho
Add `missing_trait_methods` lint

Closes #9661

changelog: new lint: [`missing_trait_methods`]
2022-10-20 15:05:06 +00:00
Alex Macleod b6a860e0ed Add missing_trait_methods lint 2022-10-20 11:02:48 +00:00
bors 502e87c379 Auto merge of #9637 - Alexendoo:unused-format-specs, r=xFrednet
Add `unused_format_specs` lint

Currently catches two cases:

An empty precision specifier:

```rust
// the same as {}
println!("{:.}", x);
```

And using formatting specs on `format_args!()`:

```rust
// prints `x.`, not `x    .`
println("{:5}.", format_args!("x"));
```

changelog: new lint: [`unused_format_specs`]
2022-10-17 11:51:32 +00:00
Alex Macleod 136c2cdb91 Add unused_format_specs lint 2022-10-17 11:36:05 +00:00
TennyZhuang 7ac97b69fc Add new lint partial_pub_fields
Signed-off-by: TennyZhuang <zty0826@gmail.com>
2022-10-16 16:03:50 +08:00
Andre Bogus e4c80f2bba add cast-nan-to-int lint 2022-10-12 13:29:27 +02:00
bors 8e87d39f99 Auto merge of #9572 - Nilstrieb:as-ptr-cast-mut, r=dswij
Add `as_ptr_cast_mut` lint

This lint detects calls to a `&self`-taking `as_ptr` method, where the result is then immediately cast to a `*mut T`. Code like this is probably invalid, as that pointer will not have write permissions, and `*mut T` is usually used to write through.

Examples of broken code with this pattern:
https://miri.saethlin.dev/ub?crate=lol_alloc&version=0.1.3
https://miri.saethlin.dev/ub?crate=sophon-wasm&version=0.19.0
https://miri.saethlin.dev/ub?crate=polars-core&version=0.24.2
https://miri.saethlin.dev/ub?crate=ach-cell&version=0.1.17

changelog: Add [`as_ptr_cast_mut`]
2022-10-11 08:08:17 +00:00
bors 292e313259 Auto merge of #9451 - kraktus:manual_filter2, r=dswij
Add `manual_filter` lint for `Option`

Share much of its implementation with `manual_map` and should greatly benefit from its previous feedback.
I'm sure it's possible to even more refactor both and would gladly take input on that as well as any clippy idiomatic usage, since this is my first lint addition.

I've added the lint to the complexity section for now, I don't know if every new lint needs to go in nursery first.

The matching could be expanded to more than `Some(<value>)` to lint on arbitrary struct matching inside the `Some` but I've left it like it was for `manual_map` for now. `needless_match::pat_same_as_expr` provides a more generic match example.

close https://github.com/rust-lang/rust-clippy/issues/8822

changelog: Add lint [`manual_filter`] for `Option`
2022-10-08 15:58:51 +00:00
Alex Macleod 86c86c3742 Add disallowed_macros lint 2022-10-05 13:44:06 +00:00
royrustdev f1c831ad17 add implicit_saturating_add lint 2022-10-03 16:46:38 +05:30
Jacob Kiesel b221184572 Implement manual_clamp lint 2022-10-01 13:58:41 -06:00
Nilstrieb b91dc03510
Add as_ptr_cast_mut lint
This lint detects calls to a `&self`-taking `as_ptr` method, where
the result is then immediately cast to a `*mut T`. Code like this
is probably invalid, as that pointer will not have write permissions,
and `*mut T` is usually used to write through.
2022-10-01 19:23:53 +02:00
bors 9aa85dc35b Auto merge of #9511 - rust-lang:box-default, r=Alexendoo
add `box-default` lint

This adds a `box-default` lint to suggest using `Box::default()` instead of `Box::new(Default::default())`, which offers less moving parts and potentially better performance according to [the perf book](https://nnethercote.github.io/perf-book/standard-library-types.html#box).

---

changelog: add [`box_default`] lint
2022-09-27 18:14:24 +00:00
Andre Bogus 63f441ec85 add box-default lint 2022-09-27 13:26:23 +02:00
Yuri Astrakhan 5a71bbdf3f new uninlined_format_args lint to inline explicit arguments
Implement https://github.com/rust-lang/rust-clippy/issues/8368 - a new
lint to inline format arguments such as `print!("{}", var)` into
`print!("{var}")`.

code | suggestion | comment
---|---|---
`print!("{}", var)` | `print!("{var}")` |  simple variables
`print!("{0}", var)` | `print!("{var}")` |  positional variables
`print!("{v}", v=var)` | `print!("{var}")` |  named variables
`print!("{0} {0}", var)` | `print!("{var} {var}")` |  aliased variables
`print!("{0:1$}", var, width)` | `print!("{var:width$}")` |  width
support
`print!("{0:.1$}", var, prec)` | `print!("{var:.prec$}")` |  precision
support
`print!("{:.*}", prec, var)` | `print!("{var:.prec$}")` |  asterisk
support

code | suggestion | comment
---|---|---
`print!("{0}={1}", var, 1+2)` | `print!("{var}={0}", 1+2)` | Format
string uses an indexed argument that cannot be inlined.  Supporting this
case requires re-indexing of the format string.

changelog: [`uninlined_format_args`]: A new lint to inline format
arguments, i.e. `print!("{}", var)` into `print!("{var}")`
2022-09-25 19:53:03 -04:00
xFrednet e279f22a91
Changelog for Rust 1.64 🍎 2022-09-20 15:23:48 +02:00
Kartavya Vashishtha 5afc261c66
Add iter_kv_map lint 2022-09-15 09:41:06 +05:30
kraktus 0958f9486b Add manual_filter lint for Option
Share much of its implementation with `manual_map` and should greatly benefit from its previous feedback.
2022-09-10 10:41:55 +02:00
Caio 51d8b6c664 Rename the arithmetic lint 2022-09-08 12:04:55 -03:00
Dmitrii Lavrov b1f86a49ea
New lint bool_to_int_with_if 2022-09-01 23:23:56 +02:00
Lukas Lueg 66a97055b2 Initial implementation of result_large_err 2022-08-30 17:39:40 +02:00
clubby789 30979bfe83 Add lint cast_slice_from_raw_parts 2022-08-29 14:10:17 +01:00
Marco Mastropaolo de028e2fb9 Implemented suspicious_to_owned lint to check if to_owned is called on a Cow.
This is done because `to_owned` is very similarly named to `into_owned`, but the
effect of calling those two methods is completely different. This creates
confusion (stemming from the ambiguity of the 'owned' term in the context of
`Cow`s) and might not be what the writer intended.
2022-08-26 17:41:17 -07:00
bors 21f103abcc Auto merge of #9379 - royrustdev:multi_assignments, r=llogiq
new lint

This fixes #6576

If you added a new lint, here's a checklist for things that will be
checked during review or continuous integration.

- \[x] Followed [lint naming conventions][lint_naming]
- \[x] Added passing UI tests (including committed `.stderr` file)
- \[x] `cargo test` passes locally
- \[x] Executed `cargo dev update_lints`
- \[x] Added lint documentation
- \[x] Run `cargo dev fmt`

---

changelog: add [`multi_assignments`] lint
2022-08-26 12:05:57 +00:00
royrustdev fb7dffeac9 add multi_assignments lint 2022-08-26 17:05:52 +05:30
Alex Macleod 2cb5318e97 Rename manual_empty_string_creation and move to pedantic 2022-08-23 14:19:46 +00:00
bors 5820addb24 Auto merge of #9269 - nahuakang:collapsible_str_replace, r=flip1995
Lint `collapsible_str_replace`

fixes #6651

```
changelog: [`collapsible_str_replace`]: create new lint `collapsible_str_replace`
```

If you added a new lint, here's a checklist for things that will be
checked during review or continuous integration.

- \[x] Followed [lint naming conventions][lint_naming]
- \[x] Added passing UI tests (including committed `.stderr` file)
- \[x] `cargo test` passes locally
- \[ ] Executed `cargo dev update_lints`
- \[x] Added lint documentation
- \[x] Run `cargo dev fmt`
2022-08-20 13:44:35 +00:00
Nahua Kang a4413f75bf Register new lint collapsible_str_replace to methods 2022-08-19 19:49:15 +02:00
Serial 2666c38acb Add [unused_peekable] lint 2022-08-19 08:05:59 -04:00
bors 868dba9f65 Auto merge of #9295 - Guilherme-Vasconcelos:manual-empty-string-creation, r=dswij
Add `manual_empty_string_creations` lint

Closes #2972

- [x] Followed [lint naming conventions][lint_naming]
- [x] Added passing UI tests (including committed `.stderr` file)
- [x] `cargo test` passes locally
- [x] Executed `cargo dev update_lints`
- [x] Added lint documentation
- [x] Run `cargo dev fmt`

changelog: [`manual_empty_string_creations`]: Add lint for empty String not being created with `String::new()`
2022-08-19 11:19:06 +00:00
bors 86ac6e88a8 Auto merge of #9040 - miam-miam100:unused_named_parameter, r=dswij
Add new lint [`positional_named_format_parameters`]

*Please write a short comment explaining your change (or "none" for internal only changes)*

changelog: Add new lint [`positional_named_format_parameters`] to warn when named parameters in format strings are used as positional arguments.
2022-08-16 13:11:27 +00:00
Guilherme-Vasconcelos 80826c3944 Implement clippy::manual_empty_string_creations lint 2022-08-14 12:45:24 -03:00
bors 679fa9f2bf Auto merge of #9187 - sgued:iter-once, r=flip1995
Add lint recommending using `std::iter::once` and `std::iter::empty`

```
changelog: [`iter_once`]: add new lint
changelog: [`iter_empty`]: add new lint
```

fixes #9186

- \[ ] Followed [lint naming conventions][lint_naming]
- \[x] Added passing UI tests (including committed `.stderr` file)
- \[x] `cargo test` passes locally
- \[x] Executed `cargo dev update_lints`
- \[x] Added lint documentation
- \[x] Run `cargo dev fmt`

[lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints

The lint doesn't really follow the naming conventions. I don't have any better idea so I'm open to suggestions.
2022-08-14 15:45:17 +00:00
bors dfa780e0ef Auto merge of #9324 - flip1995:changelog, r=xFrednet
1.63 Changelog

r? `@xFrednet`

changelog: none

[Rendered](https://github.com/flip1995/rust-clippy/blob/changelog/CHANGELOG.md)
2022-08-12 21:11:33 +00:00
flip1995 35486cb661
Update Changelog to 1.63 2022-08-12 23:10:23 +02:00
miam-miam100 9ffddf563c
Add new lint [positional_named_format_parameters] 2022-08-09 21:03:41 +01:00
bors 3af9072bc6 Auto merge of #9288 - lukaslueg:partialeqnone, r=Jarcho
Add partialeq_to_none lint

Initial implementation of #9275, adding lint `partialeq_to_none`. This is my first time working on `clippy`, so please review carefully.

I'm unsure especially about the `Sugg`, as it covers the entire `BinOp`, instead of just covering one of the sides and the operator (see the multi-line example). I was unsure if pinpointing the suggestion wouldn't be brittle...

changelog: [`PARTIALEQ_TO_NONE`]: Initial commit
2022-08-09 00:12:29 +00:00
Sosthène Guédon af4885c0cd Rename new lints to iter_on_empty_collections and iter_on_single_items 2022-08-08 21:05:27 +02:00
Sosthène Guédon 73cd95465e Add iter_once and iter_empty lints 2022-08-08 21:04:41 +02:00
Lukas Lueg 657b0da912 Add partialeq_to_none lint
Fixes #9275
2022-08-08 20:17:13 +02:00
Federico Guerinoni f6cab94bd0 Rename logic_bug to overly_complex_bool_expr
Closes #1916
2022-08-08 18:38:39 +02:00
Federico Guerinoni 0696624ba7 Add elapsed_instant lint
Closes #8603

Signed-off-by: Federico Guerinoni <guerinoni.federico@gmail.com>
2022-08-01 23:39:00 +02:00
Andy Caldwell 66b46749e6
Change lint name to plural 2022-07-29 19:35:39 +01:00
Andy Caldwell 2f48257cfb
Rename "blacklisted name" to "disallowed name" throughout 2022-07-29 19:35:18 +01:00
bors 8882578a67 Auto merge of #9130 - c410-f3r:arith, r=llogiq
Add `Arithmetic` lint

Fixes https://github.com/rust-lang/rust-clippy/issues/8903

r? `@llogiq`

changelog: Add `Arithmetic` lint
2022-07-25 21:26:15 +00:00
tabokie 8454602cef Add [assertions_on_result_states] lint
Signed-off-by: tabokie <xy.tao@outlook.com>
2022-07-25 22:42:41 +08:00
Caio 31e5465f8a Add Arithmetic lint 2022-07-18 14:29:45 -03:00
bors cce617165d Auto merge of #9148 - arieluy:then_some_unwrap_or, r=Jarcho
Add new lint `obfuscated_if_else`

part of #9100, additional commits could make it work with `then` and `unwrap_or_else` as well

changelog: Add new lint `obfuscated_if_else`
2022-07-18 12:45:11 +00:00
Ariel Uy 9ff7c91100 Add new lint obfuscated_if_else
New lint suggests using `if .. else ..` instead of
`.then_some(..).unwrap_or(..)`.
2022-07-17 18:44:49 -07:00