rust/library/core/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
..
alloc Consistent spelling of "adapter" in the standard library 2021-07-30 17:23:07 +02:00
array bump bootstrap compiler to 1.55 2021-08-01 11:19:24 -04:00
char Add missing links for core::char types 2021-07-29 14:13:41 +02:00
convert impl const From<num> for num 2021-08-07 19:03:08 +02:00
fmt Rollup merge of #87052 - phlopsi:patch-1, r=jyn514 2021-07-30 16:26:52 +09:00
future Fix may not to appropriate might not or must not 2021-07-29 01:15:20 -04:00
hash Add tracking issue and rename to hash_one 2021-06-24 01:30:48 -07:00
iter Rollup merge of #85835 - Seppel3210:master, r=yaahc 2021-08-12 15:32:53 +09:00
macros Deprecate llvm_asm! 2021-08-15 13:14:32 +01:00
mem Auto merge of #87445 - amalik18:issue-83584-fix, r=kennytm 2021-07-30 04:34:13 +00:00
num Auto merge of #87150 - rusticstuff:simplify_wrapping_neg, r=m-ou-se 2021-08-04 12:58:31 +00:00
ops Fix may not to appropriate might not or must not 2021-07-29 01:15:20 -04:00
panic Fix unused sync::atomic import on targets without atomics 2021-07-31 17:27:29 -07:00
prelude Move asm! and global_asm! to core::arch 2021-07-18 18:30:58 -04:00
ptr Auto merge of #87827 - eddyb:wrapperless-mem-replace, r=m-ou-se 2021-08-08 13:11:09 +00:00
slice Test and fix size_hint for slice's [r]split* iterators 2021-08-12 17:26:03 +02:00
str Fix may not to appropriate might not or must not 2021-07-29 01:15:20 -04:00
stream Add core::stream::from_iter 2021-06-23 17:49:26 +02:00
sync Uplift the invalid_atomic_ordering lint from clippy to rustc 2021-08-16 03:55:27 +00:00
task Update stable version of ready!() macro. 2021-07-28 16:56:12 +02:00
unicode Use HTTPS links where possible 2021-06-23 16:26:46 -04:00
any.rs Added diagnostic items to structs and traits for Clippy 2021-07-15 23:57:02 +02:00
ascii.rs Replace all fmt.pad with debug_struct 2021-04-21 14:38:24 +02:00
bool.rs Fix tracking issue for bool_to_option 2021-07-10 18:43:52 -04:00
borrow.rs Fix borrow and deref 2021-03-03 11:23:29 +01:00
cell.rs fix typo: whenver -> whenever 2021-07-26 22:12:35 +01:00
clone.rs Updates Clone docs for Copy comparison. 2021-06-10 11:28:26 -04:00
cmp.rs Added diagnostic items to functions for Clippy 2021-07-15 23:47:03 +02:00
default.rs bump bootstrap compiler to 1.55 2021-08-01 11:19:24 -04:00
ffi.rs Replace all fmt.pad with debug_struct 2021-04-21 14:38:24 +02:00
hint.rs Allow the use of the deprecated llvm_asm! in black_box 2021-08-15 13:14:32 +01:00
internal_macros.rs Remove unnecessary #[unstable] from internal macro. 2021-08-05 12:55:35 +02:00
intrinsics.rs Implement black_box using intrinsic 2021-08-12 16:16:57 +01:00
lazy.rs Capitalize safety comments 2020-09-08 22:26:44 -04:00
lib.rs impl const From<num> for num 2021-08-07 19:03:08 +02:00
marker.rs Rename variable 2021-06-29 20:26:37 -04:00
option.rs Added tracking issue to unstable attribute 2021-08-09 10:24:03 -05:00
panic.rs Move UnwindSafe, RefUnwindSafe, AssertUnwindSafe to core 2021-07-30 10:42:15 -07:00
panicking.rs Improve comments about const panic handling 2021-07-28 16:18:38 +02:00
pin.rs Fix may not to appropriate might not or must not 2021-07-29 01:15:20 -04:00
primitive.rs mv std libs to library/ 2020-07-27 19:51:13 -05:00
result.rs Add documentation for the order of Option and Result 2021-08-01 13:59:19 +02:00
time.rs Added diagnostic items to structs and traits for Clippy 2021-07-15 23:57:02 +02:00
tuple.rs mv std libs to library/ 2020-07-27 19:51:13 -05:00
unit.rs mv std libs to library/ 2020-07-27 19:51:13 -05:00