realize that a test case is incorrect

`Mutex<*const _>` doesn't make a lot of sense (there can be no
contention over a read-only reference), but `AtomicPtr::new(*const _)`
straight up doesn't compile
This commit is contained in:
Ada Alakbarova 2025-09-08 01:05:38 +02:00
parent 99ce6391dd
commit e5fd571414
No known key found for this signature in database
3 changed files with 5 additions and 11 deletions

View file

@ -5,6 +5,7 @@ use clippy_utils::ty::ty_from_hir_ty;
use rustc_errors::{Applicability, Diag};
use rustc_hir::{Expr, ExprKind, Item, ItemKind, LetStmt, QPath};
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::mir::Mutability;
use rustc_middle::ty::{self, IntTy, Ty, UintTy};
use rustc_session::declare_lint_pass;
use rustc_span::sym;
@ -169,7 +170,8 @@ fn get_atomic_name(ty: Ty<'_>) -> Option<&'static str> {
IntTy::I128 => None,
}
},
ty::RawPtr(_, _) => Some("AtomicPtr"),
// `AtomicPtr` only accepts `*mut T`
ty::RawPtr(_, Mutability::Mut) => Some("AtomicPtr"),
_ => None,
}
}

View file

@ -16,8 +16,8 @@ fn main() {
//~^ mutex_atomic
let mut x = 4u32;
// `AtomicPtr` only accepts `*mut T`, so this should not lint
let _ = Mutex::new(&x as *const u32);
//~^ mutex_atomic
let _ = Mutex::new(&mut x as *mut u32);
//~^ mutex_atomic

View file

@ -24,14 +24,6 @@ LL | let _ = Mutex::new(9isize);
|
= help: if you just want the locking behavior and not the internal type, consider using `Mutex<()>`
error: using a `Mutex` where an atomic would do
--> tests/ui/mutex_atomic.rs:19:13
|
LL | let _ = Mutex::new(&x as *const u32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::sync::atomic::AtomicPtr::new(&x as *const u32)`
|
= help: if you just want the locking behavior and not the internal type, consider using `Mutex<()>`
error: using a `Mutex` where an atomic would do
--> tests/ui/mutex_atomic.rs:22:13
|
@ -115,5 +107,5 @@ LL | let reassigned = mtx;
= help: consider using an `AtomicI32` instead
= help: if you just want the locking behavior and not the internal type, consider using `Mutex<()>`
error: aborting due to 14 previous errors
error: aborting due to 13 previous errors