Commit Graph

19496 Commits

Author SHA1 Message Date
Ethiraric
dadcd94b2a [unused_enumerate_index]: Keep explicit element type
Prior to this change, it might be that the lint would remove an explicit
type that was necessary for the type system to keep track of types.

This should be the last change that prevented this lint to be machine
applicable.
2024-03-14 23:12:47 +01:00
bors
b667d02340 Auto merge of #12472 - GuillaumeGomez:fix-10262, r=blyxyas
Don't emit `doc_markdown` lint for missing backticks if it's inside a quote

Fixes #10262.

changelog: Don't emit `doc_markdown` lint for missing backticks if it's inside a quote
2024-03-14 21:39:25 +00:00
Vadim Petrochenkov
f55a04928f hir: Remove opt_local_def_id_to_hir_id and opt_hir_node_by_def_id
Also replace a few `hir_node()` calls with `hir_node_by_def_id()`
2024-03-14 22:34:24 +03:00
bors
8a78128e9d Auto merge of #12386 - Ethiraric:fix-12381, r=blyxyas
[`use_self`]: Make it aware of lifetimes

Have the lint trigger even if `Self` has generic lifetime parameters.

```rs
impl<'a> Foo<'a> {
    type Item = Foo<'a>; // Can be replaced with Self

    fn new() -> Self {
        Foo { // No lifetime, but they are inferred to be that of Self
              // Can be replaced as well
            ...
        }
    }

    // Don't replace `Foo<'b>`, the lifetime is different!
    fn eq<'b>(self, other: Foo<'b>) -> bool {
        ..
    }
```

Fixes #12381

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

changelog: [`use_self`]: Have the lint trigger even if `Self` has generic lifetime parameters
2024-03-14 16:28:57 +00:00
bors
e77d7a3f37 Auto merge of #12477 - Kobzol:ci-concurrency-group, r=flip1995
CI: replace `cancel-outdated-builds` with `concurrency` group

This is the last remaining [usage](https://github.com/search?q=org%3Arust-lang%20cancel-outdated-builds&type=code) of the [cancel-outdated-builds](https://github.com/rust-lang/simpleinfra/tree/master/github-actions/cancel-outdated-builds) CI action. Which means that if we remove its usage, we can remove the code of the action :)

This action was replaced in `rust-lang/rust` with the native Github Actions `concurrency` group [last year](https://github.com/rust-lang/rust/pull/112955).

Note that unlike `rust-lang/rust`, which explicitly allows parallel try builds, `clippy` did not allow them, as all steps of the `clippy_bors.yaml` workflow used the `cancel-outdated-builds` action, regardless of the branch. So the new `concurrency` group mirrors that, which makes it a bit simpler than on `rust-lang/rust`.

changelog: none

r? `@Mark-Simulacrum`
2024-03-14 11:21:27 +00:00
bors
a75e271a65 Auto merge of #12282 - maekawatoshiki:fix, r=xFrednet
Handle false positive with `map_clone` lint

### Summary

- Fixes https://github.com/rust-lang/rust-clippy/issues/12271
- (This is my first contribution to clippy and any suggestion would be appreciated)

changelog: [`map_clone`]: Handle false positive with `map_clone` lint
2024-03-14 08:08:35 +00:00
The Miri Cronjob Bot
22577e55ef Merge from rustc 2024-03-14 05:01:33 +00:00
Guillaume Gomez
0e2897fd4f Rename hir::StmtKind::Local into hir::StmtKind::Let 2024-03-14 12:42:04 +01:00
Guillaume Gomez
da2795fe48 Rename ast::StmtKind::Local into ast::StmtKind::Let 2024-03-14 12:42:04 +01:00
maekawatoshiki
5f8d8f1656
Simplify logic 2024-03-14 12:48:34 +09:00
maekawatoshiki
c5d3b62cfc
Fix conflict 2024-03-14 12:40:33 +09:00
maekawatoshiki
560a5a8cd1 Fix logic 2024-03-14 12:36:55 +09:00
maekawatoshiki
20e4c74521 Handle false positive with map_clone 2024-03-14 12:36:54 +09:00
J-ZhengLi
fe4e0aca73 checks dbg inside other macros as well (but no ext macro);
some refractoring;
2024-03-14 09:32:05 +08:00
J-ZhengLi
0535f55831 lint nested dbg! macros, split tests 2024-03-14 09:29:29 +08:00
J-ZhengLi
1fe884401a fix [dbg_macro] FN when dbg is inside some complex macros 2024-03-14 09:29:29 +08:00
xFrednet
4cbe42e00d
RFC: Document Clippy's teams and team duties
I want to be clear: this is just the initial draft outlining what, I think, should be the responsibilities of the team members. It has not yet been discussed with anyone else.
2024-03-13 22:11:51 +01:00
y21
adcbb4a9b7 move readonly_write_lock to perf 2024-03-13 20:56:53 +01:00
Ethiraric
7cdeac5773 [unused_enumerate_index]: trigger on method calls
The lint used to check for patterns looking like:
```rs
for (_, x) in some_iter.enumerate() {
    // Index is ignored
}
```

This commit further checks for chained method calls constructs where we
can detect that the index is unused. Currently, this checks only for the
following patterns:
```rs
some_iter.enumerate().map_function(|(_, x)| ..)
let x = some_iter.enumerate();
x.map_function(|(_, x)| ..)
```
where `map_function` is one of `all`, `any`, `filter_map`, `find_map`,
`flat_map`, `for_each` or `map`.

Fixes #12411.
2024-03-13 20:28:01 +01:00
bors
660b058ba2 Auto merge of #12470 - sanxiyn:filetime, r=Alexendoo
filetime::FileTime::now() is new in 0.2.9

Clippy makes a use of `filetime::FileTime::now()`, which is new in `filetime` 0.2.9.

changelog: none
2024-03-13 19:12:49 +00:00
Guillaume Gomez
03d7ae8153 Also handle <blockquote> and <q> HTML tags 2024-03-13 19:31:01 +01:00
Guillaume Gomez
cd36b25c4f Add regression test for #10262 2024-03-13 19:25:36 +01:00
Guillaume Gomez
11759d1bad Don't emit doc_markdown lint for missing backticks if it's inside a quote 2024-03-13 19:25:36 +01:00
bors
73be4863f0 Auto merge of #12459 - y21:unconditional_recursion_from_into, r=Jarcho
lint when calling the blanket `Into` impl from a `From` impl

Closes #11150
```
warning: function cannot return without recursing
  --> x.rs:9:9
   |
9  | /         fn from(value: f32) -> Self {
10 | |             value.into()
11 | |         }
   | |_________^
   |
note: recursive call site
  --> x.rs:10:13
   |
10 |             value.into()
   |             ^^^^^^^^^^^^
```

I'm also thinking that we can probably generalize this lint to #11032 at some point (instead of hardcoding a bunch of impls), like how rustc's `unconditional_recursion` works, at least up to one indirect call, but this still seems useful for now :)

I've also noticed that we use `fn_def_id` in a bunch of lints and then try to get the node args of the call in a separate step, so I made a helper function that does both in one. I intend to refactor a bunch of uses of `fn_def_id` to use this later

I can add more test cases, but this is already using much of the same logic that exists for the other impls that this lint looks for (e.g. making sure that there are no conditional returns).

changelog: [`unconditional_recursion`]: emit a warning inside of `From::from` when unconditionally calling the blanket `.into()` impl
2024-03-13 16:32:25 +00:00
Jakub Beránek
11c2bad059
CI: replace cancel-outdated-builds with concurrency groupo 2024-03-13 17:26:07 +01:00
y21
65defdb474 [unconditional_recursion]: catch From -> Into -> From 2024-03-13 17:22:54 +01:00
bors
99e8000b92 Auto merge of #12466 - J-ZhengLi:issue12377, r=blyxyas
fix [`empty_docs`] trigger in proc-macro

fixes: #12377

---

changelog: fix [`empty_docs`] trigger in proc-macros
2024-03-12 19:23:26 +00:00
bors
92ca7c9569 Auto merge of #11287 - Centri3:#11285, r=llogiq
[`cast_lossless`]: Suggest type alias instead of the aliased type

Fixes #11285

Still an issue with the "from" side, i.e., `I8::from(1) as I64` shows as `i8 to I64`, but this should be ok. Not possible to reliably fix currently anyway.

changelog: [`cast_lossless`]: Suggest type alias instead of the aliased type
2024-03-12 15:28:10 +00:00
Catherine Flores
244d7da817 [cast_lossless]: Suggest type alias instead of the aliased type 2024-03-12 10:16:27 -05:00
bors
3a149111ba Auto merge of #12469 - pavedroad:master, r=y21
chore: fix some typos

Thank you for making Clippy better!

We're collecting our changelog from pull request descriptions.
If your PR only includes internal changes, you can just write
`changelog: none`. Otherwise, please write a short comment
explaining your change.

It's also helpful for us that the lint name is put within backticks (`` ` ` ``),
and then encapsulated by square brackets (`[]`), for example:
```
changelog: [`lint_name`]: your change
```

If your PR fixes an issue, you can add `fixes #issue_number` into this
PR description. This way the issue will be automatically closed when
your PR is merged.

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]
- \[ ] Added passing UI tests (including committed `.stderr` file)
- \[ ] `cargo test` passes locally
- \[ ] Executed `cargo dev update_lints`
- \[ ] Added lint documentation
- \[x] Run `cargo dev fmt`

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

Note that you can skip the above if you are just opening a WIP PR in
order to get feedback.

Delete this line and everything above before opening your PR.

---

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

changelog:
2024-03-12 10:00:15 +00:00
bors
a8a7371728 Auto merge of #12417 - Alexendoo:iter-nth, r=flip1995
Move `iter_nth` to `style`, add machine applicable suggestion

There's no `O(n)` involved with `.iter().nth()` on the linted types since the iterator implementations provide `nth` and/or `advance_by` that operate in `O(1)`

For slice iterators the codegen is equivalent, `VecDeque`'s iterator seems to codegen differently but that doesn't seem significant enough to keep it as a perf lint

changelog: [`iter_nth`] Move to `style`

r? `@flip1995`
2024-03-12 08:54:26 +00:00
bors
60f7f0669b Auto merge of #12462 - CBSpeir:clippy-book-typo, r=flip1995
Fix typo in section '6.10. Macro Expansions' of the Clippy Book

Under the "Span.ctxt method" heading in *Section 6.10. Macro Expansions* of the *Clippy Book*, the type returned by the
`Span::ctxt` method is listed as `SpanContext`.  The correct type name should be `SyntaxContext`.

---

changelog: Fixed typo in "Section 6.10. Macro Expansions" of the Clippy Book. `SpanContext` changed to `SyntaxContext`.
2024-03-12 08:39:59 +00:00
Seo Sanghyeon
27c49e1756 filetime::FileTime::now() is new in 0.2.9 2024-03-12 16:22:26 +09:00
pavedroad
f472b50710 chore: fix some typos
Signed-off-by: pavedroad <qcqs@outlook.com>
2024-03-12 14:38:57 +08:00
Oli Scherer
97f2ade8e6 s/mt/mutability/ 2024-03-12 05:53:46 +00:00
Oli Scherer
013bf92dcc Add nested bool to DefKind::Static.
Will be used in the next commit
2024-03-12 05:53:46 +00:00
Oli Scherer
b205192f65 Change DefKind::Static to a struct variant 2024-03-12 05:53:46 +00:00
The Miri Cronjob Bot
25fb1f0019 Merge from rustc 2024-03-12 05:45:33 +00:00
J-ZhengLi
3cd6fd15a5 fix [empty_docs] trigger in proc-macro 2024-03-12 10:40:40 +08:00
J-ZhengLi
10677d6901 add with_empty_docs attr macro & test cases for issue #12377 2024-03-12 09:19:35 +08:00
Jacherr
edcf10e2f7 update_lints 2024-03-11 22:55:31 +00:00
Jacherr
100ab4993e new restriction lint: division_remainder_used 2024-03-11 22:51:03 +00:00
bors
e22ca03627 Auto merge of #12452 - CBSpeir:dedup-manual-retain, r=blyxyas
[`manual_retain`]: Fix duplicate diagnostics

Relates to: #12379

The first lint guard executed in `LateLintPass::check_expr` was testing if the parent was of type `ExprKind::Assign`.  This meant the lint emitted on both sides of the assignment operator when `check_expr` is called on either `Expr`.  The guard in the fix only lints once when the `Expr` is of kind `Assign`.

changelog:  Fix duplicate lint diagnostic emission from [`manual_retain`]
2024-03-11 22:21:27 +00:00
bors
f685a4b3f1 Auto merge of #12378 - GuillaumeGomez:duplicated_attr, r=blyxyas
Add new `duplicated_attributes` lint

It's a lint idea that `@llogiq` gave me while reviewing another PR.

There are some limitations, in particular for the "output". Initially I wanted to make it possible for directly lint against the whole attribute if its parts were all duplicated, but then I realized that the output would be chaotic if the duplicates were coming from different attributes, so I preferred to go to the simplest way and simply emit a warning for each entry. Not the best, but makes the implementation much easier.

Another limitation is that `cfg_attr` would be a bit more tricky to implement because we need to check if two `cfg` sets are exactly the same. I added a FIXME and will likely come back to it later.

And finally, I updated the `cargo dev update_lints` command because the generated `tests/ui/rename.rs` file was emitting the `duplicated_attributes` lint, so I allowed this lint inside it to prevent it from working.

changelog: Add new `duplicated_attributes` lint
2024-03-11 18:36:21 +00:00
Christopher B. Speir
d66a0ec714 Fix typo in section '6.10. Macro Expansions' of the Clippy Book
The struct returned by the `Span::ctxt` method was listed as
`SpanContext`. The correct struct is currently named `SyntaxContext`.
2024-03-11 13:31:02 -05:00
bors
870e016b65 Auto merge of #12430 - sanxiyn:direct-minimal-versions, r=Alexendoo
Fix dependency specifications

As Clippy lacks `Cargo.lock`, it makes sense to test its dependency specifications with [direct-minimal-versions](https://doc.rust-lang.org/cargo/reference/unstable.html#direct-minimal-versions). This can be done with the following addition to `.cargo/config.toml`.

```toml
[unstable]
direct-minimal-versions = true
```

* `tempfile` 3.3 is required by `clippy_lints`.
* `regex` 1.5.5 is required by `ui_test` 0.22.2.
* `quote` 1.0.25 is required by `syn` 2.0.0.
* `serde` 1.0.145 is required by `toml` 0.7.3.

changelog: none
2024-03-11 17:19:06 +00:00
bors
6ff4e71a05 Auto merge of #12448 - WeiTheShinobi:fix_single_match, r=dswij
[`single_match`]: Fix duplicate diagnostics

Relates to #12379

edit two test file
`tests/ui/single_match_else.rs`
`tests/ui/single_match.rs`

those two test file point to the same lint

---

changelog: [`single_match`] Fix duplicate diagnostics
2024-03-11 10:29:00 +00:00
bors
02156dcf09 Auto merge of #12458 - hamirmahal:refactor/readability-improvement, r=dswij
[`seek_from_current`]: readability improvements

fixes #12457.

---

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

changelog: [`seek_from_current`]: readability improvements
2024-03-11 07:00:36 +00:00
Hamir Mahal
9c51fd99aa
refactor: readability improvement for seek lint 2024-03-10 12:51:33 -07:00
WeiTheShinobi
8e55bbf115 [single_match]: Fix duplicate diagnostics 2024-03-11 01:08:37 +08:00