From 20431706a863f92cb37dc512fef6e48d192aaf2c Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:11:38 +0200 Subject: Merging upstream version 1.66.0+dfsg1. Signed-off-by: Daniel Baumann --- src/test/ui/statics/issue-17718-static-sync.rs | 12 +++++ src/test/ui/statics/issue-17718-static-sync.stderr | 12 +++++ .../statics/issue-17718-static-unsafe-interior.rs | 52 ++++++++++++++++++++++ src/test/ui/statics/uninhabited-static.stderr | 18 +++++--- 4 files changed, 89 insertions(+), 5 deletions(-) create mode 100644 src/test/ui/statics/issue-17718-static-sync.rs create mode 100644 src/test/ui/statics/issue-17718-static-sync.stderr create mode 100644 src/test/ui/statics/issue-17718-static-unsafe-interior.rs (limited to 'src/test/ui/statics') diff --git a/src/test/ui/statics/issue-17718-static-sync.rs b/src/test/ui/statics/issue-17718-static-sync.rs new file mode 100644 index 000000000..6f278d76b --- /dev/null +++ b/src/test/ui/statics/issue-17718-static-sync.rs @@ -0,0 +1,12 @@ +#![feature(negative_impls)] + +use std::marker::Sync; + +struct Foo; +impl !Sync for Foo {} + +static FOO: usize = 3; +static BAR: Foo = Foo; +//~^ ERROR: `Foo` cannot be shared between threads safely [E0277] + +fn main() {} diff --git a/src/test/ui/statics/issue-17718-static-sync.stderr b/src/test/ui/statics/issue-17718-static-sync.stderr new file mode 100644 index 000000000..bc6e45e59 --- /dev/null +++ b/src/test/ui/statics/issue-17718-static-sync.stderr @@ -0,0 +1,12 @@ +error[E0277]: `Foo` cannot be shared between threads safely + --> $DIR/issue-17718-static-sync.rs:9:13 + | +LL | static BAR: Foo = Foo; + | ^^^ `Foo` cannot be shared between threads safely + | + = help: the trait `Sync` is not implemented for `Foo` + = note: shared static variables must have a type that implements `Sync` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/statics/issue-17718-static-unsafe-interior.rs b/src/test/ui/statics/issue-17718-static-unsafe-interior.rs new file mode 100644 index 000000000..65a8713ba --- /dev/null +++ b/src/test/ui/statics/issue-17718-static-unsafe-interior.rs @@ -0,0 +1,52 @@ +// run-pass +#![allow(dead_code)] +#![allow(unused_variables)] +#![allow(unused_imports)] +// pretty-expanded FIXME #23616 + +use std::marker; +use std::cell::UnsafeCell; + +struct MyUnsafePack(UnsafeCell); + +unsafe impl Sync for MyUnsafePack {} + +struct MyUnsafe { + value: MyUnsafePack +} + +impl MyUnsafe { + fn forbidden(&self) {} +} + +unsafe impl Sync for MyUnsafe {} + +enum UnsafeEnum { + VariantSafe, + VariantUnsafe(UnsafeCell) +} + +unsafe impl Sync for UnsafeEnum {} + +static STATIC1: UnsafeEnum = UnsafeEnum::VariantSafe; + +static STATIC2: MyUnsafePack = MyUnsafePack(UnsafeCell::new(1)); +const CONST: MyUnsafePack = MyUnsafePack(UnsafeCell::new(1)); +static STATIC3: MyUnsafe = MyUnsafe{value: CONST}; + +static STATIC4: &'static MyUnsafePack = &STATIC2; + +struct Wrap { + value: T +} + +unsafe impl Sync for Wrap {} + +static UNSAFE: MyUnsafePack = MyUnsafePack(UnsafeCell::new(2)); +static WRAPPED_UNSAFE: Wrap<&'static MyUnsafePack> = Wrap { value: &UNSAFE }; + +fn main() { + let a = &STATIC1; + + STATIC3.forbidden() +} diff --git a/src/test/ui/statics/uninhabited-static.stderr b/src/test/ui/statics/uninhabited-static.stderr index 88ee4cbdc..ef794bb36 100644 --- a/src/test/ui/statics/uninhabited-static.stderr +++ b/src/test/ui/statics/uninhabited-static.stderr @@ -4,14 +4,14 @@ error: static of uninhabited type LL | static VOID: Void; | ^^^^^^^^^^^^^^^^^ | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #74840 + = note: uninhabited statics cannot be initialized, and any access would be an immediate error note: the lint level is defined here --> $DIR/uninhabited-static.rs:2:9 | LL | #![deny(uninhabited_static)] | ^^^^^^^^^^^^^^^^^^ - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #74840 - = note: uninhabited statics cannot be initialized, and any access would be an immediate error error: static of uninhabited type --> $DIR/uninhabited-static.rs:8:5 @@ -58,8 +58,12 @@ LL | static VOID2: Void = unsafe { std::mem::transmute(()) }; | this code causes undefined behavior when executed | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done | +note: enums with no inhabited variants have no valid value + --> $DIR/uninhabited-static.rs:4:1 + | +LL | enum Void {} + | ^^^^^^^^^ = note: `#[warn(invalid_value)]` on by default - = note: enums with no variants have no valid value error[E0080]: could not evaluate static initializer --> $DIR/uninhabited-static.rs:16:32 @@ -76,7 +80,11 @@ LL | static NEVER2: Void = unsafe { std::mem::transmute(()) }; | this code causes undefined behavior when executed | help: use `MaybeUninit` instead, and only call `assume_init` after initialization is done | - = note: enums with no variants have no valid value +note: enums with no inhabited variants have no valid value + --> $DIR/uninhabited-static.rs:4:1 + | +LL | enum Void {} + | ^^^^^^^^^ error: aborting due to 6 previous errors; 2 warnings emitted -- cgit v1.2.3