Add suggestion for neg_multiply lint
This fixes#8115 by adding a suggestion for [neg_multiply].
My first issue on Github, any feedback or input is welcome 😃
changelog: create a suggestion for `neg_multiply`
Test clippy_utils in CI
r? `@xFrednet` Since you did the last refactor of the `str_utils` functions in #7873
changelog: Make sure tests in `clippy_utils` are passing by testing it in CI
This makes sure that the tests in clippy_utils are run in CI.
When looking into this I discovered that two tests were failing and
multiple doc tests were failing. This fixes those tests and enables a
few more doc tests.
Fix `SAFETY` comment tag casing in undocumented_unsafe_blocks
This changes the lint introduced in #7748 to suggest adding a `SAFETY` comment instead of a `Safety` comment.
Searching for `// Safety:` in rust-lang/rust yields 67 results while `// SAFETY:` yields 1072.
I think it's safe to say that this comment tag is written in upper case, just like `TODO`, `FIXME` and so on are. As such I would expect this lint to follow the official convention as well.
Note that I intentionally introduced some casing diversity in `tests/ui/undocumented_unsafe_blocks.rs` to test more cases than just `Safety:`.
changelog: Capitalize `SAFETY` comment in [`undocumented_unsafe_blocks`]
Don't emit RETURN_SELF_NOT_MUST_USE lint if `Self` already is marked as `#[must_use]`
New bug discovered with this lint. Hopefully, this is the last one.
---
changelog: none
Ensure that RETURN_SELF_NOT_MUST_USE is not emitted if the method already has `#[must_use]`
Fixes https://github.com/rust-lang/rust-clippy/issues/8140.
---
Edit:
changelog: none
(The lint is not in beta yet, this should therefore not be included inside the changelog :) )
Fix commits and formatting of CHANGELOG.md
r? `@Manishearth`
Follow up to #8136
I think the beta commit update didn't take the backport we've done into account. I fixed the commit ranges. And while I was at it, I also applied my usual formatting to the changelog entries.
changelog: none
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
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).
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.
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`
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`
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 🙃