Commit graph

18397 commits

Author SHA1 Message Date
bors
72c0d80f46 Auto merge of #11801 - y21:split_doc_pass, r=blyxyas
Split `doc.rs` up into a subdirectory

So, first, sorry for the bad diff. 😅

In #11798, `@flip1995`  suggested splitting `doc.rs` up, much like how we have the `methods/`, `matches/`, `types/` subdirectories.
I agree with this, the file is getting bigger as we add more and more doc lints that it makes sense to do this refactoring.

This is purely an internal change that moves things around a bit.
(**EDIT:** depending on the outcome of https://github.com/rust-lang/rust-clippy/pull/11801#issuecomment-1816715615 , this may change the lint group name from `doc_markdoc` to `doc`).

I tried to not change any of the actual logic of the lints and as such some things weren't as easy to move to a separate file. So we still have some `span_lint*` calls in the `doc/mod.rs` file, which I think is fine. This is also the case in `methods/mod.rs`.

Also worth mentioning that the lints missing_errors_doc, missing_panics_doc, missing_safety_doc and unnecessary_safety_doc have a lot of the same logic so it didn't make much sense for each of these to be in their own file. Instead I just put them all in `missing_headers.rs`

I also added a bit of documentation to the involved `check_{attrs,doc}` methods.

changelog: none
2023-11-20 17:22:05 +00:00
bors
11a2eb03fa Auto merge of #11453 - xFrednet:11208-path-join-correct, r=blyxyas
New lint `clippy::join_absolute_paths`

Hey `@ofeeg,` this PR is a copy of all the changes you did in 47171d3c63 from PR https://github.com/rust-lang/rust-clippy/pull/11208. I wasn't sure how to fix the git history. Hope you're okay with me figuring this out in this separate PR

---

changelog: New lint [`join_absolute_paths`]
[#11453](https://github.com/rust-lang/rust-clippy/pull/11453)

Closes: https://github.com/rust-lang/rust-clippy/issues/10655

r? `@Centri3` Since you also gave feedback on the other PR. I hope that I copied everything correctly, but a third pair of eyes would be appreciated :D
2023-11-20 12:30:03 +00:00
ofeeg
34d9e88a47
New lint clippy::join_absolute_paths
* `join_absolute_paths` Address PR review
* Move `clippy::join_absolute_paths` to `clippy::suspicious`
* `join_absolute_paths`: Address PR review

Co-Authored-By: ofeeg <mhanna0000@gmail.com>
2023-11-20 13:28:28 +01:00
y21
56cee3c587 move doc.rs to its own subdirectory 2023-11-20 12:08:07 +01:00
bors
41140e3cb8 Auto merge of #11840 - GuillaumeGomez:improve-maybe_misused_cfg, r=blyxyas
Improve maybe misused cfg

Follow-up of the improvements that were suggested to me in https://github.com/rust-lang/rust-clippy/pull/11821:

 * I unified the output to use the same terms.
 * I updated the code to prevent creating a new symbol.

r? `@blyxyas`

changelog: [`maybe_misued_cfg`]: Output and code improvements
2023-11-19 22:31:11 +00:00
Guillaume Gomez
dfbca7ffa8 Improve maybe_misused_cfg lint output
Small performance improvement when comparing symbols for `maybe_misused_cfg`
Improve suggestion for `maybe_misused_cfg` lint
2023-11-19 22:46:19 +01:00
bors
9c3a365fd2 Auto merge of #11781 - partiallytyped:11710, r=xFrednet
Verify Borrow<T> semantics for types that implement Hash, Borrow<str> and Borrow<[u8]>.

Fixes #11710

The essence of the issue is that types that implement Borrow<T> provide a facet or a representation of the underlying type. Under these semantics `hash(a) == hash(a.borrow())`.

This is a problem when a type implements `Borrow<str>`, `Borrow<[u8]>` and Hash, it is expected that the hash of all three types is identical. The problem is that the hash of [u8] is not the same as that of a String, even when the byte reference ([u8]) is derived from `.as_bytes()`

- [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`

---

 - [x] Explanation of the issue in the code
 - [x] Tests reproducing the issue
 - [x] Lint rule and emission

---

changelog: New lint: [`impl_hash_borrow_with_str_and_bytes`]
[#11781](https://github.com/rust-lang/rust-clippy/pull/11781)
2023-11-19 10:59:34 +00:00
Quinn Sinclair
3c1e0afa58 New Lint [impl_hash_with_borrow_str_and_bytes]
Implements a lint to prevent implementation of Hash, Borrow<str> and
Borrow<[u8]> as it breaks Borrow<T> "semantics". According to the book,
types that implement Borrow<A> and Borrow<B> must ensure equality of
borrow results under Eq,Ord and Hash.

> In particular Eq, Ord and Hash must be equivalent for borrowed and
owned values: x.borrow() == y.borrow() should give the same result as x == y.

In the same way, hash(x) == hash(x as Borrow<[u8]>) != hash(x as Borrow<str>).

changelog: newlint [`impl_hash_with_borrow_str_and_bytes`]
2023-11-19 11:33:01 +01:00
bors
dbd19f9b48 Auto merge of #11691 - sjwang05:lines-filter-map-ok-fix, r=Centri3
Lint `flatten()` under `lines_filter_map_ok`

Fixes #11686

changelog: [`lines_filter_map_ok`]: Also lint calls to `flatten()`
2023-11-19 01:50:24 +00:00
bors
9263f806d8 Auto merge of #11782 - Alexendoo:macro-use-imports-ordering, r=Centri3
Make `macro_use_imports` lint ordering more stable

changelog: none

Fixes [the `macro_use_imports` ordering dependence](https://github.com/rust-lang/rust/pull/117649#issuecomment-1797716088) on the hash of `Span`s
2023-11-19 01:39:06 +00:00
bors
6eb935a578 Auto merge of #11826 - kpreid:typo, r=Alexendoo
Fix typos in recent lint documentation.

Fixes typos and markup errors, and also makes the examples more realistic by hiding the `;`s so as not to visibly be discarding the computed value. Affected lints:

* `redundant_as_str`
* `unnecessary_map_on_constructor`

changelog: none
2023-11-18 19:49:46 +00:00
Kevin Reid
b3f4a9015c Remove space and rephrase map() advice. 2023-11-18 10:53:03 -08:00
bors
e8e9510219 Auto merge of #11002 - y21:issue9422, r=Jarcho
teach `eager_or_lazy` about panicky arithmetic operations

Fixes #9422
Fixes #9814
Fixes #11793

It's a bit sad that we have to do this because arithmetic operations seemed to me like the prime example where a closure would not be necessary, but this has "side effects" (changes behavior when going from lazy to eager) as some of these panic on overflow/underflow if compiled with `-Coverflow-checks` (which is the default in debug mode).
Given the number of backlinks in the mentioned issues, this seems to be a FP that is worth fixing, probably.

changelog: [`unnecessary_lazy_evaluations`]: don't lint if closure has panicky arithmetic operations
2023-11-17 18:53:15 +00:00
Kevin Reid
bffb664fbf Fix markup in recent lint documentation.
Also make the examples more realistic by hiding the `;`s so as not to
visibly be discarding the computed value.
2023-11-17 10:12:12 -08:00
bors
31e38fee23 Auto merge of #11821 - GuillaumeGomez:misspelled-cfg, r=blyxyas
Extend `maybe_misused_cfg` lint over `cfg(test)`

Fixes #11240.

One thought I had is that we could use the levenshtein distance (of 1) to ensure this is indeed `test` that was targeted. But maybe it's overkill, not sure.

changelog: [`maybe_misused_cfg`]: Extend lint over `cfg(test)`

r? `@blyxyas`
2023-11-17 11:49:20 +00:00
bors
25f4f858cc Auto merge of #11828 - CleanCut:patch-1, r=xFrednet
Fix typo

Fix a little spelling error.

changelog: none
2023-11-17 11:41:11 +00:00
Nathan Stocks
4143acf4c8
fix typo 2023-11-16 17:18:48 -07:00
y21
aca4086d7f simplify matching on binop result 2023-11-16 23:05:17 +01:00
bors
edefa9770d Auto merge of #11824 - flip1995:ci-update-rust-cache-gha, r=Alexendoo
Update rust-cache GHA in deploy workflow

This action was way outdated, produced a lot of warnings and didn't seem to work anymore.

changelog: none
2023-11-16 21:22:17 +00:00
Philipp Krones
8d89cc4307
Update rust-cache GHA in deploy workflow
This action was way outdated, produced a lot of warnings and didn't seem to work
anymore.
2023-11-16 19:31:06 +01:00
bors
edb720b199 Auto merge of #11823 - flip1995:rustup, r=flip1995
Rustup

r? `@ghost`

changelog: none
2023-11-16 18:08:51 +00:00
Philipp Krones
6f952fbe53
Bump Clippy version -> 0.1.76 2023-11-16 19:02:33 +01:00
Philipp Krones
887f5a5bb4
Bump nightly version -> 2023-11-16 2023-11-16 19:02:15 +01:00
Philipp Krones
6fab1485c3
Merge remote-tracking branch 'upstream/master' into rustup 2023-11-16 19:02:04 +01:00
Guillaume Gomez
f08037c2f5 Update documentation for MAYBE_MISUSED_CFG lint 2023-11-16 18:07:26 +01:00
Guillaume Gomez
a621d71b4e Add UI test for mispelled test 2023-11-16 18:07:26 +01:00
Guillaume Gomez
74451cd060 Extend maybe_misused_cfg lint over cfg(test) 2023-11-16 18:05:00 +01:00
y21
7696c9d1d5 allow more div and rem operations that can be checked 2023-11-16 17:30:10 +01:00
y21
1e0597cb68 [match_same_arms]: respect allow attrs on arms 2023-11-16 17:28:37 +01:00
y21
23ee33255c lint when relevant sides of binops are constants 2023-11-16 04:49:11 +01:00
bors
406d953820 Auto merge of #11806 - xFrednet:changelog-1-74, r=Alexendoo
Changelog for Rust 1.74 🎃

Roses are red,
Halloween is over,
Have you considered,
Buying a Mars rover?

---

### The cats of this release:

<img height=500 src="https://github.com/rust-lang/rust-clippy/assets/17087237/095bd32e-b5e3-41db-8f0f-bdef7ca1a6d0" alt="The cats of this Clippy release" />

<sub>The cat for the next release can be nominated in the comments</sub>

---

changelog: none
2023-11-15 12:31:24 +00:00
bors
3ea5bcf5ee Auto merge of #11809 - hrxi:pr_if_same_then_else_style, r=Alexendoo
Change `if_same_then_else` to be a `style` lint

CC #3770

From https://github.com/rust-lang/rust-clippy/issues/3770#issuecomment-687565594 (`@flip1995):`

> Oh I thought I replied to this: I definitely see now that having this
> as a correctness lint might be the wrong categorization. What we might
> want to do is to just allow this lint, if there are comments in the
> arm bodies. But a good first step would be to downgrade this lint to
> style or complexity. I would vote for style since merging two arms is
> not always less complex.

changelog: [`if_same_then_else`]: Change to be a `style` lint
2023-11-15 12:11:14 +00:00
bors
7ad3373bb1 Auto merge of #11802 - dswij:issue-11765, r=xFrednet
`needless_return_with_question_mark` ignore let-else

Fixes #11765

This PR makes `needless_return_with_question_mark` to ignore expr inside let-else.

changelog: [`needless_return_with_question_mark`] ignore let-else
2023-11-15 10:15:47 +00:00
bors
662ea3f9f4 Auto merge of #11811 - y21:avoid_cx_struct_span_lint, r=Manishearth
disallow calls to `LintContext::struct_span_lint` and `TyCtxt::struct_span_lint_hir`

`LintContext::struct_span_lint` and `TyCtxt::struct_span_lint_hir` don't show the link to the clippy documentation, see: #11805

In #11810, the last few calls to those methods were replaced with `span_lint_*`. It seems like we should just disallow them altogether so that no new code tries to use them.

The existing `disallowed_methods` lint makes this easy.

changelog: none
2023-11-15 07:27:46 +00:00
bors
783b914fae Auto merge of #11804 - y21:issue-11803, r=dswij
[`impl_trait_in_params`]: avoid ICE when function with `impl Trait` type has no parameters

Fixes #11803

If I'm reading the old code correctly, it was taking the span of the first parameter (without checking that it exists, which caused the ICE) and uses that to figure out where the generic parameter to insert should go (cc `@blyxyas` you wrote the lint, is that correct?).
This seemed equivalent to just `generics.span`, which doesn't require calculating the spans like that and simplifies it a fair bit

changelog: don't ICE when function has no parameters but generics have an `impl Trait` type
2023-11-15 04:03:44 +00:00
y21
19eec0b7cc disallow struct_span_lint 2023-11-15 03:20:04 +01:00
bors
abf01e469b Auto merge of #11810 - Jacherr:cast-possible-wrap-link, r=Manishearth
add help text where missing to lints

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

Essentially just changes the section of code that applies the lint from using `cx.struct_span_lint` and instead opts for `span_lint_and_then`, which automatically appends the help text.

changelog: add missing help text for `cast_possible_wrap`, `mod_module_files`, and `self_named_module_files` lints
2023-11-15 01:23:11 +00:00
Jacherr
11881bee6b also move module_style to span_lint_x functions 2023-11-15 01:10:20 +00:00
Jacherr
a86a57079d replace lint with span_lint_and_then 2023-11-15 00:14:38 +00:00
hrxi
b3073c536b Change if_same_then_else to be a style lint
CC #3770

From https://github.com/rust-lang/rust-clippy/issues/3770#issuecomment-687565594 (@flip1995):

> Oh I thought I replied to this: I definitely see now that having this
> as a correctness lint might be the wrong categorization. What we might
> want to do is to just allow this lint, if there are comments in the
> arm bodies. But a good first step would be to downgrade this lint to
> style or complexity. I would vote for style since merging two arms is
> not always less complex.
2023-11-15 00:33:14 +01:00
xFrednet
cab975c713
Changelog for Rust 1.74 🎃 2023-11-14 18:08:00 +01:00
xFrednet
9401cf21e4
Update version attribute for 1.74 lints 2023-11-14 18:08:00 +01:00
bors
0c42e451d6 Auto merge of #11791 - Jacherr:iter_over_hash_type, r=Jarcho
Implement new lint `iter_over_hash_type`

Implements and fixes https://github.com/rust-lang/rust-clippy/issues/11788

This PR adds a new *restriction* lint `iter_over_hash_type` which prevents `Hash`-types (that is, `HashSet` and `HashMap`) from being used as the iterator in `for` loops.

The justification for this is because in `Hash`-based types, the ordering of items is not guaranteed and may vary between executions of the same program on the same hardware. In addition, it reduces readability due to the unclear iteration order.

The implementation of this lint also ensures the following:
- Calls to `HashMap::keys`, `HashMap::values`, and `HashSet::iter` are also denied when used in `for` loops,
- When this expression is used in procedural macros, it is not linted/denied.

changelog: add new `iter_over_hash_type` lint to prevent unordered iterations through hashed data structures
2023-11-14 15:55:00 +00:00
bors
ca8f33e19b Auto merge of #11778 - granddaifuku:fix/reduce-indexing-manual_memcpy-when-array-length-is-equal-to-range, r=blyxyas
fix: [manual_memcpy] reduce indexing suggestions when array length is equal to loop range

fixes: #11689

This PR improves `manual_memcpy` suggestions by reducing unnecessary indexing.

For example,
```rust
let src = [0, 1, 2, 3, 4];
let mut dest = [0; 4];
for i in 0..4 {
    dest[i] = src[i];
{
```
Clippy suggests `dest[..4].copy_from_slice(&src[..4]);`.
I reduced this suggestion as `dest.copy_from_slice(&src[..4]);`. (Removed needless indexing.)

changelog: [`manual_memcpy`]: Reduce indexing suggestions when array length is equal to loop range
2023-11-14 13:27:36 +00:00
lcnr
9aa2330e41 finish RegionKind rename
- `ReFree` -> `ReLateParam`
- `ReEarlyBound` -> `ReEarlyParam`
2023-11-14 13:13:27 +00:00
Yudai Fukushima
a9d42e6d6d fix: reduce [manual_memcpy] indexing when array length is same to loop range
Format

refactor: extract function to shrink function length

fix: remove cmp to calculate range

fix: replace if_chain with let chains
2023-11-14 22:05:44 +09:00
y21
3f6b29ad32 [impl_trait_in_params]: fix span calculation 2023-11-14 13:52:44 +01:00
dswij
48f38eb131 needless_return_with_question_mark ignore let-else 2023-11-14 16:30:52 +08:00
bors
c3a6b376a4 Auto merge of #11800 - blyxyas:meow-meow, r=Centri3
Removing @Centri3 from reviewer rotation

Catherine decided that the best course of action would be to (maybe temporarily) remove her from the reviewer's rotation (but not unassign her from her current reviews). This PR does that. She'll always be welcomed back if she wants to review some more ❤️

> Alejandra González: [youremyfrennow.mp4](https://rust-lang.zulipchat.com/user_uploads/4715/7nE2W6cb8Q02gcK-vubvmsPM/youremyfrennow.mp4)
>
>Catherine, Fred (`@xFrednet` ) noticed that you aren't as active as in the summer, and proposed that maybe you preferred to be removed from the reviewer rotation. Don't worry, you aren't being taken out of the team, just wanted to know if you maybe preferred to not have those reviews pilling up (they can be pretty stressful to see).
>
>If you decide to step out of the reviewers rotation, you wouldn't be removed from the team, you just wouldn't have that responsability. Everyone takes break and that's fine, so yeah, if you want to not have to review PRs, let me know!
>
>So yeah, from weird teenager transfem to (probably weird) teenager transfem, the choice is in your hand.
>
>Alejandra González: meow meow ^•ﻌ•^
>
>Catherine (Centri3): Yeah that's probably best now, I'll still try with any I'm currently assigned to but I would prefer not to get anymore until then
>Catherine (Centri3): meow meow :3

changelog:none

r? `@Centri3`
2023-11-13 17:19:49 +00:00
Jacherr
f8ea496495 add tests for type-aliased hash types 2023-11-13 16:52:59 +00:00