Commit graph

122 commits

Author SHA1 Message Date
Alejandra González
649cef0e81
rename MANUAL_DIV_CEIL MSRV alias and add missing conf info for 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-21 18:02:30 +00:00
Philipp Krones
238edf273d
Rustup (#14262)
r? @ghost

changelog: none
2025-02-20 14:59:15 +00:00
lapla-cogito
55f32d9259
add missing MSRV configuration information for manual_div_ceil 2025-02-20 23:27:15 +09:00
Philipp Krones
8844a969ca
Bump Clippy version -> 0.1.87 2025-02-20 15:26:51 +01:00
Andre Bogus
83f5cbad18 add owned_cow lint 2025-02-19 23:12:46 +01:00
llogiq
4129f5c824
New lint: mem_replace_option_with_some (#14197)
`mem::replace(opt, Some(v))` can be replaced by `opt.replace(v)`.

Close #14195

changelog: [`mem_replace_option_with_some`]: new lint
2025-02-12 19:02:06 +00:00
Samuel Tardieu
342ac8ee28 New lint: mem_replace_option_with_some
`mem::replace(opt, Some(v))` can be replaced by `opt.replace(v)`.
2025-02-12 19:57:14 +01:00
Samuel Tardieu
da6a05977d {expect,unwrap}_used: add options to lint at compilation time
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-11 22:14:52 +01:00
lapla-cogito
749eb371bf
correct "Affected lints" for allow-one-hash-in-raw-strings 2025-02-10 20:20:27 +09:00
Catherine Flores
0ff95402c7
Two improvements to disallowed_* (#13669)
The improvements are as follows:
- Remove an [unnecessary `compile-flags`
directive](f712eb5cdc/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs (L1))
in `tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs`
- Support replacements as suggested by @mitsuhiko in
https://github.com/rust-lang/rust-clippy/issues/7609#issuecomment-908632622

---

changelog: support replacements in `disallowed_methods`
2025-02-08 11:32:11 +00:00
dswij
5211148dbd
add MSRV check for manual_flatten (#14086)
`manual_flatten` should respect MSRV.

changelog: [`manual_flatten`]: add MSRV check
2025-02-08 04:17:43 +00:00
Samuel Moelius
7c94744afb Address additional review comments 2025-02-07 09:13:59 -05:00
Catherine Flores
c6a861615e
add manual_option_as_slice MSRV to the lint documentation (#14171)
`manual_option_as_slice` takes MSRV into account, but this is not
mentioned in the lint documentation.

changelog: none
2025-02-07 12:28:06 +00:00
Catherine Flores
b0ad06daa8
add MSRV check for lines_filter_map_ok (#14130)
fixes #14127

changelog: [`lines_filter_map_ok`]: respect MSRV
2025-02-07 12:24:50 +00:00
lapla-cogito
16781bf29d
add manual_option_as_slice to the lint documentation 2025-02-07 21:00:39 +09:00
llogiq
2c51951dba
add manual_slice_fill lint (#14082)
close #13856

changelog: [`manual_slice_fill`]: new lint
2025-02-03 05:03:14 +00:00
lapla-cogito
e82b1f4653
add manual_slice_fill lint 2025-02-03 10:09:39 +09:00
lapla-cogito
f9669e4caf
add MSRV check for lines_filter_map_ok 2025-02-01 15:20:34 +09:00
Samuel Moelius
736ac3d30f Undo most of last commit and add type alias 2025-01-28 18:33:40 -05:00
lapla-cogito
665e78f20f
add MSRV check for manual_flatten 2025-01-27 23:17:05 +09:00
lapla-cogito
0b818aa673
fixed a missing description of the MSRV option for manual_repeat_n 2025-01-27 04:54:40 +09:00
J-ZhengLi
2671e4a5c1 add new lint non_std_lazy_statics
detect usage of `once_cell::sync::Lazy` and `lazy_static!`,
recommending usage of `std::sync::LazyLock` instead
2025-01-24 14:06:46 -07:00
Fridtjof Stoldt
67e6bf33fe
Suggest using Vec::extend() in same_item_push (#13987)
Using `Vec::extend(std::iter::repeat_n(item, N))` allows to use the more
natural number of elements to add `N`, as is probably done in the
original loop, instead of computing the difference between the existing
number of elements and the wanted one.

Before MSRV 1.82, the older suggestion to use `Vec::resize()` is still
issued.

Inspired by #6156 (which predates `repeat_n()`).

changelog: [`same_item_push`]: recommend using `Vec::extend()` to extend
a vector
2025-01-22 14:41:13 +00:00
Samuel Tardieu
ded9354dcf Suggest using Vec::extend() in same_item_push
Using `Vec::extend(std::iter::repeat_n(item, N))` allows to use the more
natural number of elements to add `N`, as is probably done in the original
loop, instead of computing the difference between the existing number of
elements and the wanted one.

Before MSRV 1.82, the older suggestion to use `Vec::resize()` is still
issued.
2025-01-15 22:50:25 +01:00
Samuel Tardieu
a4805ff610 Select edition 2024 2025-01-13 16:55:42 +01:00
Philipp Krones
663892bea7
Bump Clippy version -> 0.1.86 2025-01-09 18:01:44 +01:00
Timo
a8968e5dd8
Make inconsistent_struct_constructor "all fields are shorthand" 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-27 22:05:03 +00:00
Samuel Moelius
8a38bcc390 Make "all fields are shorthand" requirement configurable
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-26 19:36:58 -05:00
Alexey Semenyuk
6f6ddd299c Add allow-indexing-slicing-in-tests option 2024-12-20 01:06:49 +05:00
Samuel Moelius
fef10d42a3 Use two structs rather than a const generic 2024-12-18 19:13:10 -05:00
Philipp Krones
5fb924f334
Bump Clippy version -> 0.1.85 2024-11-28 18:57:52 +01:00
boyned//Kampfkarren
f0bb475f80
Remove incorrect "no default" text from trivial_copy_size_limit 2024-11-22 10:16:46 -08:00
Alejandra González
8298da72e7
Add new lint doc_include_without_cfg (#13625)
It's becoming more and more common to see people including markdown
files in their code using `doc = include_str!("...")`, which is great.
However, often there is no condition on this include, which is not great
because it slows down compilation and might trigger recompilation if
these files are updated.

This lint aims at fixing this situation.

changelog: Add new lint `doc_include_without_cfg`
2024-11-21 21:48:57 +00:00
Guillaume Gomez
404e47aa84 Add new lint doc_include_without_cfg 2024-11-21 22:43:55 +01:00
Philipp Krones
93d5ccdba7
Add cargo dev release subcommand
Currently this only provides the feature to auto-update the versions in the
`Cargo.toml` files. With the move to Josh, a command to get beta and stable
release commits will be added.
2024-11-19 17:59:33 +01:00
Samuel Moelius
b97ad4eccd Add const parameter REPLACEMENT_ALLOWED to DisallowedPath 2024-11-15 17:37:45 -05:00
Samuel Moelius
d0f3577720 Properly handle disallowed_types 2024-11-15 17:37:10 -05:00
Samuel Moelius
f159a3eb1d Support replacements in disallowed_methods 2024-11-15 17:37:08 -05:00
Philipp Krones
81483d4a6c
Move create_disallowed_map to clippy_config 2024-11-15 19:30:29 +01:00
Philipp Krones
4460db0850
Move MSRV implementation to clippy_utils 2024-11-15 19:26:39 +01:00
bors
5c6fe68c00 Auto merge of #13376 - decryphe:source-ordering, r=llogiq
new lint: `source_item_ordering`

changelog: [`source_item_ordering`]: Introduced a new restriction lint that checks the ordering of items in Modules, Enums, Structs, Impls and Traits.

From the written documentation:

> Why restrict this?
> Keeping a consistent ordering throughout the codebase helps with working as a team, and possibly improves maintainability of the codebase. The idea is that by defining a consistent and enforceable rule for how source files are structured, less time will be wasted during reviews on a topic that is (under most circumstances) not relevant to the logic implemented in the code. Sometimes this will be referred to as "bike-shedding".
>
> Keep in mind, that ordering source code alphabetically can lead to reduced performance in cases where the most commonly used enum variant isn't the first entry anymore, and similar optimizations that can reduce branch misses, cache locality and such. Either don't use this lint if that's relevant, or disable the lint in modules or items specifically where it matters. Other solutions can be to use profile guided optimization (PGO), or other advanced optimization methods.

I tried to build it as configurable as possible, as such a highly opinionated lint should be adjustable to personal opinions.

I'm open to any input and will be available both here and on the zulip for communication. In the meantime I'll be testing this lint against my own code-bases, which I've (manually) kept ordered with the default config, to see how well it works in practice.

And lastly, a big thanks to the community for making clippy the best linter there is!
2024-11-02 11:03:30 +00:00
chrysn
bd4aa170ef Add 'CoAP' to doc-valid-idents 2024-10-30 12:57:24 +01:00
decryphe
f7ab2c9908 new lint: source_item_ordering 2024-10-30 10:03:16 +01:00
Robert Spencer
acc3842d43 Add new map_with_unused_argument_over_ranges lint
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-29 21:32:00 +00:00
GnomedDev
d0b15f157c Swap Msrv from Vec to SmallVec 2024-10-27 14:11:20 +00:00
bors
3caff9962b Auto merge of #13571 - Alexendoo:website-code-indent, r=Centri3
Fix indentation of website code snippets

Fixes #13568

Follow up to #13359, I didn't catch that it swapped the `strip_prefix` out for a `trim` but they aren't interchangeable here

changelog: none
2024-10-26 18:48:12 +00:00
bors
c2534dcc49 Auto merge of #13460 - ROMemories:feat/freq-units-allowed-idents, r=Centri3
Add units/unit prefixes of frequency to doc-valid-idents

These units/unit prefixes often come up in the embedded world.

Should this PR also modify the `test_units` test? It seems only concerned with data units currently; should it also test frequency units?

changelog: [`doc_markdown`]: Add MHz, GHz, and THz to `doc-valid-idents`.
2024-10-24 08:50:36 +00:00
Alex Macleod
2666ed6c5b Fix indentation of website code snippets 2024-10-20 19:02:40 +00:00
Philipp Krones
4d5eaa0344
Bump Clippy version -> 0.1.84 2024-10-18 13:25:50 +02:00
bors
04849bd7d9 Auto merge of #13510 - alex-semenyuk:cleanup_const_float_classify, r=llogiq
Cleanup `const_float_classify`

As mentioned at #13508 `const_float_classify` has been stabilized recently in https://github.com/rust-lang/rust/pull/130157 and can be cleanup

Close #13508

changelog: [none]
2024-10-13 09:17:14 +00:00