Commit graph

17778 commits

Author SHA1 Message Date
Guillaume Gomez
3a31c05578 Remove/move comments to prevent weird rustfmt wrapping 2023-08-22 17:17:48 +02:00
Guillaume Gomez
9c96605b20 Manually add annotations for ui tests 2023-08-22 17:14:08 +02:00
bors
fc1152abf6 Auto merge of #11359 - Alexendoo:unwrap-or-default-check-suggestion, r=dswij
Check that the suggested method exists in unwrap_or_default

Fixes #11355

changelog: none
2023-08-20 15:26:33 +00:00
Alex Macleod
8f2d47ea72 Check that the suggested method exists in unwrap_or_default 2023-08-19 20:22:45 +00:00
bors
7408f1d231 Auto merge of #11319 - lengyijun:map_foreach, r=blyxyas
[iter_overeager_cloned]: detect .cloned().map() and .cloned().for_each()

changelog: [`iter_overeager_cloned`]

key idea:
for `f` in `.map(f)` and `.for_each(f)`:
1. `f` must be closure
2. don't lint if mutable paramter in clsure `f`: `|mut x| ...`
3. don't lint if parameter is moved
4. maybe incorrect
2023-08-19 13:42:11 +00:00
lengyijun
e440065a0f [iter_overeager_cloned]: detect .cloned().map() and .cloned().for_each()
key idea:
for `f` in `.map(f)` and `.for_each(f)`:
1. `f` must be a closure with one parameter
2. don't lint if mutable paramter in clsure `f`: `|mut x| ...`
3. don't lint if parameter is moved
2023-08-19 21:18:14 +08:00
bors
b7cad50eca Auto merge of #11204 - y21:issue10956, r=Alexendoo
new lint: [`should_panic_without_expect`]

Closes #10956

changelog: new lint: [`should_panic_without_expect`]
2023-08-19 12:28:44 +00:00
y21
b4ab67fd4a remove useless path 2023-08-19 14:20:15 +02:00
y21
e52bd6f850 new lint: should_panic_without_expect 2023-08-18 18:57:14 +02:00
bors
d9e6aac8bb Auto merge of #11351 - xFrednet:changelog-1-72, r=Centri3
Update version attribute for 1.72 lints

Roses are red,
Violets are blue,
Marker is alive,
and so are you!

---

![cat gif](https://cataas.com/cat/SbbeZwoC81vSTzBX)

cc: https://github.com/rust-lang/rust-clippy/issues/10847#issuecomment-1683927955

---

I've also checked the `beta-nominated` label, the changelog should include everything :)

changelog: none
2023-08-18 16:27:53 +00:00
xFrednet
8f06b19b45
Changelog for Rust 1.72 🏖️ 2023-08-18 18:27:11 +02:00
xFrednet
41570c1ee7
Update version attribute for 1.72 lints 2023-08-18 18:27:10 +02:00
bors
1698ce0ba1 Auto merge of #11280 - samueltardieu:issue-11267, r=Centri3
[new_without_default]: include `where` clause in suggestions, make applicable

changelog: [`new_without_default`]: include `where` clause in suggestions
2023-08-18 15:55:40 +00:00
bors
40872cb30f Auto merge of #11348 - eopb:eopb-patch-1, r=flip1995
Remove use of `box_syntax` in `CONTRIBUTING.md` example

`box_syntax` no longer exists.
[`clippy_lints/src/lib.rs` now uses `Box::new`](d5298bea7f/clippy_lints/src/lib.rs (L809C70-L809C70))

changelog: none
2023-08-18 12:56:48 +00:00
Ethan Brierley
ede43069cc
Remove use of box_syntax CONTRIBUTING.md` example
`box_syntax` no longer exists.
[`clippy_lints/src/lib.rs` now uses `Box::new`](d5298bea7f/clippy_lints/src/lib.rs (L809C70-L809C70))
2023-08-17 21:47:03 +01:00
bors
d5298bea7f Auto merge of #11314 - GuillaumeGomez:needless_ref_mut_async_block, r=Centri3
Correctly handle async blocks for NEEDLESS_PASS_BY_REF_MUT

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

The problem was that the `async block`s are popping a closure which we didn't go into, making it miss the mutable access to the variables.

cc `@Centri3`

changelog: none
2023-08-17 15:55:23 +00:00
Guillaume Gomez
5875bd2b5f Use HirId from PlaceWithHirId rather than using the one provided to the function 2023-08-17 17:45:17 +02:00
bors
701e77c87f Auto merge of #11070 - y21:issue11065, r=flip1995
[`useless_conversion`]: only lint on paths to fn items and fix FP in macro

Fixes #11065 (which is actually two issues: an ICE and a false positive)

It now makes sure that the function call path points to a function-like item (and not e.g. a `const` like in the linked issue), so that calling `TyCtxt::fn_sig` later in the lint does not ICE (fixes https://github.com/rust-lang/rust-clippy/issues/11065#issuecomment-1616836099).
It *also* makes sure that the expression is not part of a macro call (fixes https://github.com/rust-lang/rust-clippy/issues/11065#issuecomment-1616919639). ~~I'm not sure if there's a better way to check this other than to walk the parent expr chain and see if any of them are expansions.~~ (edit: it doesn't do this anymore)

changelog: [`useless_conversion`]: fix ICE when call receiver is a non-fn item
changelog: [`useless_conversion`]: don't lint if argument is a macro argument (fixes a FP)

r? `@llogiq` (reviewed #10814, which introduced these issues)
2023-08-17 14:41:46 +00:00
Guillaume Gomez
7e46217362 Add new regression test for needless_pass_by_ref_mut 2023-08-17 14:24:04 +02:00
bors
d43486dc8c Auto merge of #10644 - blyxyas:book-method_checking, r=flip1995
Clippy Book Chapter Updates Reborn: Method Checking

This PR adds a new chapter to the book: "Method Checking". Some major re-phrasing was done and some changes in the code comments (apart from grammar and minor changes).

## Notes

- Requires #10595 **and** #10622 to be merged before this, or else several links will be broken
- To talk about the whole project, please use the tracking issue for the project #10597 (It also contains a timeline, discussions and more information)

changelog: Add a new "Method Checking" chapter to the book.

r? `@flip1995`
2023-08-16 12:57:18 +00:00
Philipp Krones
1dbc8dd0cf
Fix define_lints->defining_lints typo in link 2023-08-16 14:54:47 +02:00
Philipp Krones
e8d79b8645
Formatting 2023-08-16 14:50:40 +02:00
blyxyas
9e4a2d7fca
Fixes based on reviews 2023-08-16 14:50:40 +02:00
blyxyas
111f0229da
Add "Method Checking"
Co-authored-by: Nahua <kangnahua@gmail.com>
2023-08-16 14:50:40 +02:00
bors
87d148759a Auto merge of #10595 - blyxyas:book-define_lints, r=flip1995
Clippy Book Chapter Updates Reborn: Defining Lints

Revival of #9659, I've made a few changes (mainly ones from reviews from #9426, like removing mid-section storytelling) and some re-writes. The goal of the project would be to slowly re-write the Clippy book (only chapters that need it) to more up-to-date style.

## Notes

- Things like `git status` commands have changed, we need to make sure that they're correct.
- As this is a team-wide effort, I would please ask anyone and everyone to read it and give your opinion.
- To talk about the whole project, please use the tracking issue for the project #10597  (It also contains a timeline, discussions and more information)

---

changelog: Add a new "Defining lints" chapter to the book

r? `@flip1995`
2023-08-16 12:37:22 +00:00
Philipp Krones
783c119768
Address review comments and formatting 2023-08-16 14:36:09 +02:00
blyxyas
6076cda3c5
Fix CI 2023-08-16 14:30:39 +02:00
blyxyas
b91d676b60
Move "Lint types to the top" 2023-08-16 14:30:39 +02:00
blyxyas
7465436270
Improve briefness 2023-08-16 14:30:39 +02:00
blyxyas
735380b2cc
Try to clear up confusion between type and category. 2023-08-16 14:30:39 +02:00
blyxyas
c22906b37f
Fix CI formatting issues 2023-08-16 14:30:38 +02:00
blyxyas
97d31c8ae0
New chapter: Defining Lints
Co-authored-by: Nahua <kangnahua@gmail.com>
2023-08-16 14:30:38 +02:00
bors
710db18ccd Auto merge of #11336 - Alexendoo:uitest-backslash, r=flip1995
Use ui_test's Windows path backslash heuristic

changelog: none

Instead of unconditionally replacing `\` with `/` we now use [`Match::PathBackslash`](https://docs.rs/ui_test/latest/ui_test/enum.Match.html#variant.PathBackslash) to only replace backslashes in paths that look like windows paths

`ui-toml` and `ui-cargo` tests still use the old way because they produce verbatim paths on windows in some tests (`\\?\C:\foo\...`) which was finnicky to get the replacement order correct with

Also removes the `ui_test` -> `compiletest` alias and `VarGuard`
2023-08-15 15:22:29 +00:00
bors
11efa0133f Auto merge of #11321 - J-ZhengLi:issue11281, r=giraffate
allow calling `to_owned` on borrowed value for [`implicit_clone`]

fixes: #11281

a small and simple fix that give up checking for `referenced_value.to_owned()` usage.

changelog: allow calling `to_owned` with borrowed value for [`implicit_clone`]
2023-08-15 11:42:05 +00:00
J-ZhengLi
aa8995e589 allow calling to_owned with borrowed value for [implicit_clone] 2023-08-15 09:41:15 +08:00
Alex Macleod
77d10ac63d Use ui_test's Windows path backslash heuristic 2023-08-14 15:59:00 +00:00
y21
f47165c703 find expansions more efficiently 2023-08-14 16:50:31 +02:00
y21
2820d980cb [useless_conversion]: fix FP in macro and add test 2023-08-14 16:28:04 +02:00
y21
34348f72f4 [useless_conversion]: make sure path points to fn-like item 2023-08-14 16:28:04 +02:00
bors
b5bfd1176b Auto merge of #11289 - lengyijun:filter_find, r=blyxyas
[iter_overeager_cloned]: detect `.cloned().filter()` and `.cloned().find()`

changelog: [`iter_overeager_cloned`]: detect `.cloned().filter()` and `.cloned().find()`

Key idea:
```
// before
iter.cloned().filter(|x| unimplemented!() )
// after
iter.filter(|&x| unimplemented!() ).cloned()

// before
iter.cloned().filter( foo )
// after
// notice `iter` must be `Iterator<Item= &T>` (callee of `cloned()`)
// so the parameter in the closure of `filter` must be `&&T`
// so the deref is safe
iter.filter(|&x| foo(x) ).cloned()
```
2023-08-14 11:15:45 +00:00
lengyijun
fc061890d6 [iter_overeager_cloned]: detect .cloned().filter() and .cloned().find()
Key idea:
```
// before
iter.cloned().filter(|x| unimplemented!() )
// after
iter.filter(|&x| unimplemented!() ).cloned()

// before
iter.cloned().filter( foo )
// after
iter.filter(|&x| foo(x) ).cloned()
```
2023-08-14 09:13:01 +08:00
bors
344ae115db Auto merge of #11329 - unvalley:lint-binary-heap-retain, r=Alexendoo
[`manual_retain`]: add lint case for `binary_heap`

Closes #9059

This PR adds changes to perform linting on the `binary_heap` as well, under the [manual_retain rule](https://rust-lang.github.io/rust-clippy/master/index.html#/manual_retain).

changelog: [manual_retain]: update for lint `binary_heap`
2023-08-13 14:45:01 +00:00
bors
83afad4cf1 Auto merge of #11333 - Alexendoo:uitest-default-check, r=flip1995
Do not bless by default in ui tests

This restores the default behaviour to check the `.stderr`, it was changed in #11239 to bless by default in `cargo test` (unless in github actions), but check by default in `cargo uitest` which is fairly confusing

It also meant `cargo uitest -F internal` no longer worked

`--bless` prevents the use of `Args::test` but we can look at reintegrating with that after `@oli-obk's` vacation

r? `@flip1995`

changelog: none
2023-08-13 14:33:45 +00:00
unvalley
1eff39ddb6 fix: change msrv to 1.69 for binary heap 2023-08-13 22:52:06 +09:00
Alex Macleod
3ac06a12a5 Do not bless by default in ui tests 2023-08-13 13:25:48 +00:00
unvalley
d5dbee4aa0 feat: update manual_retain to lint binary_heap_retain
refactor: rename variable

chore: reorder

test: update naming for msrv
2023-08-13 17:09:39 +09:00
Samuel Tardieu
f9b22e7b84 [new_without_default]: make the suggestion machine-applicable
Now that generics and lifetimes are output as expected, the lint
should be applicable.
2023-08-11 21:16:56 +02:00
Samuel Tardieu
621e76d252 [new_without_default]: include where clauses in suggestion
Fix #11267
2023-08-11 21:10:18 +02:00
Samuel Tardieu
7a06d7ec51 [new_without_default]: lifetimes are included in output
The comment was likely obsolete.
2023-08-11 21:10:18 +02:00
bors
75370e0671 Auto merge of #11325 - oli-obk:SPEEDTEST, r=flip1995
Fix SPEEDTEST instructions and output

* `--nocapture` hasn't been needed anymore since forever (even before `ui_test`)
* the result was dividing by 1000 instead of the number of test runs, giving bogus (but still useful for the purpose) timing results.

changelog: fix SPEEDTEST instructions and output
2023-08-11 15:30:38 +00:00