rust/compiler/rustc_lint/src
bors 92f3753b07 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
..
nonstandard_style mv compiler to compiler/ 2020-08-30 18:45:07 +03:00
array_into_iter.rs Link to edition guide instead of issues for 2021 lints. 2021-08-09 17:45:01 +02:00
builtin.rs Auto merge of #86492 - hyd-dev:no-mangle-method, r=petrochenkov 2021-08-13 19:47:03 +00:00
context.rs Fix lint capitalization and ignoring, test with include_str 2021-08-04 13:38:17 -04:00
early.rs Add additional missing lint handling logic 2021-07-17 23:03:58 -05:00
internal.rs Auto merge of #86827 - camsteffen:hash-lint-resolved, r=oli-obk 2021-07-13 15:06:10 +00:00
late.rs Add inferred args to typeck 2021-07-25 07:28:51 +00:00
levels.rs Auto merge of #87449 - matthiaskrgr:clippyy_v2, r=nagisa 2021-08-01 09:15:15 +00:00
lib.rs Uplift the invalid_atomic_ordering lint from clippy to rustc 2021-08-16 03:55:27 +00:00
methods.rs Fix doctest 2020-10-26 18:19:49 -04:00
non_ascii_idents.rs Stablize non_ascii_idents feature. 2021-04-08 02:52:00 +08:00
non_fmt_panic.rs Use is_diagnostic_item instead of get_diagnostic_item. 2021-08-13 12:21:31 +02:00
nonstandard_style.rs Adjust #[no_mangle]-related checks and lints for impl items 2021-08-12 17:11:44 +08:00
noop_method_call.rs Warn in doc test 2021-03-03 11:23:33 +01:00
passes.rs Add inferred args to typeck 2021-07-25 07:28:51 +00:00
redundant_semicolon.rs Lint on redundant trailing semicolon after item 2020-12-29 16:30:02 -05:00
tests.rs Update to last upstream version 2021-07-08 17:14:28 +02:00
traits.rs move Constness into TraitPredicate 2021-08-13 09:26:33 +00:00
types.rs Auto merge of #84039 - jyn514:uplift-atomic-ordering, r=wesleywiser 2021-08-16 06:36:13 +00:00
unused.rs Introduce hir::ExprKind::Let - Take 2 2021-08-15 16:18:26 -03:00