summaryrefslogtreecommitdiffstats
path: root/src/test/ui/statics
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/ui/statics')
-rw-r--r--src/test/ui/statics/issue-17718-static-sync.rs12
-rw-r--r--src/test/ui/statics/issue-17718-static-sync.stderr12
-rw-r--r--src/test/ui/statics/issue-17718-static-unsafe-interior.rs52
-rw-r--r--src/test/ui/statics/uninhabited-static.stderr18
4 files changed, 89 insertions, 5 deletions
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<T>(UnsafeCell<T>);
+
+unsafe impl<T: Send> Sync for MyUnsafePack<T> {}
+
+struct MyUnsafe<T> {
+ value: MyUnsafePack<T>
+}
+
+impl<T> MyUnsafe<T> {
+ fn forbidden(&self) {}
+}
+
+unsafe impl<T: Send> Sync for MyUnsafe<T> {}
+
+enum UnsafeEnum<T> {
+ VariantSafe,
+ VariantUnsafe(UnsafeCell<T>)
+}
+
+unsafe impl<T: Send> Sync for UnsafeEnum<T> {}
+
+static STATIC1: UnsafeEnum<isize> = UnsafeEnum::VariantSafe;
+
+static STATIC2: MyUnsafePack<isize> = MyUnsafePack(UnsafeCell::new(1));
+const CONST: MyUnsafePack<isize> = MyUnsafePack(UnsafeCell::new(1));
+static STATIC3: MyUnsafe<isize> = MyUnsafe{value: CONST};
+
+static STATIC4: &'static MyUnsafePack<isize> = &STATIC2;
+
+struct Wrap<T> {
+ value: T
+}
+
+unsafe impl<T: Send> Sync for Wrap<T> {}
+
+static UNSAFE: MyUnsafePack<isize> = MyUnsafePack(UnsafeCell::new(2));
+static WRAPPED_UNSAFE: Wrap<&'static MyUnsafePack<isize>> = 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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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<T>` 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<T>` 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