Commit graph

13089 commits

Author SHA1 Message Date
flip1995
646a9cf559
Bump nightly version -> 2021-12-17 2021-12-17 13:22:34 +01:00
flip1995
fad9407c5a
Merge remote-tracking branch 'upstream/master' into rustup 2021-12-17 13:22:25 +01:00
bors
40fd785199 Auto merge of #7978 - smoelius:master, r=llogiq
Add `unnecessary_to_owned` lint

This PR adds a lint to check for unnecessary calls to `ToOwned::to_owned` and other similar functions (e.g., `Cow::into_owned`, `ToString::to_string`, etc.).

The lint checks for expressions of the form `&receiver.to_owned_like()` used in a position requiring type `&T` where one of the following is true:
* `receiver`'s type is `T` exactly
* `receiver`'s type implements `Deref<Target = T>`
* `receiver`'s type implements `AsRef<T>`

The lint additionally checks for expressions of the form `receiver.to_owned_like()` used as arguments of type `impl AsRef<T>`.

It would be nice if the lint could also check for expressions used as arguments to functions like the following:
```
fn foo<T: AsRef<str>>(x: T) { ... }
```
However, I couldn't figure out how to determine whether a function input type was instantiated from a parameter with a trait bound.

If someone could offer me some guidance, I would be happy to add such functionality.

Closes #7933

changelog: Add [`unnecessary_to_owned`] lint
2021-12-15 10:46:43 +00:00
Samuel E. Moelius III
b8913894a1 Expand is_clone_like comment 2021-12-15 05:25:47 -05:00
Matthias Krüger
b2f8a27ff2 Rollup merge of #90521 - jhpratt:stabilize-destructuring_assignment, r=jackh726,pnkfelix
Stabilize `destructuring_assignment`

Closes #71126

- [Stabilization report](https://github.com/rust-lang/rust/issues/71126#issuecomment-941148058)
- [Completed FCP](https://github.com/rust-lang/rust/issues/71126#issuecomment-954914819)

`@rustbot` label +F-destructuring-assignment +T-lang
Also needs +relnotes but I don't have permission to add that tag.
2021-12-15 08:36:19 +01:00
Nicholas Nethercote
a83c935a18 Remove unnecessary sigils around Ident::as_str() calls. 2021-12-15 17:32:42 +11:00
Nicholas Nethercote
ecd4919ebb Remove unnecessary sigils around Symbol::as_str() calls. 2021-12-15 17:32:14 +11:00
Jacob Pratt
f8817f63e1 Stabilize destructuring_assignment 2021-12-14 22:38:51 -05:00
Nicholas Nethercote
a89a063ba0 Remove SymbolStr.
By changing `as_str()` to take `&self` instead of `self`, we can just
return `&str`. We're still lying about lifetimes, but it's a smaller lie
than before, where `SymbolStr` contained a (fake) `&'static str`!
2021-12-15 13:30:26 +11:00
Matthias Krüger
55df990a9b Rollup merge of #91881 - Patrick-Poitras:stabilize-iter-zip, r=scottmcm
Stabilize `iter::zip`

Hello all!

As the tracking issue (#83574) for `iter::zip` completed the final commenting period without any concerns being raised, I hereby submit this stabilization PR on the issue.

As the pull request that introduced the feature (#82917) states, the `iter::zip` function is a shorter way to zip two iterators. As it's generally a quality-of-life/ergonomic improvement, it has been integrated into the codebase without any trouble, and has been
used in many places across the rust compiler and standard library since March without any issues.

For more details, I would refer to `@cuviper's` original PR, or the [function's documentation](https://doc.rust-lang.org/std/iter/fn.zip.html).
2021-12-15 01:28:08 +01:00
Matthias Krüger
b166642c35 Rollup merge of #90939 - estebank:wg-af-polish, r=tmandry
Tweak errors coming from `for`-loop, `?` and `.await` desugaring

 * Suggest removal of `.await` on non-`Future` expression
 * Keep track of obligations introduced by desugaring
 * Remove span pointing at method for obligation errors coming from desugaring
 * Point at called local sync `fn` and suggest making it `async`

```
error[E0277]: `()` is not a future
  --> $DIR/unnecessary-await.rs:9:10
   |
LL |     boo().await;
   |     -----^^^^^^ `()` is not a future
   |     |
   |     this call returns `()`
   |
   = help: the trait `Future` is not implemented for `()`
help: do not `.await` the expression
   |
LL -     boo().await;
LL +     boo();
   |
help: alternatively, consider making `fn boo` asynchronous
   |
LL | async fn boo () {}
   | +++++
```

Fix #66731.
2021-12-15 01:28:04 +01:00
Samuel E. Moelius III
3beb6b1908 Address review comments 2021-12-14 18:36:19 -05:00
PFPoitras
288afb366a Remove iter::zip feature gate from clippy 2021-12-14 18:50:46 -04:00
bors
6b6cc5d576 Auto merge of #91728 - Amanieu:stable_asm, r=joshtriplett
Stabilize asm! and global_asm!

Tracking issue: #72016

It's been almost 2 years since the original [RFC](https://github.com/rust-lang/rfcs/pull/2850) was posted and we're finally ready to stabilize this feature!

The main changes in this PR are:
- Removing `asm!` and `global_asm!` from the prelude as per the decision in #87228.
- Stabilizing the `asm` and `global_asm` features.
- Removing the unstable book pages for `asm` and `global_asm`. The contents are moved to the [reference](https://github.com/rust-lang/reference/pull/1105) and [rust by example](https://github.com/rust-lang/rust-by-example/pull/1483).
  - All links to these pages have been removed to satisfy the link checker. In a later PR these will be replaced with links to the reference or rust by example.
- Removing the automatic suggestion for using `llvm_asm!` instead of `asm!` if you're still using the old syntax, since it doesn't work anymore with `asm!` no longer being in the prelude. This only affects code that predates the old LLVM-style `asm!` being renamed to `llvm_asm!`.
- Updating `stdarch` and `compiler-builtins`.
- Updating all the tests.

r? `@joshtriplett`
2021-12-14 21:15:22 +00:00
Samuel E. Moelius III
cb609a9904 Add comma 2021-12-13 12:27:47 -05:00
Esteban Kuber
c5287b37fa fix clippy tests 2021-12-13 17:09:16 +00:00
Esteban Kuber
1c3747e7dd Fix rebase and clippy tests 2021-12-13 17:09:16 +00:00
Esteban Kuber
d8af82e4bb Fix clippy uses of QPath::LangItem 2021-12-13 17:09:16 +00:00
Samuel E. Moelius III
3807905e08 Handle to_vec on for loop expression #8069 2021-12-13 07:04:57 -05:00
Samuel E. Moelius III
290f74be4e Address review comments
* Share a list of methods with `implicit_clone`
* Ensure no overlap with `redundant_clone`
2021-12-13 06:31:17 -05:00
Samuel E. Moelius III
468c86e4a3 Add unnecessary_to_owned lint 2021-12-13 06:31:17 -05:00
Cormac Relf
17c1ff9faa let-else: use hir::Let in clippy
fix clippy format using `cargo fmt -p clippy_{lints,utils}`
manually revert rustfmt line truncations
rename to hir::Let in clippy
Undo the shadowing of various `expr` variables after renaming `scrutinee`
reduce destructuring of hir::Let to avoid `expr` collisions
cargo fmt -p clippy_{lints,utils}
bless new clippy::author output
2021-12-13 14:02:41 +11:00
Amanieu d'Antras
e1139cf570 Fix clippy tests 2021-12-13 00:00:51 +00:00
bors
41c48bd390 Auto merge of #91549 - fee1-dead:const_env, r=spastorino
Eliminate ConstnessAnd again

Closes #91489.
Closes #89432.

Reverts #91491.
Reverts #89450.

r? `@spastorino`
2021-12-12 22:15:32 +00:00
Ellen
603b865ae4 clippy owo 2021-12-12 12:34:21 +00:00
Deadbeef
adf8c381f2 Revert "Auto merge of #91491 - spastorino:revert-91354, r=oli-obk"
This reverts commit ff2439b7b9bafcfdff86b7847128014699df8442, reversing
changes made to 2a9e0831d6603d87220cedd1b1293e2eb82ef55c.
2021-12-12 12:34:46 +08:00
bors
aa3648af50 Auto merge of #8100 - c410-f3r:blah-blah-blah, r=giraffate
Fix `blocks_in_if_conditions` false positive

Fix #8099

changelog: Fix [`blocks_in_if_conditions`] false positive with an empty closure
2021-12-09 23:50:02 +00:00
bors
d27f598651 Auto merge of #8110 - xFrednet:0000-lintcheck-markdown-output, r=matthiaskrgr
Update lintcheck output to use tables and add markdown support

This PR updates changes lintcheck's output to use text tables and adds a markdown option to use Markdown links in the reports table. At first, I tried to keep the original output format, but the loading of old stats broke with the markdown option. The old format is therefore sadly incompatible with the new one. I can if requested make it in a way that the markdown output is only and optional additional output, but that would require more work for little benefit IMO.

For now, lintcheck has two output types. Here are the examples (best viewed on desktop):

<details>
<summary>`cargo lintcheck --only anyhow`</summary>

```txt
clippy 0.1.59 (460bef22a 2021-12-08)

### Reports

target/lintcheck/sources/anyhow-1.0.38/build.rs:1:null clippy::cargo_common_metadata "package `anyhow` is missing `package.keywords` metadata"
target/lintcheck/sources/anyhow-1.0.38/src/error.rs:350:5 clippy::missing_panics_doc "docs for function which may panic missing `# Panics` section"
target/lintcheck/sources/anyhow-1.0.38/src/lib.rs:1:null clippy::cargo_common_metadata "package `anyhow` is missing `package.keywords` metadata"

### Stats:

| lint                                               | count |
| -------------------------------------------------- | ----- |
| clippy::missing_panics_doc                         |     1 |
| clippy::cargo_common_metadata                      |     2 |

### ICEs:

```

</details>

<details>
<summary>`cargo lintcheck --only anyhow --markdown` (The file links only work locally)</summary>

clippy 0.1.59 (460bef22a 2021-12-08)

### Reports

| file | lint | message |
| --- | --- | --- |
| [`anyhow-1.0.38/build.rs:1:null`](../target/lintcheck/sources/anyhow-1.0.38/build.rs#L1) | `clippy::cargo_common_metadata`                    | "package `anyhow` is missing `package.keywords` metadata" |
| [`anyhow-1.0.38/src/error.rs:350:5`](../target/lintcheck/sources/anyhow-1.0.38/src/error.rs#L350) | `clippy::missing_panics_doc`                       | "docs for function which may panic missing `# Panics` section" |
| [`anyhow-1.0.38/src/lib.rs:1:null`](../target/lintcheck/sources/anyhow-1.0.38/src/lib.rs#L1) | `clippy::cargo_common_metadata`                    | "package `anyhow` is missing `package.keywords` metadata" |

### Stats:

| lint                                               | count |
| -------------------------------------------------- | ----- |
| clippy::missing_panics_doc                         |     1 |
| clippy::cargo_common_metadata                      |     2 |

### ICEs:

</details>

The table margins are so large to keep the table inline for long file names and lint names

---

changelog: none

r? `@matthiaskrgr`
2021-12-09 22:49:47 +00:00
xFrednet
d6fca4657d
Update lintcheck output to use tables and add markdown support 2021-12-09 20:38:43 +01:00
bors
4a4f0923ab Auto merge of #8096 - xFrednet:0000-remove-lintcheck-log-file, r=matthiaskrgr
Remove lintcheck log and add `--filter` option to lintcheck

This PR removes the really outdated lintcheck log from this repo and adds a new `--filter` option to force warnings of a lint. This also ignores `allow` attributes. I believe that this is a good thing, as we'll see if suppressed false positives are also fixed by the changes.

---

#### Example:
```sh
$ cargo lintcheck --filter identity_op
```

#### Output
```
clippy 0.1.59 (460bef22a 2021-12-08)

[..]/cargo-0.49.0/src/cargo/core/compiler/fingerprint.rs:1910:17 clippy::identity_op "the operation is ineffective. Consider reducing it to `(ret[0] as usize)`"
[..]/cargo-0.49.0/src/cargo/util/hex.rs:8:9 clippy::identity_op "the operation is ineffective. Consider reducing it to `num`"
[..]/libc-0.2.81/src/unix/linux_like/linux/mod.rs:2654:18 clippy::identity_op "the operation is ineffective. Consider reducing it to `(dev & 0x00000000000000ff)`"
[..]/libc-0.2.81/src/unix/linux_like/linux/mod.rs:2665:16 clippy::identity_op "the operation is ineffective. Consider reducing it to `(minor & 0x000000ff)`"
[..]/libc-0.2.81/src/unix/linux_like/mod.rs:1218:27 clippy::identity_op "the operation is ineffective. Consider reducing it to `IPOPT_CONTROL`"
[..]/rayon-1.5.0/src/slice/quicksort.rs:588:17 clippy::identity_op "the operation is ineffective. Consider reducing it to `len / 4`"
[..]/regex-1.3.2/src/dfa.rs:1380:14 clippy::identity_op "the operation is ineffective. Consider reducing it to `(empty_flags.start as u8)`"

Stats:
clippy::identity_op 7
ICEs:
```
Two of these lints are suppressed when lintcheck runs normally

---

changelog: none

r? `@matthiaskrgr` Feel free to reassign if you think that someone else would be a better reviewer 🙃
2021-12-09 17:40:32 +00:00
xFrednet
e42f79c0a3
Add filter option to lintcheck 2021-12-09 18:11:46 +01:00
bors
5abecad009 Auto merge of #8106 - medwards:rustc-lint-groups, r=flip1995
Remind users of separate `rustc` lint groups

changelog: none

fixes #8104
2021-12-09 13:36:51 +00:00
Michael Edwards
4520529a83 Remind users of separate rustc lint groups 2021-12-09 12:44:49 +01:00
Caio
392b2eff4b Fix blocks_in_if_conditions false positive 2021-12-08 20:02:28 -03:00
xFrednet
460bef22a3
Remove and ignore lintcheck's log file 2021-12-08 20:12:50 +01:00
bors
53059792e9 Auto merge of #8071 - GuillaumeGomez:method-must-use, r=xFrednet
Add new lint to warn when #[must_use] attribute should be used on a method

This lint is somewhat similar to https://rust-lang.github.io/rust-clippy/master/index.html#must_use_candidate but also different: it emits a warning by default and only targets methods (so not functions nor associated functions).

Someone suggested it to me after this tweet: https://twitter.com/m_ou_se/status/1466439813230477312

I think it would reduce the number of cases of API misuses quite a lot.

What do you think?

---

changelog: Added new [`return_self_not_must_use`] lint
2021-12-08 19:09:25 +00:00
bors
3c8f90bd5a Auto merge of #8030 - WaffleLapkin:ignore_trait_assoc_types_type_complexity, r=llogiq
Ignore associated types in traits when considering type complexity

changelog: Ignore associated types in traits when checking ``[`type_complexity`]`` lint.

fixes #1013
2021-12-08 11:54:03 +00:00
Maybe Waffle
c176568abd Ignore associated items in trait *implementations* when considering type complexity 2021-12-08 14:38:59 +03:00
Guillaume Gomez
e93767b395 Apply new lint on clippy source code 2021-12-08 11:16:14 +01:00
Guillaume Gomez
2b35edbb84 Update other UI tests as well 2021-12-08 11:16:14 +01:00
Guillaume Gomez
8dfb3ec8a4 Add new lint to warn when #[must_use] attribute should be used on a method 2021-12-08 11:16:14 +01:00
bors
86cea73449 Auto merge of #8086 - dswij:7991, r=giraffate
Fix bad suggestion on `option_if_let_else` when there is complex subpat

closes #7991

Prefer not warning any complex subpat in `option_if_let_else` rather than suggesting obscure suggestions.

changelog: [`option_if_let_else`] does not warn when complex subpat is present
2021-12-07 23:45:58 +00:00
bors
ecae70f729 Auto merge of #8075 - Qwaz:non_send_fields_documentation, r=xFrednet
Clarify the purpose of the non_send lint

PR 2/2 for issue #8045. Tried to tone down the warning message and clarify the intention of the lint. Specifically, I added a description that this lint tries to detect "types that are not safe to be sent to another thread".

changelog: none

r? `@xFrednet`
2021-12-07 22:14:10 +00:00
Yechan Bae
5d63a28638 Move non_send_fields_in_send_ty back to nursery 2021-12-07 10:45:59 -05:00
Yechan Bae
c0fd250c62 Fix grammar issues 2021-12-07 10:08:22 -05:00
Yechan Bae
ee0d71e103 Clarify the purpose of the lint 2021-12-07 10:06:34 -05:00
dswij
b5fa5b37cc option_if_let_else Do not warn when complex subpat is present 2021-12-07 15:47:28 +08:00
bors
1c7df44e2d Auto merge of #8085 - jqnatividad:8084-needless_lifetimes_typo, r=giraffate
`needless_lifetimes` Known problems typo

fixes #8084

[needless_lifetimes]

changelog: none
2021-12-07 00:45:59 +00:00
Joel Natividad
d91b91ae57 needless_lifetimes Known problems typo
fixes #8084
2021-12-06 19:11:19 -05:00
bors
f615ea474b Auto merge of #8080 - dswij:8019, r=giraffate
Fix FP on `question_mark` if returned object is not local

Closes #8019

changelog: [`question_mark`] Fix FP when returned object is not local
2021-12-07 00:07:46 +00:00