Commit Graph

13535 Commits

Author SHA1 Message Date
bors
92b6955b12 Auto merge of #94512 - RalfJung:sdiv-ub, r=oli-obk
Miri/CTFE: properly treat overflow in (signed) division/rem as UB

To my surprise, it looks like LLVM treats overflow of signed div/rem as UB. From what I can tell, MIR `Div`/`Rem` directly lowers to the corresponding LLVM operation, so to make that correct we also have to consider these overflows UB in the CTFE/Miri interpreter engine.

r? `@oli-obk`
2022-03-03 12:56:24 +00:00
bors
ef4af1d2d8 Auto merge of #8497 - Manishearth:transmute-undefined-repr-note, r=flip1995
comment about transmute_undefined_repr in nursery

See discussion in https://github.com/rust-lang/rust-clippy/pull/8432

changelog: none
2022-03-03 09:05:21 +00:00
Manish Goregaokar
78547b1716
comment about transmute_undefined_repr in nursery 2022-03-03 09:03:27 +00:00
Liu Dingming
6cc2eeaa56 Suggest into_iter() over drain(..)
Add doc

Add description

iter_with_drain dogfood

Disable emiting on struct field.

Fix clippy

Add eq_path for SpanlessEq

Fix tests

Better error message

Fix doc test

Fix version

Apply suggestions
2022-03-03 13:10:19 +08:00
Ralf Jung
c45a42a332 bless clippy 2022-03-02 19:20:27 -05:00
flip1995
7f44a753ce Move transmute_undefined_repr back to nursery
There's still open discussion if this lint is ready to be enabled by
default. We want to give us more time to figure this out and prevent
this lint from getting to stable as an enabled-by-default lint.
2022-03-02 13:07:00 -08:00
bors
6e211eac7c Auto merge of #8489 - smoelius:unnecessary-find-map, r=llogiq
Add `unnecessary_find_map` lint

This PR adds an `unnecessary_find_map` lint. It is essentially just a minor enhancement of `unnecessary_filter_map`.

Closes #8467

changelog: New lint `unnecessary_find_map`
2022-03-02 19:50:27 +00:00
bors
2e40dc81b7 Auto merge of #8456 - ebobrow:use_self_pat, r=llogiq
check `use_self` in `pat`

fixes #6955

changelog: check `use_self` in `pat`
2022-03-02 19:31:22 +00:00
bors
27869d6d46 Auto merge of #8174 - rust-lang:missing-spin-loop, r=flip1995
new lint: `missing-spin-loop`

This fixes #7809. I went with the shorter name because the function is called `std::hint::spin_loop`. It doesn't yet detect `while let` loops. I left that for a follow-up PR.

---

changelog: new lint: [`missing_spin_loop`]
2022-03-02 19:12:32 +00:00
Andre Bogus
9f1080cc6e new lint: missing-spin-loop 2022-03-02 19:31:06 +01:00
bors
14f3d05939 Auto merge of #8432 - dtolnay-contrib:transmuteundefinedrepr2, r=Manishearth
Transmute_undefined_repr to nursery again

This PR reinstates #8418, which was reverted in #8425 (incorrectly I think).

I don't want to start a revert war over this but I feel very strongly that this lint is not in a state that would be a net benefit to users of clippy. In its current form, making this an enabled-by-default `correctness` lint with authoritative-sounding proclamations of undefined behavior does more harm than the benefit of the true positive cases.

I can file a bunch more examples of false positives but I don't want to give the author of this lint the impression that it is ready to graduate from `nursery` as soon as I've exhausted the amount of time I am willing to spend revising this lint.

Instead I would recommend that the author of the lint try running it on some reputable codebases containing transmutes. Everywhere that the lint triggers please consider critically whether it should be triggering. For cases that you think are true positives, please raise a few of them with the crate authors (in a PR or issue) to better understand their perspective if they think the transmute is correct.

---

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

changelog: Re-remove [`transmute_undefined_repr`] from default set of enabled lints
2022-03-02 17:05:06 +00:00
bors
1a25d190e7 Auto merge of #8491 - matthiaskrgr:no_num_cpus, r=flip1995
tests: use std:🧵:available_parallelism() instead of num_cpus to get thread count

removes the dependency added in https://github.com/rust-lang/rust-clippy/pull/8451
---

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

changelog: tests: use std:🧵:available_parallelism() instead of num_cpus to get thread count
2022-03-02 09:26:11 +00:00
Samuel E. Moelius III
2a588d810f Add unnecessary_find_map lint 2022-03-01 19:24:55 -05:00
Matthias Krüger
7a15061fbc tests: use std:🧵:available_parallelism() instead of num_cpus to get thread count
removes the dependency added in https://github.com/rust-lang/rust-clippy/pull/8451
2022-03-01 21:32:18 +01:00
bors
b8a205aeb8 Auto merge of #8488 - flip1995:ci-cargo-dev-new-lint, r=llogiq
Move testing of cargo dev new_lint to cargo dev workflow

This should be placed there. No need to run this in PR CI, if clippy_dev
isn't touched. (It will be run by bors anyway)

changelog: none
2022-03-01 20:05:21 +00:00
bors
28b1fe5129 Auto merge of #8313 - flip1995:msrv-internal-lint, r=xFrednet
Implement internal lint for MSRV lints

This internal lint checks if the `extract_msrv_attrs!` macro is used if
a lint has a MSRV. If not, it suggests to add this attribute to the lint
pass implementation.

Following up https://github.com/rust-lang/rust-clippy/pull/8280#discussion_r785226072. This currently doesn't implement the documentation check. But since this is just an extension of this lint, I think this is a good MVP of this lint.

r? `@camsteffen`

cc `@xFrednet`

changelog: none
2022-03-01 17:40:52 +00:00
flip1995
73944645aa
Move testing of cargo dev new_lint to cargo dev workflow
This should be placed there. No need to run this in PR CI, if clippy_dev
isn't touched. (It will be run by bors anyway)
2022-03-01 10:10:01 +00:00
flip1995
bca4ee7971
Implement internal lint for MSRV lints
This internal lint checks if the `extract_msrv_attrs!` macro is used if
a lint has a MSRV. If not, it suggests to add this attribute to the lint
pass implementation.
2022-03-01 09:40:07 +00:00
bors
e511476f24 Auto merge of #8479 - smoelius:unnecessary-filter-map, r=llogiq
Fix some `unnecessary_filter_map` false positives

This is a proposed fix for #4433.

It moves `clone_or_copy_needed` out of `unnecessary_iter_cloned.rs` and into `methods::utils`. It then adds a check of this function to `unnecessary_filter_map::check`.

Fixes #4433

changelog: none
2022-02-28 20:09:18 +00:00
Samuel E. Moelius III
d123ffc6c7 Check clone_or_copy_needed in unnecessary_filter_map::check 2022-02-28 05:24:00 -05:00
Samuel E. Moelius III
cfd32522c0 Add tests to tests/ui/unnecessary_filter_map.rs
The tests currently fail, and are fixed by the next commit.
2022-02-28 05:24:00 -05:00
bors
8d12cd4779 Auto merge of #8476 - xFrednet:0000-update-edition-for-rustfmt, r=giraffate
Update edition in rustfmt.toml

I noticed that our `rustfmt.toml` still has the edition 2018 listed. This updates the configuration to use 2021.

This luckily doesn't introduce any formatting changes 🙃

changelog: none
2022-02-27 13:01:04 +00:00
xFrednet
acddac4b96
Update edition in rustfmt.toml 2022-02-26 20:33:47 +01:00
Elliot Bobrow
914ae1e849 check use_self in pat 2022-02-26 09:23:29 -08:00
bors
d1ca1c1d0c Auto merge of #8462 - ken-matsui:use-precise-namespace-for-reverse, r=llogiq
Use the precise namespace for `Reverse`

Closes: https://github.com/rust-lang/rust-clippy/issues/8461

changelog: [`unnecessary_sort_by`](https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_sort_by): Use the precise namespace for `Reverse`
2022-02-26 14:49:39 +00:00
flip1995
35020280a0 Merge commit 'e329249b6a3a98830d860c74c8234a8dd9407436' into clippyup 2022-02-26 14:26:21 +01:00
bors
e329249b6a Auto merge of #8464 - Jarcho:ptr_arg_8463, r=camsteffen
Fix `ptr_arg`

fixes: #8463

changelog: Fix `ptr_arg` when multiple arguments are being checked in one function
2022-02-26 03:00:53 +00:00
bors
2c8d5a2500 Auto merge of #8453 - tamaroning:fix_large_enum_variant, r=camsteffen
fix false positives of large_enum_variant

fixes: #8321
The size of enums containing generic type was calculated to be 0.
I changed [large_enum_variant] so that such enums are not linted.

changelog: none
2022-02-26 02:42:43 +00:00
bors
8bba6b7af0 Auto merge of #8253 - Alexendoo:print-in-fmt, r=camsteffen
Add `print_in_format_impl` lint

changelog: new lint: [`print_in_format_impl`]

Lints the use of `print`-like macros in manual `Display`/`Debug` impls. I feel like I make this mistake every time I write one 😄

r? `@camsteffen`
2022-02-25 21:12:14 +00:00
Alex Macleod
52f3d61a2a Add print_in_format_impl lint 2022-02-25 21:10:06 +00:00
Alex Macleod
bcbb07f4dc Rename RecursiveFormatImpl to FormatImpl 2022-02-25 18:22:55 +00:00
bors
4417f78e91 Auto merge of #8474 - Alexendoo:paths, r=Manishearth
Replace some more paths with diagnostic items

cc #5393

Replaces the macro & mem paths, and catches a couple others that were unused

changelog: none
2022-02-25 16:07:59 +00:00
bors
95897bfcf2 Auto merge of #8472 - Mastermindaxe:#8152_new-without-default_should_not_trigger_on_doc_hidden_items, r=flip1995
Disable ``[`new-without-default`]`` for new() methods that are marked…

… with '#[doc(hidden)]'

Fixes #8152

changelog: Disable ``[`new-without-default`]`` for new() methods that are marked with `#[doc(hidden)]`
2022-02-25 15:51:37 +00:00
Alex Macleod
2955db493e Replace some more paths with diagnostic items 2022-02-25 15:38:06 +00:00
Florian Nagel
862211d540 Disable `[new-without-default]` for new() methods that are marked with '#[doc(hidden)]'
Fixes issue #8152
2022-02-25 16:34:37 +01:00
Mark Rousskov
307966fbb2 Switch bootstrap cfgs 2022-02-25 08:00:52 -05:00
J-ZhengLi
30fb8229e1 add tests, add base bone for the new lint 2022-02-25 18:08:52 +08:00
bors
87355df6d4 Auto merge of #93368 - eddyb:diagbld-guarantee, r=estebank
rustc_errors: let `DiagnosticBuilder::emit` return a "guarantee of emission".

That is, `DiagnosticBuilder` is now generic over the return type of `.emit()`, so we'll now have:
* `DiagnosticBuilder<ErrorReported>` for error (incl. fatal/bug) diagnostics
  * can only be created via a `const L: Level`-generic constructor, that limits allowed variants via a `where` clause, so not even `rustc_errors` can accidentally bypass this limitation
  * asserts `diagnostic.is_error()` on emission, just in case the construction restriction was bypassed (e.g. by replacing the whole `Diagnostic` inside `DiagnosticBuilder`)
  * `.emit()` returns `ErrorReported`, as a "proof" token that `.emit()` was called
    (though note that this isn't a real guarantee until after completing the work on
     #69426)
* `DiagnosticBuilder<()>` for everything else (warnings, notes, etc.)
  * can also be obtained from other `DiagnosticBuilder`s by calling `.forget_guarantee()`

This PR is a companion to other ongoing work, namely:
* #69426
  and it's ongoing implementation:
  #93222
  the API changes in this PR are needed to get statically-checked "only errors produce `ErrorReported` from `.emit()`", but doesn't itself provide any really strong guarantees without those other `ErrorReported` changes
* #93244
  would make the choices of API changes (esp. naming) in this PR fit better overall

In order to be able to let `.emit()` return anything trustable, several changes had to be made:
* `Diagnostic`'s `level` field is now private to `rustc_errors`, to disallow arbitrary "downgrade"s from "some kind of error" to "warning" (or anything else that doesn't cause compilation to fail)
  * it's still possible to replace the whole `Diagnostic` inside the `DiagnosticBuilder`, sadly, that's harder to fix, but it's unlikely enough that we can paper over it with asserts on `.emit()`
* `.cancel()` now consumes `DiagnosticBuilder`, preventing `.emit()` calls on a cancelled diagnostic
  * it's also now done internally, through `DiagnosticBuilder`-private state, instead of having a `Level::Cancelled` variant that can be read (or worse, written) by the user
  * this removes a hazard of calling `.cancel()` on an error then continuing to attach details to it, and even expect to be able to `.emit()` it
  * warnings were switched to *only* `can_emit_warnings` on emission (instead of pre-cancelling early)
  * `struct_dummy` was removed (as it relied on a pre-`Cancelled` `Diagnostic`)
* since `.emit()` doesn't consume the `DiagnosticBuilder` <sub>(I tried and gave up, it's much more work than this PR)</sub>,
  we have to make `.emit()` idempotent wrt the guarantees it returns
  * thankfully, `err.emit(); err.emit();` can return `ErrorReported` both times, as the second `.emit()` call has no side-effects *only* because the first one did do the appropriate emission
* `&mut Diagnostic` is now used in a lot of function signatures, which used to take `&mut DiagnosticBuilder` (in the interest of not having to make those functions generic)
  * the APIs were already mostly identical, allowing for low-effort porting to this new setup
  * only some of the suggestion methods needed some rework, to have the extra `DiagnosticBuilder` functionality on the `Diagnostic` methods themselves (that change is also present in #93259)
  * `.emit()`/`.cancel()` aren't available, but IMO calling them from an "error decorator/annotator" function isn't a good practice, and can lead to strange behavior (from the caller's perspective)
  * `.downgrade_to_delayed_bug()` was added, letting you convert any `.is_error()` diagnostic into a `delay_span_bug` one (which works because in both cases the guarantees available are the same)

This PR should ideally be reviewed commit-by-commit, since there is a lot of fallout in each.

r? `@estebank` cc `@Manishearth` `@nikomatsakis` `@mark-i-m`
2022-02-25 00:46:04 +00:00
Dylan DPC
996fa506a4 Rollup merge of #93714 - compiler-errors:can-type-impl-copy-error-span, r=jackh726
better ObligationCause for normalization errors in `can_type_implement_copy`

Some logic is needed so we can point to the field when given totally nonsense types like `struct Foo(<u32 as Iterator>::Item);`

Fixes #93687
2022-02-24 21:42:12 +01:00
Vadim Petrochenkov
a30eba2c7e Update clippy tests 2022-02-24 22:55:40 +03:00
Vadim Petrochenkov
83d32701f2 resolve: Fix incorrect results of opt_def_kind query for some built-in macros
Previously it always returned `MacroKind::Bang` while some of those macros are actually attributes and derives
2022-02-24 22:54:36 +03:00
bors
7b2896a8fc Auto merge of #8468 - flip1995:rustup, r=flip1995
Rustup

r? `@ghost`

changelog: none
2022-02-24 18:37:57 +00:00
flip1995
ce1904f6cf
Bump nightly version -> 2022-02-24 2022-02-24 19:33:10 +01:00
flip1995
5ece8d2bc4
Bump Clippy Version -> 0.1.61 2022-02-24 19:32:47 +01:00
flip1995
fd495a0654
Merge remote-tracking branch 'upstream/master' into rustup 2022-02-24 19:32:17 +01:00
Michael Goulet
676943a9f9 better ObligationCause for normalization errors in can_type_implement_copy 2022-02-24 08:30:38 -08:00
bors
042892a081 Auto merge of #8466 - tamaroning:fix_reduntant_closure, r=Manishearth
False positive redundant_closure when using ref pattern in closure params

fixes #8460
Fixed [redundant_closure] so that closures of which params bound as `ref` or `ref mut ` doesn't trigger the lint.
(e.g. `|ref x| some_expr` doesn't trigger the lint.)
changelog: none
2022-02-23 18:26:30 +00:00
tamaron
31b49b0be8 fix typo 2022-02-24 00:25:07 +09:00
tamaron
db62821c03 fix 2022-02-24 00:16:24 +09:00
Eduard-Mihai Burtescu
881b8cb704 rustc_errors: take self by value in DiagnosticBuilder::cancel. 2022-02-23 06:08:06 +00:00