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
This commit is contained in:
parent
7069a8c2b7
commit
402a9c9f5e
28 changed files with 655 additions and 455 deletions
30
src/test/ui/lint/lint-invalid-atomic-ordering-ptr.rs
Normal file
30
src/test/ui/lint/lint-invalid-atomic-ordering-ptr.rs
Normal file
|
@ -0,0 +1,30 @@
|
|||
// only-x86_64
|
||||
use std::sync::atomic::{AtomicPtr, Ordering};
|
||||
|
||||
fn main() {
|
||||
let ptr = &mut 5;
|
||||
let other_ptr = &mut 10;
|
||||
let x = AtomicPtr::new(ptr);
|
||||
|
||||
// Allowed load ordering modes
|
||||
let _ = x.load(Ordering::Acquire);
|
||||
let _ = x.load(Ordering::SeqCst);
|
||||
let _ = x.load(Ordering::Relaxed);
|
||||
|
||||
// Disallowed load ordering modes
|
||||
let _ = x.load(Ordering::Release);
|
||||
//~^ ERROR atomic loads cannot have `Release` or `AcqRel` ordering
|
||||
let _ = x.load(Ordering::AcqRel);
|
||||
//~^ ERROR atomic loads cannot have `Release` or `AcqRel` ordering
|
||||
|
||||
// Allowed store ordering modes
|
||||
x.store(other_ptr, Ordering::Release);
|
||||
x.store(other_ptr, Ordering::SeqCst);
|
||||
x.store(other_ptr, Ordering::Relaxed);
|
||||
|
||||
// Disallowed store ordering modes
|
||||
x.store(other_ptr, Ordering::Acquire);
|
||||
//~^ ERROR atomic stores cannot have `Acquire` or `AcqRel` ordering
|
||||
x.store(other_ptr, Ordering::AcqRel);
|
||||
//~^ ERROR atomic stores cannot have `Acquire` or `AcqRel` ordering
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue