Commit graph

3286 commits

Author SHA1 Message Date
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
flip1995
8fea1d94f3 Merge commit 'a5d597637dcb78dc73f93561ce474f23d4177c35' into clippyup 2021-12-06 12:33:31 +01:00
Aaron Hill
3c8b644d0d Only check for errors in predicate when skipping impl assembly
Prior to PR #91205, checking for errors in the overall obligation
would check checking the `ParamEnv`, due to an incorrect
`super_visit_with` impl. With this bug fixed, we will now
bail out of impl candidate assembly if the `ParamEnv` contains
any error types.

In practice, this appears to be overly conservative - when an error
occurs early in compilation, we end up giving up early for some
predicates that we could have successfully evaluated without overflow.
By only checking for errors in the predicate itself, we avoid causing
additional spurious 'type annotations needed' errors after a 'real'
error has already occurred.

With this PR, the diagnostic changes caused by PR #91205 are reverted.
2021-11-27 11:33:55 -06:00
bors
6b997b6576 Auto merge of #91205 - Aaron1011:visit_param_env, r=lcnr
Visit `param_env` field in Obligation's `TypeFoldable` impl

This oversight appears to have gone unnoticed for a long time
without causing issues, but it should still be fixed.
2021-11-26 09:55:06 +00:00
Aaron Hill
9274ec5691 Visit param_env field in Obligation's TypeFoldable impl
This oversight appears to have gone unnoticed for a long time
without causing issues, but it should still be fixed.
2021-11-25 15:33:37 -06:00
Esteban Kuber
5fc61a24c4 Fix clippy test 2021-11-25 18:39:32 +00:00
Cameron Steffen
e58ffb88e6 Fix Clippy with changed for loop desugar 2021-11-21 08:16:09 -06:00
Joshua Nelson
ac9dd36856 Don't abort compilation after giving a lint error
The only reason to use `abort_if_errors` is when the program is so broken that either:
1. later passes get confused and ICE
2. any diagnostics from later passes would be noise

This is never the case for lints, because the compiler has to be able to deal with `allow`-ed lints.
So it can continue to lint and compile even if there are lint errors.
2021-11-08 01:22:28 +00:00
flip1995
e674d0a599 Merge commit 'e18101137866b79045fee0ef996e696e68c920b4' into clippyup 2021-11-04 12:52:36 +00:00
Matthias Krüger
d634faea06 Rollup merge of #89786 - jkugelman:must-use-len-and-is_empty, r=joshtriplett
Add #[must_use] to len and is_empty

Parent issue: #89692

r? `@joshtriplett`
2021-10-31 13:20:05 +01:00
John Kugelman
892063ed2d Add #[must_use] to len and is_empty 2021-10-30 19:25:12 -04:00
Esteban Kuber
f674e6f49c Always sort suggestions before emitting them 2021-10-24 20:28:44 +00:00
flip1995
7631fc5d82 Merge commit '91496c2ac6abf6454c413bb23e8becf6b6dc20ea' into clippyup 2021-10-21 13:11:36 +02:00
Matthias Krüger
e84537bcdd Rollup merge of #89990 - petrochenkov:idempty, r=wesleywiser
rustc_span: `Ident::invalid` -> `Ident::empty`

The equivalent for `Symbol`s was renamed some time ago (`kw::Invalid` -> `kw::Empty`), and it makes sense to do the same thing for `Ident`s as well.
2021-10-18 08:13:30 +02:00
Vadim Petrochenkov
5f2ecc37f8 rustc_span: Ident::invalid -> Ident::empty
The equivalent for `Symbol`s was renamed some time ago (`kw::Invalid` -> `kw::Empty`), and it makes sense to do the same thing for `Ident`s.
2021-10-17 23:20:30 +03:00
Matthias Krüger
79b73ac98d Rollup merge of #89963 - r00ster91:parenthesisparentheses, r=nagisa
Some "parenthesis" and "parentheses" fixes

"Parenthesis" is the singular (e.g. one `(` or one `)`) and "parentheses" is the plural (multiple `(` or `)`s) and this is not hard to mix up so here are some fixes for that.

Inspired by #89958
2021-10-17 18:18:59 +02:00
r00ster91
599d9126a2 Some "parenthesis" and "parentheses" fixes 2021-10-17 12:04:01 +02:00
Cameron Steffen
0a23fff82d Fix clippy with changed macro statement spans 2021-10-15 02:36:58 -05:00
Oli Scherer
049ab82662 Update clippy ui output 2021-10-13 11:06:14 +00:00
bors
175738677c Auto merge of #89770 - jkugelman:must-use-from-and-into, r=joshtriplett
Add #[must_use] to From::from and Into::into

Risk of churn: **High**
Magic 8-Ball says: **Outlook not so good**

I figured I'd put this out there. If we don't do it now maybe we save it for a rainy day.

Parent issue: #89692

r? `@joshtriplett`
2021-10-12 09:43:37 +00:00
John Kugelman
44db271272 Add #[must_use] to From::from and Into::into 2021-10-11 18:10:30 -04:00
flip1995
f44a904a56 Deprecate mem_discriminant_non_enum
This lint has been uplifted and is now included in
enum_intrinsics_non_enums.
2021-10-11 10:10:16 +02:00
flip1995
5cf4984872 Merge commit 'b7f3f7f6082679da2da9a0b3faf1b5adef3afd3b' into clippyup 2021-10-07 11:21:30 +02:00
bors
87bb18e7c2 Auto merge of #88175 - camsteffen:let-desugar-span, r=Manishearth
Add expansion to while desugar spans

In the same vein as #88163, this reverts a change in Clippy behavior as a result of #80357 (and reverts some `#[allow]`s): This changes `clippy::blocks_in_if_conditions` to not fire on `while` loops. Though we might actually want Clippy to lint those cases, we should introduce the change purposefully, with tests, and possibly under a different lint name.

The actual change here is to add a desugaring expansion to the spans when lowering a `while` loop.

r? `@Manishearth`
2021-10-03 21:44:10 +00:00
Cameron Steffen
e165c12932 Make diangostic item names consistent 2021-10-02 19:38:19 -05:00
Cameron Steffen
9c2d52fabe Add desugaring mark to while loop 2021-10-02 17:41:14 -05:00
Manish Goregaokar
730d86f521 Rollup merge of #88782 - asquared31415:issue-79559, r=cjgillot
Fix ICE when `start` lang item has wrong generics

In my previous pr #87875 I missed the requirements on the `start` lang item due to its relative difficulty to test and opting for more conservative estimates.  This fixes that by updating the requirement to be exactly one generic type.

The `start` lang item should have exactly one generic type for the return type of the `main` fn ptr passed to it.  I believe having zero would previously *sometimes* compile (often with the use of `fn() -> ()` as the fn ptr but it was likely UB to call if the return type of `main` was not `()` as far as I know) however it also sometimes would not for various errors including ICEs and LLVM errors depending on exact situations.  Having more than 1 generic has always failed with an ICE because only the one generic type is expected and provided.

Fixes #79559, fixes #73584, fixes #83117 (all duplicates)
Relevant to #9307

r? ````@cjgillot````
2021-09-30 18:05:20 -07:00
flip1995
23d5457e6d Merge commit 'cb7915b00c235e9b5861564f3be78dba330980ee' into clippyup 2021-09-28 18:03:12 +01:00
asquared31415
87ba8d24d6 update test 2021-09-14 18:47:47 -04:00
Fabian Wolff
81ce2fb167 Ignore automatically derived impls of Clone and Debug in dead code analysis 2021-09-09 19:49:07 +02:00
flip1995
091ed44b50 Merge commit '27afd6ade4bb1123a8bf82001629b69d23d62aff' into clippyup 2021-09-08 16:31:47 +02:00
bors
f7aaa2a200 Auto merge of #88493 - chenyukang:fix-duplicated-diagnostic, r=estebank
Fix #88256 remove duplicated diagnostics

Fix #88256
2021-09-06 00:14:41 +00:00
yukang
6764fde913 Fix #88256, remove duplicated diagnostic 2021-09-04 19:26:25 +08:00
lcnr
fd8b150959 feature(const_generics) -> feature(const_param_types) 2021-08-30 11:00:21 +02:00
Ellen
0b526fd7fb rename const_evaluatable_checked to generic_const_exprs
2021-08-30 11:00:21 +02:00
Mara Bos
4c847c0dbd Rollup merge of #88230 - steffahn:a_an, r=oli-obk
Fix typos “a”→“an”

Fix typos in comments; found using a regex to find some easy instance of incorrect usage of a vs. an.

While automation was used to find these, every change was checked manually.

Changes in submodules get separate PRs:
* https://github.com/rust-lang/stdarch/pull/1201
* https://github.com/rust-lang/cargo/pull/9821
* https://github.com/rust-lang/miri/pull/1874
* https://github.com/rust-lang/rls/pull/1746
* https://github.com/rust-analyzer/rust-analyzer/pull/9984
  _folks @ rust-analyzer are fast at merging…_
  * https://github.com/rust-analyzer/rust-analyzer/pull/9985
  * https://github.com/rust-analyzer/rust-analyzer/pull/9987
  * https://github.com/rust-analyzer/rust-analyzer/pull/9989

_For `clippy`, I don’t know if the changes should better better be moved to a PR to the original repo._

<hr>

This has some overlap with #88226, but neither is a strict superset of the other.

If you want multiple commits, I can split it up; in that case, make sure to suggest a criterion for splitting.
2021-08-23 20:45:49 +02:00
Frank Steffahn
c86071898f Fix typos “a”→“an” 2021-08-22 15:35:11 +02:00
Cameron Steffen
ae02282ad0 Fix clippy let expressions fallout 2021-08-19 14:17:05 -05:00
bors
d9c3f0d690 Auto merge of #84039 - jyn514:uplift-atomic-ordering, r=wesleywiser
Uplift the invalid_atomic_ordering lint from clippy to rustc

This is mostly just a rebase of https://github.com/rust-lang/rust/pull/79654; I've copy/pasted the text from that PR below.

r? `@lcnr` since you reviewed the last one, but feel free to reassign.

---

This is an implementation of https://github.com/rust-lang/compiler-team/issues/390.

As mentioned, in general this turns an unconditional runtime panic into a (compile time) lint failure. It has no false positives, and the only false negatives I'm aware of are if `Ordering` isn't specified directly and is comes from an argument/constant/whatever.

As a result of it having no false positives, and the alternative always being strictly wrong, it's on as deny by default. This seems right.

In the [zulip stream](https://rust-lang.zulipchat.com/#narrow/stream/233931-t-compiler.2Fmajor-changes/topic/Uplift.20the.20.60invalid_atomic_ordering.60.20lint.20from.20clippy/near/218483957) `@joshtriplett` suggested that lang team should FCP this before landing it. Perhaps libs team cares too?

---

Some notes on the code for reviewers / others below

## Changes from clippy

The code is changed from [the implementation in clippy](68cf94f6a6/clippy_lints/src/atomic_ordering.rs) in the following ways:

1. Uses `Symbols` and `rustc_diagnostic_item`s instead of string literals.
    - It's possible I should have just invoked Symbol::intern for some of these instead? Seems better to use symbol, but it did require adding several.
2. The functions are moved to static methods inside the lint struct, as a way to namespace them.
    - There's a lot of other code in that file — which I picked as the location for this lint because `@jyn514` told me that seemed reasonable.
3. Supports unstable AtomicU128/AtomicI128.
    - I did this because it was almost easier to support them than not — not supporting them would have (ideally) required finding a way not to give them a `rustc_diagnostic_item`, which would have complicated an already big macro.
    - These don't have tests since I wasn't sure if/how I should make tests conditional on whether or not the target has the atomic... This is to a certain extent an issue of 64bit atomics too, but 128-bit atomics are much less common. Regardless, the existing tests should be *more* than thorough enough here.
4. Minor changes like:
    - grammar tweaks ("loads cannot have `Release` **and** `AcqRel` ordering" => "loads cannot have `Release` **or** `AcqRel` ordering")
    - function renames (`match_ordering_def_path` => `matches_ordering_def_path`),
    - avoiding clippy-specific helper methods that don't exist in rustc_lint and didn't seem worth adding for this case (for example `cx.struct_span_lint` vs clippy's `span_lint_and_help` helper).

## Potential issues

(This is just about the code in this PR, not conceptual issues with the lint or anything)

1. I'm not sure if I should have used a diagnostic item for `Ordering` and its variants (I couldn't figure out how really, so if I should do this some pointers would be appreciated).
    - It seems possible that failing to do this might possibly mean there are more cases this lint would miss, but I don't really know how `match_def_path` works and if it has any pitfalls like that, so maybe not.

2. I *think* I deprecated the lint in clippy (CC `@flip1995` who asked to be notified about clippy changes in the future in [this comment](https://github.com/rust-lang/rust/pull/75671#issuecomment-718731659)) but I'm not sure if I need to do anything else there.
    - I'm kind of hoping CI will catch if I missed anything, since `x.py test src/tools/clippy` fails with a lot of errors with and without my changes (and is probably a nonsense command regardless). Running `cargo test` from src/tools/clippy also fails with unrelated errors that seem like refactorings that didnt update clippy? So, honestly no clue.

3. I wasn't sure if the description/example I gave good. Hopefully it is. The example is less thorough than the one from clippy here: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_atomic_ordering. Let me know if/how I should change it if it needs changing.

4. It pulls in the `if_chain` crate. This crate was already used in clippy, and seems like it's used elsewhere in rustc, but I'm willing to rewrite it to not use this if needed (I'd prefer not to, all things being equal).
2021-08-16 06:36:13 +00:00
Thom Chiovoloni
295225b660 Uplift the invalid_atomic_ordering lint from clippy to rustc
- Deprecate clippy::invalid_atomic_ordering
- Use rustc_diagnostic_item for the orderings in the invalid_atomic_ordering lint
- Reduce code duplication
- Give up on making enum variants diagnostic items and just look for
`Ordering` instead

  I ran into tons of trouble with this because apparently the change to
  store HIR attrs in a side table also gave the DefIds of the
  constructor instead of the variant itself. So I had to change
  `matches_ordering` to also check the grandparent of the defid as well.

- Rename `atomic_ordering_x` symbols to just the name of the variant
- Fix typos in checks - there were a few places that said "may not be
  Release" in the diagnostic but actually checked for SeqCst in the lint.
- Make constant items const
- Use fewer diagnostic items
- Only look at arguments after making sure the method matches

  This prevents an ICE when there aren't enough arguments.

- Ignore trait methods
- Only check Ctors instead of going through `qpath_res`

  The functions take values, so this couldn't ever be anything else.

- Add if_chain to allowed dependencies
- Fix grammar
- Remove unnecessary allow
2021-08-16 03:55:27 +00:00
Caio
b97d4c062b Introduce hir::ExprKind::Let - Take 2 2021-08-15 16:18:26 -03:00
bors
456e48f39e Auto merge of #87954 - flip1995:clippyup, r=Manishearth
Update Clippy

r? `@Manishearth`
2021-08-13 05:30:37 +00:00
Guillaume Gomez
fd5427b686 Rollup merge of #87885 - m-ou-se:edition-guide-links, r=rylev
Link to edition guide instead of issues for 2021 lints.

This changes the 2021 lints to not link to github issues, but to the edition guide instead.

Fixes  #86996
2021-08-12 13:25:07 +02:00
flip1995
1ad5464200 Merge commit '7bfc26ec8e7a454786668e7e52ffe527fc649735' into clippyup 2021-08-12 11:16:25 +02:00
Mara Bos
8e563b5468 Bless clippy tests. 2021-08-12 10:48:16 +02:00
Esteban Kuber
652b6a771f update clippy 2021-08-11 14:21:33 +00:00
bors
c9e45e47d5 Auto merge of #86754 - estebank:use-multispans-more, r=varkor
Use `multipart_suggestions` more

Built on top of #86532
2021-07-30 23:18:12 +00:00
Yuki Okushi
0af50b4d32 Rollup merge of #87385 - Aaron1011:final-enable-semi, r=petrochenkov
Make `SEMICOLON_IN_EXPRESSIONS_FROM_MACROS` warn by default

This PR makes the `SEMICOLON_IN_EXPRESSIONS_FROM_MACROS` lint warn by default.

To avoid showing a large number of un-actionable warnings to users, we only enable the lint for macros defined in the same crate. This ensures that users will be able to fix the warning by simply removing a semicolon.

In the future, I'd like to enable this lint unconditionally, and eventually make it into a hard error in a future edition. This PR is a step towards that goal.
2021-07-31 04:09:20 +09:00
Esteban Küber
9a6ae783d4 Use multispan suggestions more often
* Use more accurate span for `async move` suggestion
* Use more accurate span for deref suggestion
* Use `multipart_suggestion` more often
2021-07-30 09:26:31 -07:00
Aaron Hill
967a72196c Remove unnecessary trailing semicolons from clippy tests 2021-07-29 09:52:35 -05:00