Commit graph

9991 commits

Author SHA1 Message Date
Alex Macleod
d24f0d056f Don't lint needless_return in fns across a macro boundary 2023-07-17 14:03:00 +00:00
Alex Macleod
36f84a6176 Move tuple_array_conversions to nursery 2023-07-17 12:09:20 +00:00
Catherine
74a77047da Rewrite [tuple_array_conversions] 2023-07-17 05:36:50 -05:00
y21
c83d58f507 document that write!ing into a string never fails 2023-07-17 12:23:18 +02:00
y21
c3881569af new lint: format_collect 2023-07-17 12:13:34 +02:00
Philipp Krones
2feb9a582f Another fix for incorrect_impls 2023-07-17 10:22:49 +02:00
Philipp Krones
d6d530fd0b Merge commit 'd9c24d1b1ee61f276e550b967409c9f155eac4e3' into clippyup 2023-07-17 10:22:32 +02:00
Sylvestre Ledru
eaccc6d38f [semicolon_if_nothing_returned]: enable the autofix 2023-07-16 19:37:42 +02:00
Caio
1f82f6ddf3 [significant_drop_tightening] Fix #11160 2023-07-14 13:51:34 -03:00
Mahdi Dibaiee
fdb2e363d3 refactor(rustc_middle): Substs -> GenericArg 2023-07-14 13:27:35 +01:00
Philipp Krones
faa07d334a
Bump Clippy version -> 0.1.73 2023-07-14 13:36:23 +02:00
Philipp Krones
415fdb2d1a
Merge remote-tracking branch 'upstream/master' into rustup 2023-07-14 13:36:16 +02:00
bors
bafde54367 Auto merge of #11152 - Alexendoo:unnecessary-cast-applicability, r=Manishearth
Set `unnecessary_cast` suggestion to `MaybeIncorrect` for pointer casts

Closes #11113

changelog: none
2023-07-14 07:39:49 +00:00
Urgau
50da77521e Rename cast_ref_to_mut to invalid_reference_casting (clippy side) 2023-07-13 23:01:24 +02:00
syvb
8d258c1508 Add handling for None.unwrap_or(_else) 2023-07-13 13:05:49 -04:00
syvb
c2aaa622eb Fix ICE on None.unwrap_or_default() 2023-07-13 13:00:10 -04:00
Alex Macleod
ea36a9df75 Set unnecessary_cast suggestion to MaybeIncorrect for pointer casts
Removing casts may cause type inference to stop working which requires
manual intervention
2023-07-13 13:29:41 +00:00
bors
7ccf5d404b Auto merge of #11095 - Alexendoo:rustfmt-imports, r=Manishearth
Add `imports_granularity = "Module"` to rustfmt.toml

This lets rustfmt split/merge imports, `Module` seems to be the most common style in clippy

https://rust-lang.github.io/rustfmt/?version=v1.6.0&search=#imports_granularity

changelog: none

Almost all the updates other than the config file change are from `cargo dev fmt` or blessed tests, the exceptions being

- `tests/ui/single_component_path_imports.rs`
- `tests/ui/single_component_path_imports_nested_first.rs`
- `tests/ui/single_component_path_imports_self_after.rs`
- `tests/ui/single_component_path_imports_self_before.rs`
- `tests/ui/unsafe_removed_from_name.rs` (added a test with merged imports as a drive by)
- `tests/ui/wildcard_imports.rs`
- `tests/ui/wildcard_imports_2021.rs`
2023-07-13 12:54:52 +00:00
Alex Macleod
2811effe34 Add imports_granularity = "Module" to rustfmt.toml 2023-07-13 12:44:57 +00:00
bors
a0e825786b Auto merge of #11147 - y21:issue11145, r=Alexendoo
[`arithmetic_side_effect`]: allow different types on the right hand side for `Wrapping<T>`

Fixes #11145

This lint has a list of allowed types, one of which is `Wrapping<T>`, but it was only actually allowed if the type on the right hand side was also `Wrapping<T>`, which meant that, for example, `Wrapping<u32> += u32` would still lint. It now allows binary ops involving `Wrapping<T>` regardless of the type on the rhs.
These impls have only existed since Rust 1.60.0, so that is probably why the lint was previously not handling this correctly

changelog: [`arithmetic_side_effect`]: allow different types on the right hand side for `Wrapping<T>` (e.g. `Wrapping<T> += T`)
2023-07-13 12:28:52 +00:00
bors
631faa1bc7 Auto merge of #11146 - hydro-project:tuple-array-conversions, r=Centri3,xFrednet
[`tuple_array_conversions`]: move from `complexity` to `nursery`

The lint suggestion is arguably often less readable and more complex than the original code.

For example, which of the following is the most readable:
```rust
let _vertices = edges.flat_map(|(src, dst)| [src, dst]);
let _vertices = edges.flat_map(<_ as Into<[i32; 2]>>::into);
let _vertices = edges.flat_map(<[i32; 2]>::from);
```

The lint can be useful, but really only applies if the tuple is either long enough that naming the fields is silly (maybe at least 4 entries long), or if the author intends the fields to be homogenous, which is author intent and can't be determined by the lint. Therefore I think the lint should be marked as pedantic.

Currently, there are also a lot of false positives with the lint:
* https://github.com/rust-lang/rust-clippy/issues/11082
* https://github.com/rust-lang/rust-clippy/issues/11085
* https://github.com/rust-lang/rust-clippy/issues/11100 (https://github.com/rust-lang/rust-clippy/pull/11105)
* https://github.com/rust-lang/rust-clippy/issues/11124
* https://github.com/rust-lang/rust-clippy/issues/11144

Should fix those issues before enabling it for everyone.

---

changelog: Move [`tuple_array_conversions`] to `nursery` (Now allow-by-default)
<!-- FIY: Ignore this change, if the commit gets backported -->
[#11146](https://github.com/rust-lang/rust-clippy/pull/11146)
2023-07-13 08:39:33 +00:00
Catherine
2e43d0c917 Improve suggestion and add more tests 2023-07-12 19:54:55 -05:00
Catherine
885ce610fe New lint [four_forward_slashes]
Make it trim the contents
2023-07-12 19:39:24 -05:00
Samuel Moelius
050b714c9d Add "Known problems" section to needless_borrow documentation 2023-07-12 20:15:54 -04:00
bors
df92b5284e Auto merge of #11123 - panosfol:master, r=giraffate
[`panic_in_result_fn`] remove `todo!`, `unimplemented!`, `unreachable!`

This commit fixes #11025 by removing checks for `todo!`, `unimplemented!` and `unreachable!`.

changelog: [`panic_in_result_fn`] remove `todo!`, `unimplemented!`, `unreachable!`
2023-07-12 23:57:29 +00:00
bors
d398e59163 Auto merge of #11138 - xFrednet:changelog-1-71, r=flip1995
Changelog for Rust 1.71 👑

Roses are red,
violets are blue,
new format is tried,
it's way less of a fight

---

Hey `@rust-lang/clippy,` `@blyxyas,` and `@Centri3,` I've tried the "new"/minimal changelog format we discussed a few meetings ago. I like it, and the writing process was also way quicker.

[🖼️ Rendered 🖼️](https://github.com/xFrednet/rust-clippy/blob/changelog-1-71/CHANGELOG.md#rust-171)

Furthermore, a big thank you to `@blyxyas` and `@Alexendoo` for updating the script that fetches the PR commits and adding links to the config values to the changelog. ❤️

---

changelog: none
2023-07-12 22:35:22 +00:00
Mingwei Samuel
4102a309d7 [tuple_array_conversions]: move from complexity to nursery
Due to outstanding issues:
* https://github.com/rust-lang/rust-clippy/issues/11082
* https://github.com/rust-lang/rust-clippy/issues/11085
* https://github.com/rust-lang/rust-clippy/issues/11100 (https://github.com/rust-lang/rust-clippy/pull/11105)
* https://github.com/rust-lang/rust-clippy/issues/11124
* https://github.com/rust-lang/rust-clippy/issues/11144
2023-07-12 15:28:46 -07:00
y21
c5fc61ca94 [arithmetic_side_effect]: allow different rhs type 2023-07-13 00:24:10 +02:00
Panagiotis Foliadis
c49c177e06 [panic_in_result_fn] remove todo!, unimplemented!, unreachable!
This commit fixes #11025 by removing checks for `todo!`,
`unimplemented!` and `unreachable!`.

Signed-off-by: Panagiotis Foliadis <pfoliadis@hotmail.com>
2023-07-12 22:19:01 +03:00
xFrednet
31397b489a
Update version attribute for 1.71 lints 2023-07-11 19:23:42 +02:00
bors
a8939e5eae Auto merge of #111717 - Urgau:uplift_fn_null_check, r=oli-obk
Uplift `clippy::fn_null_check` lint

This PR aims at uplifting the `clippy::fn_null_check` lint into rustc.

## `incorrect_fn_null_checks`

(warn-by-default)

The `incorrect_fn_null_checks` lint checks for expression that checks if a function pointer is null.

### Example

```rust
let fn_ptr: fn() = /* somehow obtained nullable function pointer */

if (fn_ptr as *const ()).is_null() { /* ... */ }
```

### Explanation

Function pointers are assumed to be non-null, checking for their nullity is incorrect.

-----

Mostly followed the instructions for uplifting a clippy lint described here: https://github.com/rust-lang/rust/pull/99696#pullrequestreview-1134072751

`@rustbot` label: +I-lang-nominated
r? compiler
2023-07-11 09:34:48 +00:00
y21
0b5dac0975 [unnecessary_literal_unwrap]: also handle unwrap_err_unchecked 2023-07-11 08:41:36 +02:00
y21
cd1c8532e9 [unnecessary_literal_unwrap]: lint unwrap_unchecked 2023-07-11 08:38:15 +02:00
Urgau
103949b241 Drop uplifted clippy::fn_null_check 2023-07-10 18:12:41 +02:00
bors
3be3fb7231 Auto merge of #11016 - y21:issue10029, r=blyxyas,dswij
[`filter_next`]: suggest making binding mutable if it needs to be

Fixes #10029

changelog: [`filter_next`]: suggest making binding mutable if it needs to be and adjust applicability
2023-07-10 10:47:37 +00:00
bors
9ab7137686 Auto merge of #11133 - GuillaumeGomez:fix-description-typo, r=Manishearth
Fix typo in `needless_pass_by_ref_mut` lint description

Someone nicely showed me that I made a small typo in https://github.com/rust-lang/rust-clippy/pull/10900.

changelog: none
2023-07-10 09:45:22 +00:00
y21
23ac72316d adjust applicability and suggest making binding mutable 2023-07-10 11:24:16 +02:00
Guillaume Gomez
d1575d1f54 changelog: Fix typo in needless_pass_by_ref_mut lint description 2023-07-10 10:27:23 +02:00
bors
9058b040c8 Auto merge of #11096 - y21:issue11091, r=giraffate
[`manual_range_patterns`]: lint negative values

Fixes #11091.

Now also lints negative values in patterns (`-1 | -2 | -3`)

changelog: [`manual_range_patterns`]: lint negative values
2023-07-10 00:04:08 +00:00
bors
507d1c282e Auto merge of #11110 - y21:unnecessary_literal_unwrap_ignore_expn, r=Jarcho
[`unnecessary_literal_unwrap`]: don't lint if binding initializer comes from expansion

Fixes https://github.com/rust-lang/rust-clippy/discussions/11109

changelog: [`unnecessary_literal_unwrap`]: don't lint if binding initializer comes from expansion
2023-07-09 20:09:22 +00:00
bors
ebd8d31542 Auto merge of #11055 - smoelius:try-this, r=dswij
"try this" -> "try"

Current help messages contain a mix of "try", "try this", and one "try this instead". In the spirit of #10631, this PR adopts the first, as it is the most concise.

It also updates the `lint_message_conventions` test to catch cases of "try this".

(Aside: #10120 unfairly contained multiple changes in one PR. I am trying to break that PR up into smaller pieces.)

changelog: Make help messages more concise ("try this" -> "try").
2023-07-09 15:07:25 +00:00
bors
b46033e9ce Auto merge of #10900 - GuillaumeGomez:needless-pass-by-ref, r=llogiq
Add `needless_pass_by_ref_mut` lint

changelog: [`needless_pass_by_ref_mut`]: This PR add a new lint `needless_pass_by_ref_mut` which emits a warning in case a `&mut` function argument isn't used mutably. It doesn't warn on trait and trait impls functions.

Fixes #8863.
2023-07-09 14:25:10 +00:00
Samuel Moelius
3bf2138289 Fix #10535 2023-07-08 19:12:10 -04:00
bors
6ae065ffd6 Auto merge of #11129 - c410-f3r:lock-1, r=Manishearth
[significant_drop_tightening] Fix #11128

Fix #11128

```
changelog: [`significant_drop_tightening`]: Consider manual alias of the `drop` function.
```
2023-07-08 21:10:43 +00:00
Caio
6384221910 Dogfood 2023-07-08 18:08:48 -03:00
Caio
2be695bf29 [significant_drop_tightening] Fix #11128 2023-07-08 17:43:34 -03:00
bors
8e261c09bb Auto merge of #11049 - Centri3:manual_is_infinite, r=blyxyas,xFrednet
New lints [`manual_is_infinite`] and [`manual_is_finite`]

Closes #9665

changelog: New lints [`manual_is_infinite`] and [`manual_is_finite`]
[#11049](https://github.com/rust-lang/rust-clippy/pull/11049)
2023-07-08 18:45:35 +00:00
Catherine
41438c2b90 Refactor, remove Constant::to_bits 2023-07-08 13:17:35 -05:00
Catherine
a5dfb68491 refactor 2023-07-08 13:11:56 -05:00
Centri3
844afbfeba use other instead of self 2023-07-08 13:02:54 -05:00
Centri3
004e89d4cf rename to manual_partial_ord_and_ord_impl
cargo dev fmt

cargo test passes

cargo test passes

refactor a lil

Update bool_comparison.stderr

heavily refactor + bump `clippy::version`

refactor

refactor

check bounds to increase accuracy, and add todos
2023-07-08 13:02:54 -05:00
Centri3
2a1fd22f81 implement manual_partial_ord_impl
first try at this
2023-07-08 13:02:38 -05:00
bors
1816caaa76 Auto merge of #113376 - Nilstrieb:pointer-coercions-are-not-casts-because-that-sounds-way-to-general-aaaa, r=oli-obk
Rename `adjustment::PointerCast` and variants using it to `PointerCoercion`

It makes it sounds like the `ExprKind` and `Rvalue` are supposed to represent all pointer related casts, when in reality their just used to share a little enum variants. Make it clear there these are only coercions and that people who see this and think "why are so many pointer related casts not in these variants" aren't insane.

This enum was added in #59987. I'm not sure whether the variant sharing is actually worth it, but this at least makes it less confusing.

r? oli-obk
2023-07-08 13:48:30 +00:00
Nilstrieb
5df1f6681d Pass correct substs to implements_trait in incorrect_impls
`Copy<T>` does in fact not exist. The substs on the trait_ref contain
the `Self` type of the impl as the first parameter, so passing that
to `implements_trait`, which then nicely prepends the `Self` type
for us does not end will.
2023-07-07 20:28:51 +02:00
Alex Macleod
87373d7f52 Fix failing clippy tests
Comments out the C string literals due to https://github.com/rust-lang/rust/pull/113334

Fixes https://github.com/rust-lang/rust-clippy/issues/11121
2023-07-07 18:19:08 +00:00
Nilstrieb
b5ac726ed3 Rename adjustment::PointerCast and variants using it to PointerCoercion
It makes it sound like the `ExprKind` and `Rvalue` are supposed to represent all pointer related
casts, when in reality their just used to share a some enum variants. Make it clear there these
are only coercion to make it clear why only some pointer related "casts" are in the enum.
2023-07-07 18:17:16 +02:00
y21
c927912c5b [manual_range_patterns]: document what range we don't lint 2023-07-07 17:25:28 +02:00
y21
5cc0c04826 [manual_range_patterns]: lint negative values 2023-07-07 17:25:28 +02:00
Alex Macleod
4939a716e8 arc_with_non_send_sync: reword and move to suspicious 2023-07-07 12:02:05 +00:00
Catherine
5949f762bf Make suggestion give multiple alternatives 2023-07-06 20:27:21 -05:00
Catherine
f12edfdb53 manual_float_methods 2023-07-06 20:27:21 -05:00
bors
dd8e44c5a2 Auto merge of #11111 - Alexendoo:regex-def-paths, r=giraffate
Fix regex lints for regex 1.9.0

regex 1.9.0 was [just released](https://blog.burntsushi.net/regex-internals/), which changes where the types are defined. Instead of updating the definitions to the ones in 1.9.0 this PR uses [`def_path_def_ids`](https://doc.rust-lang.org/nightly/nightly-rustc/clippy_utils/fn.def_path_def_ids.html) on the canonical paths so that we don't have to worry about third party crate internals

This means that it still works with older regex versions too, and will for any future layout changes. I tested it with 1.8.4 and 1.9.0

changelog: [`INVALID_REGEX`], [`TRIVIAL_REGEX`]: now works with regex 1.9.0
2023-07-06 23:40:33 +00:00
Boxy
cbe468222a Move TyCtxt::mk_x to Ty::new_x where applicable 2023-07-05 20:27:07 +01:00
Alex Macleod
f945351170 Fix regex lints for regex 1.9.0 2023-07-05 18:29:43 +00:00
y21
6868c0a74b [unnecessary_literal_unwrap]: don't lint if binding initializer is expn 2023-07-05 13:03:34 +02:00
bors
1e656d8d6d Auto merge of #10970 - y21:read_line_without_trim, r=giraffate
new lint: `read_line_without_trim`

This adds a new lint that checks for calls to `Stdin::read_line` with a reference to a string that is then attempted to parse into an integer type without first trimming it, which is always going to fail at runtime.
This is something that I've seen happen a lot to beginners, because it's easy to run into when following the example of chapter 2 in the book where it shows how to program a guessing game.
It would be nice if we could point beginners to clippy and tell them "let's see what clippy has to say" and have clippy explain to them why it fails 👀

I think this lint can later be "generalized" to work not just for `Stdin` but also any `BufRead` (which seems to be where the guarantee about the trailing newline comes from) and also, matching/comparing it to a string slice that doesn't end in a newline character (e.g. `input == "foo"` is always going to fail)

changelog: new lint: [`read_line_without_trim`]
2023-07-05 00:13:59 +00:00
Guillaume Gomez
f048f73251 Add warning about semver compatibility if it's a public function 2023-07-04 20:35:23 +02:00
bors
3f4e5999b2 Auto merge of #11094 - y21:issue11084, r=Alexendoo
[`useless_vec`]: add more tests and don't lint inside of macros

Closes #11084.

I realized that the fix I added in #11081 itself also causes an error in a suggestion when inside of a macro. Example:
```rs
macro_rules! x {
  () => {
    for _ in vec![1, 2] {}
  }
}
x!();
```
Here it would suggest replacing `vec![1, 2]` with `[x!()]`, because that's what the source callsite is (reminder: it does this to get the correct span of `x!()` for code like `for _ in vec![x!()]`), but that's wrong when *inside* macros, so I decided to make it not lint if the whole loop construct is inside a macro to avoid this issue.

changelog: [`useless_vec`]: add more tests and don't lint inside of macros

r? `@Alexendoo` since these were your tests, I figured it makes most sense to assign you
2023-07-03 21:07:44 +00:00
y21
8fad54e8f9 new lint: read_line_without_trim 2023-07-03 22:51:38 +02:00
Guillaume Gomez
33adfcd327 Add warning for NEEDLESS_PASS_BY_REF_MUT lint about the fact that it changes API 2023-07-03 22:48:40 +02:00
Guillaume Gomez
dd3e00f102 Fix warnings of needless_pass_by_ref_mut in clippy 2023-07-03 22:25:36 +02:00
Guillaume Gomez
b41fc6784f Add needless_pass_by_ref lint 2023-07-03 22:25:36 +02:00
y21
b4549c50b5 [useless_vec]: add more tests for macro combinations 2023-07-03 19:48:27 +02:00
bors
ba3bd8f0f1 Auto merge of #11078 - Centri3:11068, r=llogiq
[`needless_raw_string_hashes`]: Only reset hashes needed if not following quote

Fixes #11068

changelog: none
2023-07-03 17:01:27 +00:00
bors
3f17c5c388 Auto merge of #10924 - est31:manual_let_else_question_mark, r=Centri3,flip1995,Manishearth
Don't lint manual_let_else in cases where ? would work

Don't lint `manual_let_else` where the question mark operator `?` would be sufficient, that is, mostly in cases like:

```Rust
let v = if let Some(v) = ex { v } else { return None };
```

Also, this PR emits the `question_mark` lint for `let...else` patterns that could be written with `?` (also, only `return None` like cases).

```
changelog: [`manual_let_else`]: don't lint in cases where question_mark already lints
changelog: [`question_mark`]: lint for `let Some(...) = ex else { return None };`
```

Fixes  #8755
2023-07-03 14:18:32 +00:00
bors
a959061763 Auto merge of #11081 - y21:issue11075, r=Manishearth
[`useless_vec`]: use the source span for initializer

Fixes #11075.

changelog: [`useless_vec`]: use the source span for the initializer expression when inside of a macro
2023-07-03 12:08:36 +00:00
y21
1f77f8cc3c [useless_vec]: use the source span 2023-07-03 13:40:33 +02:00
Catherine
9a581077d4 Fix FP [needless_raw_string_hashes] 2023-07-03 06:35:04 -05:00
bors
2b03bb08b2 Auto merge of #11077 - y21:issue11076, r=Manishearth
[`arc_with_non_send_sync`]: don't lint if type has nested type parameters

Fixes #11076

changelog: [`arc_with_non_send_sync`]: don't lint if type has nested type parameters

r? `@Manishearth`
2023-07-03 09:48:05 +00:00
y21
75c339cd0a [arc_with_non_send_sync]: look for nested type parameters 2023-07-03 11:35:25 +02:00
est31
d80581c7d2 Move pat_and_expr_can_be_question_mark into clippy_utils 2023-07-03 09:42:54 +02:00
est31
6990eaa972 Don't suppress manual_let_else if question_mark is allowed
If question_mark is allowed, there is no overlap any more,
so we can just not suppress it.
2023-07-03 09:42:54 +02:00
bors
c46ddeb9e1 Auto merge of #10987 - y21:type_id_on_box, r=llogiq
new lint: `type_id_on_box`

Closes #7687.

A new lint that detects calling `.type_id()` on `Box<dyn Any>` (and not on the underlying `dyn Any`), which can make up for some pretty confusing bugs!

changelog: new lint: [`type_id_on_box`]
2023-07-03 06:16:14 +00:00
bors
4752466c8e Auto merge of #11069 - y21:issue11063, r=Alexendoo
[`missing_fields_in_debug`]: make sure self type is an adt

Fixes #11063, another ICE that can only happen in core.

This lint needs the `DefId` of the implementor to get its fields, but that ICEs if the implementor does not have a `DefId` (as is the case with primitive types, e.g. `impl Debug for bool`), which is where this ICE comes from.

This PR changes the check I added in #10897 to be more... robust against `Debug` implementations we don't want to lint.
Instead of just checking if the self type is a type parameter and "special casing" one specific case we don't want to lint, we should probably rather just check that the self type is either a struct, an enum or a union and only then continue.
That prevents weird edge cases like this one that can only happen in core.

Again, I don't know if it's even possible to add a test case for this since one cannot implement `Debug` for primitive types outside of the crate that defined `Debug` (core).
I did make sure that this PR no longer ICEs on `impl<T> Debug for T` and `impl Debug for bool`.
Maybe writing such a test is possible with `#![no_core]` and then re-defining the `Debug` trait or something like that...?

changelog: [`missing_fields_in_debug`]: make sure self type is an adt (fixes an ICE in core)

r? `@Alexendoo` (reviewed the last PRs for this lint)
2023-07-02 21:12:10 +00:00
y21
555ceb83fe [missing_fields_in_debug]: make sure self is an adt 2023-07-02 21:42:39 +02:00
bors
83d0682d5e Auto merge of #11061 - Alexendoo:let-and-return-closures, r=llogiq
`let_and_return`: lint 'static lifetimes, don't lint borrows in closures

Fixes #11056

Now also ignores functions returning `'static` lifetimes, since I noticed the `stdin.lock()` example was still being linted but doesn't need to be since https://github.com/rust-lang/rust/pull/93965

changelog: none
2023-07-02 15:14:46 +00:00
Alex Macleod
e29a5acf6f let_and_return: lint 'static lifetimes, don't lint borrows in closures 2023-07-02 14:25:40 +00:00
Philipp Krones
cb3ecf7b79 Merge commit '37f4c1725d3fd7e9c3ffd8783246bc5589debc53' into clippyup 2023-07-02 14:59:02 +02:00
bors
1990b72e8a Auto merge of #11058 - Centri3:typos, r=xFrednet
Fix typos

Just a couple misc typos I found

changelog: none
2023-07-02 12:11:30 +00:00
Catherine
885a18207f Fix typos 2023-07-02 07:11:05 -05:00
bors
bb33e0343f Auto merge of #112718 - oli-obk:SIMD-destructure_mir_const, r=cjgillot
Make simd_shuffle_indices use valtrees

This removes the second-to-last user of the `destructure_mir_constant` query. So in a follow-up we can remove the query and just move the query provider function directly into pretty printing (which is the last user).

cc `@rust-lang/clippy` there's a small functional change, but I think it is correct?
2023-07-02 07:43:36 +00:00
Catherine
cb5d7e344a address comments 2023-07-01 12:37:16 -05:00
Catherine
fbb3f759e2 update docs 2023-07-01 12:36:02 -05:00
Catherine
04b0857691 Typo 2023-07-01 12:36:02 -05:00
Catherine
354172a18e New lint manual_try_fold 2023-07-01 12:36:02 -05:00
bors
c7bf05c1a4 Auto merge of #11020 - Centri3:tuple_array_conversion, r=llogiq
New lint [`tuple_array_conversions`]

Closes #10748

PS, the implementation is a bit ugly 😅 ~~I will likely refactor soon enough :)~~ Done :D

changelog: New lint [`tuple_array_conversions`]
2023-07-01 15:27:35 +00:00
Samuel Moelius
420f3d11e8 "try this" -> "try" 2023-07-01 07:08:01 -04:00
est31
20dfaba035 Put into one pass 2023-06-30 19:47:22 +02:00
Catherine
efac83813d Make eq_op suggest .is_nan() 2023-06-30 11:43:02 -05:00
est31
c6be62159f Fix the now stricter lint in manual_rem_euclid.rs 2023-06-30 18:01:28 +02:00
est31
86391abc70 Don't lint manual_let_else in cases where the question mark operator would work
Also, lint question_mark for `let...else` clauses that can be simplified to use `?`.
This lint isn't perfect as it doesn't support the unstable try blocks.
2023-06-30 18:01:27 +02:00
bors
2c40b99d08 Auto merge of #11048 - flip1995:rustup, r=flip1995
Rustup

r? `@ghost`

changelog: none
2023-06-30 14:09:53 +00:00
Philipp Krones
8010c3462d
Merge remote-tracking branch 'upstream/master' into rustup 2023-06-30 16:09:06 +02:00
y21
648d1ae8e0 lint on matches and pattern matching 2023-06-30 14:54:49 +02:00
bors
73f14176e3 Auto merge of #10774 - c410-f3r:lock-1, r=Jarcho
[significant_drop_tightening] Fix #10413

Fix #10413

This is quite a rewrite that unfortunately took a  large amount of time. I tried my best to comment what is going on to easy review but feel free to ask any question.

The problem basically is that the current algorithm is only taking into consideration single blocks which means that things like the following don't work or show unpredictable results.

```rust
let mutex = Mutex::new(1);
{
  let lock = mutex.lock().unwrap();
  {
    let _ = *lock;
  }
}
```

The solve the issue, each path that refers a lock is now being tracked individually.

```
changelog: [`significant_drop_tightening`]: Lift the restriction of only considerate single blocks
```
2023-06-30 02:51:15 +00:00
bors
3d4c536e87 Auto merge of #11013 - Centri3:redundant_rest_pattern, r=giraffate
New lint [`redundant_at_rest_pattern`]

Closes #11011

It's always a great feeling when a new lint triggers on clippy itself 😄

changelog: New lint [`redundant_at_rest_pattern`]
2023-06-29 23:54:35 +00:00
Caio
fc832f0eb7 Dogfood 2023-06-29 09:30:04 -03:00
Caio
f0619024b8 Fix #10413 2023-06-29 09:27:49 -03:00
Catherine
826edd75ef heavily refactor 2023-06-29 06:46:28 -05:00
Catherine
95b24d44a6 Fix FP 2023-06-29 06:46:28 -05:00
Catherine
b1acbde618 Add msrv check and make test pass 2023-06-29 06:46:28 -05:00
Catherine
bfcc8ba444 New lint tuple_array_conversions 2023-06-29 06:46:00 -05:00
bors
9020937bbe Auto merge of #11030 - darklyspaced:master, r=Centri3,xFrednet
suggests `is_some_and` over `map().unwrap`

changelog: Enhancement: [`option_map_unwrap_or`] now considers the [`msrv`] config when creating the suggestion.

 * modified option_map_unwrap_or lint to recognise when an `Option<T>` is mapped to an `Option<bool>` with false being used when `None` is detected; suggests the use of `is_some_and` instead
 * msrv is set to 1.70.0 for this lint; when `is_some_and` was stabilised

fixes #9125
2023-06-29 09:54:51 +00:00
darklyspaced
211278bc86
updated list of lints that use msrv 2023-06-29 10:18:38 +08:00
bors
10ce1a6d5e Auto merge of #11001 - y21:issue8628, r=Jarcho
[`question_mark`]: don't lint inside of `try` block

Fixes #8628.

Diff looks a bit noisy because I had to move the two functions into an impl, because they now need to access the structs `try_block_depth` field to see if they're inside a try block.

changelog: [`question_mark`]: don't lint inside of `try` block
2023-06-28 18:38:44 +00:00
bors
ea4c5c5ca5 Auto merge of #11035 - y21:issue10729, r=Jarcho
[`option_if_let_else`]: suggest `.as_ref()` if scrutinee is of type `&Option<_>`

Fixes #10729

`Option::map_or` takes ownership, so if matching on an `&Option<_>`, we need to suggest `.as_ref()` before calling `map_or` to get the same effect and to not cause a borrowck error.

changelog: [`option_if_let_else`]: suggest `.as_ref()`/`.as_mut()` if scrutinee is of type `&Option<_>`/`&mut Option<_>`
2023-06-28 15:39:04 +00:00
y21
70610c0018 lint in nested bodies if try is in outer body 2023-06-28 12:41:18 +02:00
bors
750c7a11da Auto merge of #11042 - y21:issue10459, r=Manishearth
[`unused_async`]: don't lint if function is part of a trait

Fixes #10459.

We shouldn't lint if the function is part of a trait, because the user won't be able to easily remove the `async`, as this will then not match with the function signature in the trait definition

changelog: [`unused_async`]: don't lint if function is part of a trait
2023-06-28 09:54:20 +00:00
y21
b713cd5945 move is_in_trait_method to utils and rename 2023-06-28 11:35:10 +02:00
Catherine
46aa8abf08 Change category and update to ui_test 2023-06-28 03:20:21 -05:00
Centri3
8296a338db new lints for visibility 2023-06-28 03:20:21 -05:00
Catherine
3376c714ee Add note to remove if statement altogether 2023-06-27 20:10:31 -05:00
y21
b592d39968 manual_range_pattern -> manual_range_patterns 2023-06-27 22:35:54 +02:00
y21
1d4afc5d82 new lint: manual_range_pattern 2023-06-27 22:34:31 +02:00
y21
a43bfefd19 [unused_async]: don't lint on async trait impls 2023-06-27 22:30:38 +02:00
Catherine
e9ced12512 Rename the lint 2023-06-27 06:31:04 -05:00
Catherine
9a8347ded5 New lint [redundant_rest_pattern] 2023-06-27 06:06:56 -05:00
Centri3
8cb6c86996 change category and refactor
Update raw_strings.rs

Revert "new lints for visibility"

This reverts commit 0e5a537d209727169769dc19cf86aef27122c092.

new lints for visibility
2023-06-27 05:16:40 -05:00
Centri3
cb52d19ce1 don't lint needless_raw_string_hashes when it's unnecessary 2023-06-27 05:12:00 -05:00
Catherine
ec765d9516 Update raw_strings.rs 2023-06-27 05:12:00 -05:00
Centri3
bc744eb82b new lint needless_raw_string + refactor a bit
Thanks, #112373, for the snippet at line 75!
2023-06-27 05:12:00 -05:00
Centri3
1bf74fc303 add needless_raw_string_hashes lint
add semicolon in doctest
2023-06-27 05:12:00 -05:00
darklyspaced
a693cbc1bc
changed msrv name for consistency & changed nested if for style 2023-06-27 11:29:02 +08:00
darklyspaced
ca00b138b2
ignore too_many_arguments on check 2023-06-27 11:29:02 +08:00
darklyspaced
c378bf9ddf
Revert "now passes dogfood by wrapping unwrap_recv and unwrap_arg into a tuple"
This reverts commit 7b91844a3207d90d4200a7b53d0ae1a7a1dca73a.
2023-06-27 11:29:02 +08:00
darklyspaced
b832175b2d
now passes dogfood by wrapping unwrap_recv and unwrap_arg into a tuple
was previously failing due to `check` having to many arguments.
2023-06-27 11:29:02 +08:00
darklyspaced
c60222dc12
changed the msrv to 1.70 to suggest is_some_and
if the msrv is not >= 1.70 then the `map_or` is suggested instead of `is_some_and` (even when `unwrap_or` returns false)
2023-06-27 11:29:02 +08:00
darklyspaced
9b7d8d1dc7
suggests is_some_and over map().unwrap_or(false) 2023-06-27 11:29:02 +08:00
Michael Goulet
716c552632 Migrate predicates_of and caller_bounds to Clause 2023-06-26 23:12:03 +00:00
Catherine
d29506794e Don't lint code from external macros 2023-06-26 15:10:06 -05:00
y21
733a9ea6b9 [option_if_let_else]: suggest .as_ref() if &Option<_> 2023-06-26 20:13:06 +02:00
bors
a9e0bbb931 Auto merge of #112887 - WaffleLapkin:become_unuwuable_in_hir, r=compiler-errors,Nilstrieb
`hir`: Add `Become` expression kind (explicit tail calls experiment)

This adds `hir::ExprKind::Become` alongside ast lowering. During hir-thir lowering we currently lower `become` as `return`, so that we can partially test `become` without ICEing.

cc `@scottmcm`
r? `@Nilstrieb`
2023-06-26 13:51:04 +00:00
Oli Scherer
7bd8ab77e5 Make simd_shuffle_indices use valtrees 2023-06-26 09:34:52 +00:00
Maybe Waffle
555bd985d2 Support hir::ExprKind::Become in clippy 2023-06-26 08:56:32 +00:00
bors
407bfd483a Auto merge of #11005 - Centri3:never_loop, r=giraffate
Check if `if` conditions always evaluate to true in `never_loop`

This fixes the example provided in #11004, but it shouldn't be closed as this is still an issue on like
```rust
let x = true;
if x { /* etc */ }`
```
This also makes `clippy_utils::consts::constant` handle `ConstBlock` and `DropTemps`.

changelog: [`never_loop`]: Check if `if` conditions always evaluate to true
2023-06-26 00:42:38 +00:00
bors
78e36d9f53 Auto merge of #10996 - Centri3:mem_forget, r=xFrednet
Lint `mem_forget` if any fields are `Drop`

Closes #9298
I think this way of doing it (`needs_drop`) should be fine.

---

changelog: Enhancement: [`mem_forget`]: Now lints on types with fields that implement `Drop`
[#10996](https://github.com/rust-lang/rust-clippy/pull/10996)
2023-06-25 09:40:13 +00:00
Catherine
a5ae9044fb make note less verbose 2023-06-25 04:28:40 -05:00
Renato Lochetti
f0eb40c981
Avoid linting on procedural macros 2023-06-24 19:45:16 -03:00
bors
1b4c423f30 Auto merge of #11021 - y21:issue9493, r=llogiq
[`format_push_string`]: look through `match` and `if` expressions

Closes #9493.

changelog: [`format_push_string`]: look through `match` and `if` expressions
2023-06-24 18:59:58 +00:00
y21
fe856d383f [format_push_string]: look through match, if, if-let 2023-06-24 19:54:12 +02:00
Catherine
db4efe3f6d Don't lint ptr_arg when return type uses Cow's lifetime 2023-06-24 03:26:40 -05:00
bors
ce0a48a9b6 Auto merge of #10994 - y21:issue8772, r=giraffate
[`type_repetition_in_bounds`]: respect MSRV for combining bounds

Fixes #8772.

changelog: [`type_repetition_in_bounds`]: respect msrv for combining `?Sized` bound
2023-06-23 00:31:04 +00:00
Michael Goulet
533a819115 Migrate item_bounds to ty::Clause 2023-06-22 18:34:23 +00:00
y21
33b6d0d206 rename MSRV alias, add MSRV to lint doc 2023-06-22 17:19:43 +02:00
Catherine
6a1084c26f Check if if conditions always evaluate to true in never_loop 2023-06-22 04:31:05 -05:00
bors
6ec23880f2 Auto merge of #10979 - y21:issue9909, r=giraffate
[`get_unwrap`]: include a borrow in the suggestion if argument is not an integer literal

Fixes #9909

I have to say, I don't really understand what the previous logic was trying to do, but this fixes the linked bug.
It was checking if the argument passed to `.get()` can be parsed as a usize (i.e. if it's an integer literal, probably?), and if not, it wouldn't include a borrow? I don't know how we came to that conclusion, but that logic doesn't work:
```rs
let slice = &[1, 2];
let _r: &i32 = slice.get({ 1 }).unwrap();
// previous suggestion: slice[{ 1 }]
// the suggestion should be: &slice[{ 1 }]
```
Here the argument passed to it isn't an integer literal, but it should still include a borrow, because it would otherwise change the type from `&i32` to `i32`.

The exception is that if the parent of the `get().unwrap()` expr is a dereference or a method call or the like, we don't need an explicit borrow because it's automatically inserted by the compiler

changelog: [`get_unwrap`]: include a borrow in the suggestion if argument is not an integer literal
2023-06-21 23:57:02 +00:00
bors
9fa4089410 Auto merge of #10993 - Centri3:iter_nth_zero, r=Manishearth
Don't lint [`iter_nth_zero`] in `next`

Closes #9820
This also *slightlyy* modifies the output of `iter_nth`, as I noticed the types' names weren't in backticks

changelog: [`iter_nth_zero`]: No longer lints in implementations of `Iterator::next`
2023-06-21 22:06:12 +00:00
Centri3
242807a9c1 Don't lint iter_nth_zero in next 2023-06-21 15:58:52 -05:00
Catherine
b6f194b48c move to drop_forget_ref 2023-06-21 15:56:24 -05:00
bors
b3fd7b8120 Auto merge of #10948 - Centri3:borrow_as_ptr, r=dswij
[`borrow_as_ptr`]: Ignore temporaries

Fixes #9884

changelog: [`borrow_as_ptr`]: Ignore temporaries
2023-06-21 17:07:52 +00:00
y21
716305d4b6 [question_mark]: don't lint inside of try block 2023-06-21 16:39:46 +02:00
bors
a2b99d8174 Auto merge of #112877 - Nilstrieb:rollup-5g5hegl, r=Nilstrieb
Rollup of 6 pull requests

Successful merges:

 - #112632 (Implement PartialOrd for `Vec`s over different allocators)
 - #112759 (Make closure_saved_names_of_captured_variables a query. )
 - #112772 (Add a fully fledged `Clause` type, rename old `Clause` to `ClauseKind`)
 - #112790 (Syntactically accept `become` expressions (explicit tail calls experiment))
 - #112830 (More codegen cleanups)
 - #112844 (Add retag in MIR transform: `Adt` for `Unique` may contain a reference)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-06-21 08:00:23 +00:00
y21
bdb2a17107 declare needs_ref later 2023-06-21 09:16:25 +02:00
y21
3122e3d78f use let chains, move assignments out of block, add tests 2023-06-21 09:04:40 +02:00
bors
70c2d0cfe5 Auto merge of #106450 - albertlarsan68:fix-arc-ptr-eq, r=Amanieu
Make `{Arc,Rc,Weak}::ptr_eq` ignore pointer metadata

FCP completed in https://github.com/rust-lang/rust/issues/103763#issuecomment-1362267967

Closes #103763
2023-06-21 05:13:39 +00:00
Catherine
e3b601a1aa Add WebAssembly to allowed idents 2023-06-20 18:12:20 -05:00
Catherine
d8d59965f1 Lint mem_forget if fields are Drop 2023-06-20 13:37:03 -05:00
y21
765a6e4a90 put issue link between <> 2023-06-20 17:36:38 +02:00
y21
1b6738ba39 s/is_dyn_trait/is_dyn_any 2023-06-20 17:33:32 +02:00
y21
87c28b9463 [type_repetition_in_bounds]: respect msrv for combining maybe bounds 2023-06-20 17:24:46 +02:00
bors
62972ae2dd Auto merge of #10952 - Centri3:excessive_precision, r=dswij
Don't lint `excessive_precision` on inf

Fixes #9910

changelog: [`excessive_precision`]: No longer lints overflowing literals
2023-06-20 14:56:21 +00:00
bors
5da6174318 Auto merge of #10990 - y21:issue8634-partial, r=blyxyas,xFrednet
[`single_match`]: don't lint if block contains comments

Fixes #8634

It now ignores matches with a comment in the "else" arm

changelog: [`single_match`]: don't lint if block contains comments
2023-06-20 13:57:19 +00:00
bors
8fd021f504 Auto merge of #10986 - Centri3:undocumented_unsafe_blocks, r=Manishearth
Allow safety comment above attributes

Closes #8679

changelog: Enhancement: [`undocumented_safety_block`]: Added `accept-comment-above-attributes` configuration.
2023-06-20 05:04:46 +00:00
Centri3
cc2e49f695 allow safety comment above attributes 2023-06-19 23:46:57 -05:00
bors
1919dff4ee Auto merge of #10989 - ericmarkmartin:use-placeref-abstraction, r=Manishearth
Use placeref abstraction

rust-lang/rust#80647 suggests refactoring certain patterns with MIR places to use higher-level abstractions provided by the [`Place`](https://doc.rust-lang.org/stable/nightly-rustc/rustc_middle/mir/struct.Place.html)/[`PlaceRef`](https://doc.rust-lang.org/stable/nightly-rustc/rustc_middle/mir/struct.PlaceRef.html). While working on that issue, I found a couple candidates for such refactoring in clippy.

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

changelog: none
2023-06-20 04:43:38 +00:00
bors
89294e1756 Auto merge of #10992 - blyxyas:fix-test_case_lib, r=Manishearth
`items_after_test_module`: Ignore in-proc-macros items

The library `test-case` is having some problems with this lint, ignoring proc macros should fix it.
Related to #10713 and frondeus/test-case#122

(Couldn't add test cases for this exact situation without importing the library, but I think the fix is simple enough that we can be pretty sure there won't be any problems :) )

changelog:[`items_after_test_module`]: Ignore items in procedural macros
2023-06-20 04:14:20 +00:00
bors
5b60388e5a Auto merge of #10930 - y21:issue9956, r=blyxyas,xFrednet
[`redundant_closure_call`]: handle nested closures

Fixes #9956.

This ended up being a much larger change than I'd thought, and I ended up having to pretty much rewrite it as a late lint pass, because it needs access to certain things that I don't think are available in early lint passes (e.g. getting the parent expr). I think this'll be required to fi-x #10922 anyway, so this is probably fine.
(edit: had to write "fi-x" because "fix" makes github think that this PR fixes it, which it doesn't 😅 )

Previously, it would suggest changing `(|| || 42)()()` to `|| 42()`, which is a type error (it needs parens: `(|| 42)()`). In my opinion, though, the suggested fix should have really been `42`, so that's what this PR changes.

changelog: [`redundant_closure_call`]: handle nested closures and rewrite as a late lint pass
2023-06-19 20:30:35 +00:00
bors
f396004b25 Auto merge of #10975 - hehaoqian:fix_self_named_module_files, r=Centri3,xFrednet
Fix false positive of [self_named_module_files] and [mod_module_files]

changelog: [self_named_module_files] [mod_module_files]: No longer lints dependencies located in subdirectory of workspace

fixes #8887

---

First time contributor here, just read contribution guide today.

I have several questions:

1. ~Is it the correct way to use environment variable `CARGO_HOME` to get the location of cargo home directory?~
(Edit: Code no longer uses CARGO_HOME)
2. How to setup test for this PR? This involves multiple files and `CARGO_HOME` setup. ~Not sure how to do this.~
~Edit: Working on tests right now~ A workspace_test has been added
2023-06-19 20:14:21 +00:00
bors
c8c03ea606 Auto merge of #10793 - c410-f3r:bbbbbbbbbbb, r=xFrednet
[`arithmetic_side_effects`] Fix #10792

Fix #10792

```
changelog: [`arithmetic_side_effects`]: Retrieve field values of structures that are in constant environments
```
2023-06-19 19:51:49 +00:00
blyxyas
62c9e0b87d
Ignore in-proc-macros items 2023-06-19 20:50:24 +02:00
y21
2e856fa99b add test for block comment and add note to description 2023-06-19 20:07:31 +02:00
y21
d7e723441e [single_match]: don't lint if block contains comments 2023-06-19 17:18:27 +02:00
Michael Goulet
b2c7ce8908 s/Clause/ClauseKind 2023-06-19 14:57:42 +00:00
Eric Mark Martin
66590ba41b use PlaceRef abstractions 2023-06-19 03:44:04 -04:00
hehaoqian
e11ebbd5e7 Move continue into if statement
Co-authored-by: Catherine <114838443+Centri3@users.noreply.github.com>
2023-06-19 08:36:27 +08:00
Centri3
2cd4a9182a Ignore functions annotated with #[test] 2023-06-18 19:32:38 -05:00
y21
26ac76c15f add it to the methods lint pass 2023-06-18 22:36:08 +02:00
y21
9ab1e8e95c that was definitely not the right version 2023-06-18 22:27:20 +02:00
y21
c5a9adc2be new lint: type_id_on_box 2023-06-18 22:20:10 +02:00
hehaoqian
65b93a5b43 Fix false positive of [self_named_module_files] and [mod_module_files] 2023-06-18 09:04:59 +08:00
Centri3
a8605269bd add test for closures 2023-06-17 20:01:15 -05:00
Centri3
07dbcbda12 new lint single_call_fn 2023-06-17 20:01:06 -05:00
Caio
0e1caa765e Fix #10792 2023-06-17 17:03:31 -03:00
y21
6331c943ff include a ref if argument is not just a numeric literal 2023-06-17 20:48:56 +02:00
bors
8c8ff5f31d Auto merge of #10976 - dswij:issue-10966, r=Alexendoo
Make [`missing_panics_doc`]  not lint for `todo!()`

closes #10966

changelog: [`missing_panics_doc`] now does not lint for `todo!()`
2023-06-17 16:40:39 +00:00
dswij
1f621af28c Exlude todo!() from missing_panics_in_doc 2023-06-17 23:20:33 +08:00
Renato Lochetti
e2e6a02445
Addressing reviewer comments 2023-06-17 09:36:38 -03:00
Renato Lochetti
520228b377
Adding configuration to allow safety comment above stmt containing unsafe block 2023-06-17 09:36:36 -03:00
Oli Scherer
5777494f99 Add AliasKind::Weak for type aliases.
Only use it when the type alias contains an opaque type.

Also does wf-checking on such type aliases.
2023-06-16 19:39:48 +00:00
bors
3217f8aeaa Auto merge of #10942 - Centri3:unnecessary_cast, r=llogiq
Ignore more type aliases in `unnecessary_cast`

This is potentially the worst code I've ever written, and even if not, it's very close to being on par with starb. This will ignore `call() as i32` and `local_obtained_from_call as i32` now.

This should fix every reasonable way to reproduce #10555, but likely not entirely.

changelog: Ignore more type aliases in `unnecessary_cast`
2023-06-16 19:24:11 +00:00