Uplift the invalid_atomic_ordering lint from clippy to rustc#84039
Uplift the invalid_atomic_ordering lint from clippy to rustc#84039bors merged 2 commits intorust-lang:masterfrom
Conversation
|
Some changes occurred in src/tools/clippy. cc @rust-lang/clippy |
|
cc @thomcc |
|
Oh also the clippy deprecation will conflict with rust-lang/rust-clippy#7056; I expect there will be a subtree sync before fcp finishes though so it shouldn't be a big deal. |
This comment has been minimized.
This comment has been minimized.
|
I am not sure why CI is failing :( I think it has something to do with |
|
Hey, thanks for taking this over and carrying it over the finish line. I had struggled a few times with the rebase, since I'm mostly unfamiliar with rustc and clippy, and generally didn't have the time to dedicate to it at the moment. Still, will be super thrilled to see it land, it will make atomic stuff way easier to teach, if nothing else! |
compiler/rustc_lint/src/types.rs
Outdated
There was a problem hiding this comment.
This is a growing pattern in Clippy that is now moving to rustc. Should we have a tcx.get_diagnostic_name(def_id)?
Or, alternatively...
if cx.tcx.is_diagnostic_item(sym::atomic_mod, cx.tcx.parent(did)) {
if matches!(cx.tcx.item_name(did), sym::AtomicU8 | sym::AtomicBool | ..) {There was a problem hiding this comment.
It already exists: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyCtxt.html#method.get_diagnostic_item
It has a warning that it's slower than is_diagnostic_item (presumably because it invalids more of the incremental cache). Should I use it anyway?
There was a problem hiding this comment.
Also, I'm not sure what you're suggesting the new code should look like. Don't I need to check all the types in the array no matter what?
There was a problem hiding this comment.
It already exists
That gets a DefId from a name. I'm suggesting the opposite.
My second suggestion is to make the parent module a diagnostic item instead of the types and then just check the name of the type.
compiler/rustc_lint/src/types.rs
Outdated
There was a problem hiding this comment.
It would be better short-circuiting to check the method name before the type.
There was a problem hiding this comment.
Unfortunately that panics if the method name is the same but the type doesn't match, because it assumes the call has at least 2/3 args.
There was a problem hiding this comment.
Err actually it panics with or without that change; let me look into it.
There was a problem hiding this comment.
@lcnr why was the UI test you suggested valid? Shouldn't inherent impls always take precedence over trait impls? nightly rustc accepts it, but I don't know why :/
compiler/rustc_lint/Cargo.toml
Outdated
There was a problem hiding this comment.
I would prefer that we try to keep our external dependencies as small as possible and this doesn't seem like a necessary addition to me but we have no official policy saying that, so I don't think it should hold up this PR.
There was a problem hiding this comment.
@wesleywiser if_chain is already in the source tree through clippy, this just adds it to rustc itself. I could rewrite it without if_chain, but it would be annoying and IMO a lot uglier.
There was a problem hiding this comment.
Yes, that's true but clippy isn't a dependency of rustc so any dependencies they pull in don't actually affect rustc. That's why you had to add it to the tidy allowed set of dependencies.
It's my personal preference and we already have quite a lot of external dependencies as that list showed so don't worry about it 🙂
40b4b00 to
caa95ff
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
daf3ddf to
116d14b
Compare
|
don't have a lot of capacity rn and this is out of cache for me r? @estebank in case you have the time, otherwise I can probably get to this next weekend |
|
Sync PR is up: #84427 |
|
I think this is mostly done from an implementation standpoint. @rust-lang/lang does this need an FCP? If so, could someone start one? |
This comment has been minimized.
This comment has been minimized.
|
⌛ Testing commit 768e85bbc5f8001b70bb13c37f0777b4ed232500 with merge f530f4975433fbc8a6bc2318fd508a50c0852372... |
This comment has been minimized.
This comment has been minimized.
|
💔 Test failed - checks-actions |
|
☔ The latest upstream changes (presumably #87579) made this pull request unmergeable. Please resolve the merge conflicts. |
|
@wesleywiser do you know why this is still running on android? I have |
|
I'm not sure. It seems like that should work as compiletest is getting invoked with the correct target flag. Maybe try adding |
|
@bors r=wesleywiser rollup=never |
|
📌 Commit f1ee65e609789518247d9c8b35050f7941a2e9d4 has been approved by |
This comment has been minimized.
This comment has been minimized.
|
⌛ Testing commit f1ee65e609789518247d9c8b35050f7941a2e9d4 with merge 677762189fe82d44347708c21a7eef0e65e5fad4... |
This comment has been minimized.
This comment has been minimized.
|
💔 Test failed - checks-actions |
|
@bors r=wesleywiser rollup=never |
|
📌 Commit 95f4920a398d3900974a49259b8ee7fc4ec7190e has been approved by |
|
⌛ Testing commit 95f4920a398d3900974a49259b8ee7fc4ec7190e with merge 41d8c0eb647dd7026d752da6a7dcf871c589dffe... |
This comment has been minimized.
This comment has been minimized.
|
💔 Test failed - checks-actions |
|
I give up. I have no idea what's wrong and I am not willing to put more time into it. |
|
Oh. For some reason there are like 12 files that all test the same thing, and I only added |
- 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
|
@bors r=wesleywiser |
|
📌 Commit 5522177 has been approved by |
|
☀️ Test successful - checks-actions |
|
Woohoo! Congrats @jyn514 🎉 |
This is mostly just a rebase of #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 rust-lang/compiler-team#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
Orderingisn'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 @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 in the following ways:
Symbolsandrustc_diagnostic_items instead of string literals.rustc_diagnostic_item, which would have complicated an already big macro.ReleaseandAcqRelordering" => "loads cannot haveReleaseorAcqRelordering")match_ordering_def_path=>matches_ordering_def_path),cx.struct_span_lintvs clippy'sspan_lint_and_helphelper).Potential issues
(This is just about the code in this PR, not conceptual issues with the lint or anything)
I'm not sure if I should have used a diagnostic item for
Orderingand its variants (I couldn't figure out how really, so if I should do this some pointers would be appreciated).match_def_pathworks and if it has any pitfalls like that, so maybe not.I think I deprecated the lint in clippy (CC @flip1995 who asked to be notified about clippy changes in the future in this comment) but I'm not sure if I need to do anything else there.
x.py test src/tools/clippyfails with a lot of errors with and without my changes (and is probably a nonsense command regardless). Runningcargo testfrom src/tools/clippy also fails with unrelated errors that seem like refactorings that didnt update clippy? So, honestly no clue.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.
It pulls in the
if_chaincrate. 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).