diff --git a/tests/ui/stdlib-unit-tests/atomic-from-mut-not-available.alignment_matches.stderr b/tests/ui/stdlib-unit-tests/atomic-from-mut-not-available.alignment_matches.stderr new file mode 100644 index 0000000000000..109985c005286 --- /dev/null +++ b/tests/ui/stdlib-unit-tests/atomic-from-mut-not-available.alignment_matches.stderr @@ -0,0 +1,13 @@ +error[E0658]: use of unstable library feature `atomic_from_mut` + --> $DIR/atomic-from-mut-not-available.rs:24:5 + | +LL | core::sync::atomic::AtomicU64::from_mut(&mut 0u64); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #76314 for more information + = help: add `#![feature(atomic_from_mut)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/stdlib-unit-tests/atomic-from-mut-not-available.alignment_mismatch.stderr b/tests/ui/stdlib-unit-tests/atomic-from-mut-not-available.alignment_mismatch.stderr new file mode 100644 index 0000000000000..47b17f9fcd7ad --- /dev/null +++ b/tests/ui/stdlib-unit-tests/atomic-from-mut-not-available.alignment_mismatch.stderr @@ -0,0 +1,17 @@ +error[E0599]: no function or associated item named `from_mut` found for struct `AtomicU64` in the current scope + --> $DIR/atomic-from-mut-not-available.rs:24:36 + | +LL | core::sync::atomic::AtomicU64::from_mut(&mut 0u64); + | ^^^^^^^^ function or associated item not found in `AtomicU64` + | +note: if you're trying to build a new `AtomicU64`, consider using `AtomicU64::new` which returns `AtomicU64` + --> $SRC_DIR/core/src/sync/atomic.rs:LL:COL + = note: this error originates in the macro `atomic_int` (in Nightly builds, run with -Z macro-backtrace for more info) +help: there is an associated function `from` with a similar name + | +LL | core::sync::atomic::AtomicU64::from(&mut 0u64); + | ~~~~ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0599`. diff --git a/tests/ui/stdlib-unit-tests/atomic-from-mut-not-available.rs b/tests/ui/stdlib-unit-tests/atomic-from-mut-not-available.rs index 8326187838a20..7e9de3570eb91 100644 --- a/tests/ui/stdlib-unit-tests/atomic-from-mut-not-available.rs +++ b/tests/ui/stdlib-unit-tests/atomic-from-mut-not-available.rs @@ -1,7 +1,27 @@ -//@ only-x86 -//@ only-linux +//! This test exercises the combined effect of the `cfg(target_has_atomic_equal_alignment = "...")` +//! implementation in the compiler plus usage of said `cfg(target_has_atomic_equal_alignment)` in +//! `core` for the `Atomic64::from_mut` API. +//! +//! This test is a basic smoke test: that `AtomicU64::from_mut` is gated by +//! `#[cfg(target_has_atomic_equal_alignment = "8")]`, which is only available on platforms where +//! `AtomicU64` has the same alignment as `u64`. This is notably *not* satisfied by `x86_32`, where +//! they have differing alignments. Thus, `AtomicU64::from_mut` should *not* be available on +//! `x86_32` linux and should report assoc item not found, if the `cfg` is working correctly. +//! Conversely, `AtomicU64::from_mut` *should* be available on `x86_64` linux where the alignment +//! matches. + +//@ revisions: alignment_mismatch alignment_matches + +// This should fail on 32-bit x86 linux... +//@[alignment_mismatch] only-x86 +//@[alignment_mismatch] only-linux + +// ... but pass on 64-bit x86_64 linux. +//@[alignment_matches] only-x86_64 +//@[alignment_matches] only-linux fn main() { core::sync::atomic::AtomicU64::from_mut(&mut 0u64); - //~^ ERROR: no function or associated item named `from_mut` found for struct `AtomicU64` + //[alignment_mismatch]~^ ERROR no function or associated item named `from_mut` found for struct `AtomicU64` + //[alignment_matches]~^^ ERROR use of unstable library feature `atomic_from_mut` }