summaryrefslogtreecommitdiffstats
path: root/tests/ui/static
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
commit64d98f8ee037282c35007b64c2649055c56af1db (patch)
tree5492bcf97fce41ee1c0b1cc2add283f3e66cdab0 /tests/ui/static
parentAdding debian version 1.67.1+dfsg1-1. (diff)
downloadrustc-64d98f8ee037282c35007b64c2649055c56af1db.tar.xz
rustc-64d98f8ee037282c35007b64c2649055c56af1db.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/static')
-rw-r--r--tests/ui/static/auxiliary/extern-statics.rs4
-rw-r--r--tests/ui/static/auxiliary/issue_24843.rs1
-rw-r--r--tests/ui/static/auxiliary/nested_item.rs30
-rw-r--r--tests/ui/static/auxiliary/static-priv-by-default.rs27
-rw-r--r--tests/ui/static/auxiliary/static_priv_by_default.rs51
-rw-r--r--tests/ui/static/bad-const-type.rs4
-rw-r--r--tests/ui/static/bad-const-type.stderr11
-rw-r--r--tests/ui/static/issue-18118-2.rs6
-rw-r--r--tests/ui/static/issue-18118-2.stderr11
-rw-r--r--tests/ui/static/issue-18118.rs6
-rw-r--r--tests/ui/static/issue-18118.stderr14
-rw-r--r--tests/ui/static/issue-24843.rs8
-rw-r--r--tests/ui/static/issue-34194.rs11
-rw-r--r--tests/ui/static/issue-5216.rs10
-rw-r--r--tests/ui/static/issue-5216.stderr28
-rw-r--r--tests/ui/static/nested_item_main.rs10
-rw-r--r--tests/ui/static/refer-to-other-statics-by-value.rs8
-rw-r--r--tests/ui/static/safe-extern-statics-mut.mir.stderr35
-rw-r--r--tests/ui/static/safe-extern-statics-mut.rs17
-rw-r--r--tests/ui/static/safe-extern-statics-mut.thir.stderr35
-rw-r--r--tests/ui/static/safe-extern-statics.mir.stderr35
-rw-r--r--tests/ui/static/safe-extern-statics.rs17
-rw-r--r--tests/ui/static/safe-extern-statics.thir.stderr35
-rw-r--r--tests/ui/static/static-closures.rs4
-rw-r--r--tests/ui/static/static-closures.stderr9
-rw-r--r--tests/ui/static/static-drop-scope.rs37
-rw-r--r--tests/ui/static/static-drop-scope.stderr89
-rw-r--r--tests/ui/static/static-extern-type.rs27
-rw-r--r--tests/ui/static/static-items-cant-move.rs19
-rw-r--r--tests/ui/static/static-items-cant-move.stderr9
-rw-r--r--tests/ui/static/static-lifetime-bound.rs6
-rw-r--r--tests/ui/static/static-lifetime-bound.stderr22
-rw-r--r--tests/ui/static/static-lifetime.rs6
-rw-r--r--tests/ui/static/static-lifetime.stderr16
-rw-r--r--tests/ui/static/static-method-privacy.rs10
-rw-r--r--tests/ui/static/static-method-privacy.stderr12
-rw-r--r--tests/ui/static/static-mut-bad-types.rs7
-rw-r--r--tests/ui/static/static-mut-bad-types.stderr12
-rw-r--r--tests/ui/static/static-mut-foreign-requires-unsafe.mir.stderr27
-rw-r--r--tests/ui/static/static-mut-foreign-requires-unsafe.rs12
-rw-r--r--tests/ui/static/static-mut-foreign-requires-unsafe.thir.stderr27
-rw-r--r--tests/ui/static/static-mut-not-constant.rs6
-rw-r--r--tests/ui/static/static-mut-not-constant.stderr9
-rw-r--r--tests/ui/static/static-mut-not-pat.rs43
-rw-r--r--tests/ui/static/static-mut-not-pat.stderr21
-rw-r--r--tests/ui/static/static-mut-requires-unsafe.mir.stderr27
-rw-r--r--tests/ui/static/static-mut-requires-unsafe.rs10
-rw-r--r--tests/ui/static/static-mut-requires-unsafe.thir.stderr27
-rw-r--r--tests/ui/static/static-priv-by-default2.rs30
-rw-r--r--tests/ui/static/static-priv-by-default2.stderr27
-rw-r--r--tests/ui/static/static-reference-to-fn-1.rs24
-rw-r--r--tests/ui/static/static-reference-to-fn-1.stderr12
-rw-r--r--tests/ui/static/static-reference-to-fn-2.rs54
-rw-r--r--tests/ui/static/static-reference-to-fn-2.stderr49
-rw-r--r--tests/ui/static/static-region-bound.rs12
-rw-r--r--tests/ui/static/static-region-bound.stderr13
-rw-r--r--tests/ui/static/static-vec-repeat-not-constant.rs6
-rw-r--r--tests/ui/static/static-vec-repeat-not-constant.stderr12
-rw-r--r--tests/ui/static/static_sized_requirement.rs12
-rw-r--r--tests/ui/static/thread-local-in-ctfe.rs23
-rw-r--r--tests/ui/static/thread-local-in-ctfe.stderr33
61 files changed, 1215 insertions, 0 deletions
diff --git a/tests/ui/static/auxiliary/extern-statics.rs b/tests/ui/static/auxiliary/extern-statics.rs
new file mode 100644
index 000000000..c090bc79f
--- /dev/null
+++ b/tests/ui/static/auxiliary/extern-statics.rs
@@ -0,0 +1,4 @@
+extern "C" {
+ pub static XA: u8;
+ pub static mut XB: u8;
+}
diff --git a/tests/ui/static/auxiliary/issue_24843.rs b/tests/ui/static/auxiliary/issue_24843.rs
new file mode 100644
index 000000000..6ca04f860
--- /dev/null
+++ b/tests/ui/static/auxiliary/issue_24843.rs
@@ -0,0 +1 @@
+pub static TEST_STR: &'static str = "Hello world";
diff --git a/tests/ui/static/auxiliary/nested_item.rs b/tests/ui/static/auxiliary/nested_item.rs
new file mode 100644
index 000000000..9db9d19d6
--- /dev/null
+++ b/tests/ui/static/auxiliary/nested_item.rs
@@ -0,0 +1,30 @@
+// original problem
+pub fn foo<T>() -> isize {
+ {
+ static foo: isize = 2;
+ foo
+ }
+}
+
+// issue 8134
+struct Foo;
+impl Foo {
+ pub fn foo<T>(&self) {
+ static X: usize = 1;
+ }
+}
+
+// issue 8134
+pub struct Parser<T>(T);
+impl<T: std::iter::Iterator<Item=char>> Parser<T> {
+ fn in_doctype(&mut self) {
+ static DOCTYPEPattern: [char; 6] = ['O', 'C', 'T', 'Y', 'P', 'E'];
+ }
+}
+
+struct Bar;
+impl Foo {
+ pub fn bar<T>(&self) {
+ static X: usize = 1;
+ }
+}
diff --git a/tests/ui/static/auxiliary/static-priv-by-default.rs b/tests/ui/static/auxiliary/static-priv-by-default.rs
new file mode 100644
index 000000000..41f368f46
--- /dev/null
+++ b/tests/ui/static/auxiliary/static-priv-by-default.rs
@@ -0,0 +1,27 @@
+// aux-build:static_priv_by_default.rs
+
+extern crate static_priv_by_default;
+
+mod child {
+ pub mod childs_child {
+ static private: isize = 0;
+ pub static public: isize = 0;
+ }
+}
+
+fn foo(_: isize) {}
+
+fn full_ref() {
+ foo(static_priv_by_default::private); //~ ERROR: static `private` is private
+ foo(static_priv_by_default::public);
+ foo(child::childs_child::private); //~ ERROR: static `private` is private
+ foo(child::childs_child::public);
+}
+
+fn medium_ref() {
+ use child::childs_child;
+ foo(childs_child::private); //~ ERROR: static `private` is private
+ foo(childs_child::public);
+}
+
+fn main() {}
diff --git a/tests/ui/static/auxiliary/static_priv_by_default.rs b/tests/ui/static/auxiliary/static_priv_by_default.rs
new file mode 100644
index 000000000..39f912066
--- /dev/null
+++ b/tests/ui/static/auxiliary/static_priv_by_default.rs
@@ -0,0 +1,51 @@
+#![crate_type = "lib"]
+
+static private: isize = 0;
+pub static public: isize = 0;
+
+pub struct A(());
+
+impl A {
+ fn foo() {}
+}
+
+mod foo {
+ pub static a: isize = 0;
+ pub fn b() {}
+ pub struct c;
+ pub enum d {}
+ pub type e = isize;
+
+ pub struct A(());
+
+ impl A {
+ fn foo() {}
+ }
+
+ // these are public so the parent can re-export them.
+ pub static reexported_a: isize = 0;
+ pub fn reexported_b() {}
+ pub struct reexported_c;
+ pub enum reexported_d {}
+ pub type reexported_e = isize;
+}
+
+pub mod bar {
+ pub use foo::reexported_a as e;
+ pub use foo::reexported_b as f;
+ pub use foo::reexported_c as g;
+ pub use foo::reexported_d as h;
+ pub use foo::reexported_e as i;
+}
+
+pub static a: isize = 0;
+pub fn b() {}
+pub struct c;
+pub enum d {}
+pub type e = isize;
+
+static j: isize = 0;
+fn k() {}
+struct l;
+enum m {}
+type n = isize;
diff --git a/tests/ui/static/bad-const-type.rs b/tests/ui/static/bad-const-type.rs
new file mode 100644
index 000000000..934ee353d
--- /dev/null
+++ b/tests/ui/static/bad-const-type.rs
@@ -0,0 +1,4 @@
+static i: String = 10;
+//~^ ERROR mismatched types
+//~| expected struct `String`, found integer
+fn main() { println!("{}", i); }
diff --git a/tests/ui/static/bad-const-type.stderr b/tests/ui/static/bad-const-type.stderr
new file mode 100644
index 000000000..dcc1ee07c
--- /dev/null
+++ b/tests/ui/static/bad-const-type.stderr
@@ -0,0 +1,11 @@
+error[E0308]: mismatched types
+ --> $DIR/bad-const-type.rs:1:20
+ |
+LL | static i: String = 10;
+ | ^^- help: try using a conversion method: `.to_string()`
+ | |
+ | expected struct `String`, found integer
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/tests/ui/static/issue-18118-2.rs b/tests/ui/static/issue-18118-2.rs
new file mode 100644
index 000000000..f712a2eed
--- /dev/null
+++ b/tests/ui/static/issue-18118-2.rs
@@ -0,0 +1,6 @@
+pub fn main() {
+ const z: &'static isize = {
+ static p: isize = 3;
+ &p //~ ERROR constants cannot refer to statics
+ };
+}
diff --git a/tests/ui/static/issue-18118-2.stderr b/tests/ui/static/issue-18118-2.stderr
new file mode 100644
index 000000000..4fc3ca78f
--- /dev/null
+++ b/tests/ui/static/issue-18118-2.stderr
@@ -0,0 +1,11 @@
+error[E0013]: constants cannot refer to statics
+ --> $DIR/issue-18118-2.rs:4:10
+ |
+LL | &p
+ | ^
+ |
+ = help: consider extracting the value of the `static` to a `const`, and referring to that
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0013`.
diff --git a/tests/ui/static/issue-18118.rs b/tests/ui/static/issue-18118.rs
new file mode 100644
index 000000000..f58a3de28
--- /dev/null
+++ b/tests/ui/static/issue-18118.rs
@@ -0,0 +1,6 @@
+pub fn main() {
+ const z: &'static isize = {
+ let p = 3;
+ &p //~ ERROR `p` does not live long enough
+ };
+}
diff --git a/tests/ui/static/issue-18118.stderr b/tests/ui/static/issue-18118.stderr
new file mode 100644
index 000000000..49798a148
--- /dev/null
+++ b/tests/ui/static/issue-18118.stderr
@@ -0,0 +1,14 @@
+error[E0597]: `p` does not live long enough
+ --> $DIR/issue-18118.rs:4:9
+ |
+LL | &p
+ | ^^
+ | |
+ | borrowed value does not live long enough
+ | using this value as a constant requires that `p` is borrowed for `'static`
+LL | };
+ | - `p` dropped here while still borrowed
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0597`.
diff --git a/tests/ui/static/issue-24843.rs b/tests/ui/static/issue-24843.rs
new file mode 100644
index 000000000..0b3397e21
--- /dev/null
+++ b/tests/ui/static/issue-24843.rs
@@ -0,0 +1,8 @@
+// aux-build: issue_24843.rs
+// check-pass
+
+extern crate issue_24843;
+
+static _TEST_STR_2: &'static str = &issue_24843::TEST_STR;
+
+fn main() {}
diff --git a/tests/ui/static/issue-34194.rs b/tests/ui/static/issue-34194.rs
new file mode 100644
index 000000000..6dce556e9
--- /dev/null
+++ b/tests/ui/static/issue-34194.rs
@@ -0,0 +1,11 @@
+// build-pass
+#![allow(dead_code)]
+
+struct A {
+ a: &'static (),
+}
+
+static B: &'static A = &A { a: &() };
+static C: &'static A = &B;
+
+fn main() {}
diff --git a/tests/ui/static/issue-5216.rs b/tests/ui/static/issue-5216.rs
new file mode 100644
index 000000000..4072a57cb
--- /dev/null
+++ b/tests/ui/static/issue-5216.rs
@@ -0,0 +1,10 @@
+fn f() { }
+struct S(Box<dyn FnMut() + Sync>);
+pub static C: S = S(f); //~ ERROR mismatched types
+
+
+fn g() { }
+type T = Box<dyn FnMut() + Sync>;
+pub static D: T = g; //~ ERROR mismatched types
+
+fn main() {}
diff --git a/tests/ui/static/issue-5216.stderr b/tests/ui/static/issue-5216.stderr
new file mode 100644
index 000000000..1afff28f0
--- /dev/null
+++ b/tests/ui/static/issue-5216.stderr
@@ -0,0 +1,28 @@
+error[E0308]: mismatched types
+ --> $DIR/issue-5216.rs:3:21
+ |
+LL | pub static C: S = S(f);
+ | - ^ expected struct `Box`, found fn item
+ | |
+ | arguments to this struct are incorrect
+ |
+ = note: expected struct `Box<(dyn FnMut() + Sync + 'static)>`
+ found fn item `fn() {f}`
+note: tuple struct defined here
+ --> $DIR/issue-5216.rs:2:8
+ |
+LL | struct S(Box<dyn FnMut() + Sync>);
+ | ^
+
+error[E0308]: mismatched types
+ --> $DIR/issue-5216.rs:8:19
+ |
+LL | pub static D: T = g;
+ | ^ expected struct `Box`, found fn item
+ |
+ = note: expected struct `Box<(dyn FnMut() + Sync + 'static)>`
+ found fn item `fn() {g}`
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/tests/ui/static/nested_item_main.rs b/tests/ui/static/nested_item_main.rs
new file mode 100644
index 000000000..2fe00aede
--- /dev/null
+++ b/tests/ui/static/nested_item_main.rs
@@ -0,0 +1,10 @@
+// run-pass
+// aux-build:nested_item.rs
+
+
+extern crate nested_item;
+
+pub fn main() {
+ assert_eq!(2, nested_item::foo::<()>());
+ assert_eq!(2, nested_item::foo::<isize>());
+}
diff --git a/tests/ui/static/refer-to-other-statics-by-value.rs b/tests/ui/static/refer-to-other-statics-by-value.rs
new file mode 100644
index 000000000..90f1980f8
--- /dev/null
+++ b/tests/ui/static/refer-to-other-statics-by-value.rs
@@ -0,0 +1,8 @@
+// run-pass
+
+static A: usize = 42;
+static B: usize = A;
+
+fn main() {
+ assert_eq!(B, 42);
+}
diff --git a/tests/ui/static/safe-extern-statics-mut.mir.stderr b/tests/ui/static/safe-extern-statics-mut.mir.stderr
new file mode 100644
index 000000000..cec5f9d9c
--- /dev/null
+++ b/tests/ui/static/safe-extern-statics-mut.mir.stderr
@@ -0,0 +1,35 @@
+error[E0133]: use of mutable static is unsafe and requires unsafe function or block
+ --> $DIR/safe-extern-statics-mut.rs:13:13
+ |
+LL | let b = B;
+ | ^ use of mutable static
+ |
+ = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior
+
+error[E0133]: use of mutable static is unsafe and requires unsafe function or block
+ --> $DIR/safe-extern-statics-mut.rs:14:14
+ |
+LL | let rb = &B;
+ | ^^ use of mutable static
+ |
+ = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior
+
+error[E0133]: use of mutable static is unsafe and requires unsafe function or block
+ --> $DIR/safe-extern-statics-mut.rs:15:14
+ |
+LL | let xb = XB;
+ | ^^ use of mutable static
+ |
+ = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior
+
+error[E0133]: use of mutable static is unsafe and requires unsafe function or block
+ --> $DIR/safe-extern-statics-mut.rs:16:15
+ |
+LL | let xrb = &XB;
+ | ^^^ use of mutable static
+ |
+ = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior
+
+error: aborting due to 4 previous errors
+
+For more information about this error, try `rustc --explain E0133`.
diff --git a/tests/ui/static/safe-extern-statics-mut.rs b/tests/ui/static/safe-extern-statics-mut.rs
new file mode 100644
index 000000000..389a4589a
--- /dev/null
+++ b/tests/ui/static/safe-extern-statics-mut.rs
@@ -0,0 +1,17 @@
+// aux-build:extern-statics.rs
+// revisions: mir thir
+// [thir]compile-flags: -Z thir-unsafeck
+
+extern crate extern_statics;
+use extern_statics::*;
+
+extern "C" {
+ static mut B: u8;
+}
+
+fn main() {
+ let b = B; //~ ERROR use of mutable static is unsafe
+ let rb = &B; //~ ERROR use of mutable static is unsafe
+ let xb = XB; //~ ERROR use of mutable static is unsafe
+ let xrb = &XB; //~ ERROR use of mutable static is unsafe
+}
diff --git a/tests/ui/static/safe-extern-statics-mut.thir.stderr b/tests/ui/static/safe-extern-statics-mut.thir.stderr
new file mode 100644
index 000000000..8e6d2805a
--- /dev/null
+++ b/tests/ui/static/safe-extern-statics-mut.thir.stderr
@@ -0,0 +1,35 @@
+error[E0133]: use of mutable static is unsafe and requires unsafe function or block
+ --> $DIR/safe-extern-statics-mut.rs:13:13
+ |
+LL | let b = B;
+ | ^ use of mutable static
+ |
+ = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior
+
+error[E0133]: use of mutable static is unsafe and requires unsafe function or block
+ --> $DIR/safe-extern-statics-mut.rs:14:15
+ |
+LL | let rb = &B;
+ | ^ use of mutable static
+ |
+ = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior
+
+error[E0133]: use of mutable static is unsafe and requires unsafe function or block
+ --> $DIR/safe-extern-statics-mut.rs:15:14
+ |
+LL | let xb = XB;
+ | ^^ use of mutable static
+ |
+ = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior
+
+error[E0133]: use of mutable static is unsafe and requires unsafe function or block
+ --> $DIR/safe-extern-statics-mut.rs:16:16
+ |
+LL | let xrb = &XB;
+ | ^^ use of mutable static
+ |
+ = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior
+
+error: aborting due to 4 previous errors
+
+For more information about this error, try `rustc --explain E0133`.
diff --git a/tests/ui/static/safe-extern-statics.mir.stderr b/tests/ui/static/safe-extern-statics.mir.stderr
new file mode 100644
index 000000000..102abd081
--- /dev/null
+++ b/tests/ui/static/safe-extern-statics.mir.stderr
@@ -0,0 +1,35 @@
+error[E0133]: use of extern static is unsafe and requires unsafe function or block
+ --> $DIR/safe-extern-statics.rs:13:13
+ |
+LL | let a = A;
+ | ^ use of extern static
+ |
+ = note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior
+
+error[E0133]: use of extern static is unsafe and requires unsafe function or block
+ --> $DIR/safe-extern-statics.rs:14:14
+ |
+LL | let ra = &A;
+ | ^^ use of extern static
+ |
+ = note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior
+
+error[E0133]: use of extern static is unsafe and requires unsafe function or block
+ --> $DIR/safe-extern-statics.rs:15:14
+ |
+LL | let xa = XA;
+ | ^^ use of extern static
+ |
+ = note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior
+
+error[E0133]: use of extern static is unsafe and requires unsafe function or block
+ --> $DIR/safe-extern-statics.rs:16:15
+ |
+LL | let xra = &XA;
+ | ^^^ use of extern static
+ |
+ = note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior
+
+error: aborting due to 4 previous errors
+
+For more information about this error, try `rustc --explain E0133`.
diff --git a/tests/ui/static/safe-extern-statics.rs b/tests/ui/static/safe-extern-statics.rs
new file mode 100644
index 000000000..0aa90c442
--- /dev/null
+++ b/tests/ui/static/safe-extern-statics.rs
@@ -0,0 +1,17 @@
+// aux-build:extern-statics.rs
+// revisions: mir thir
+// [thir]compile-flags: -Z thir-unsafeck
+
+extern crate extern_statics;
+use extern_statics::*;
+
+extern "C" {
+ static A: u8;
+}
+
+fn main() {
+ let a = A; //~ ERROR use of extern static is unsafe
+ let ra = &A; //~ ERROR use of extern static is unsafe
+ let xa = XA; //~ ERROR use of extern static is unsafe
+ let xra = &XA; //~ ERROR use of extern static is unsafe
+}
diff --git a/tests/ui/static/safe-extern-statics.thir.stderr b/tests/ui/static/safe-extern-statics.thir.stderr
new file mode 100644
index 000000000..7fd2182c4
--- /dev/null
+++ b/tests/ui/static/safe-extern-statics.thir.stderr
@@ -0,0 +1,35 @@
+error[E0133]: use of extern static is unsafe and requires unsafe function or block
+ --> $DIR/safe-extern-statics.rs:13:13
+ |
+LL | let a = A;
+ | ^ use of extern static
+ |
+ = note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior
+
+error[E0133]: use of extern static is unsafe and requires unsafe function or block
+ --> $DIR/safe-extern-statics.rs:14:15
+ |
+LL | let ra = &A;
+ | ^ use of extern static
+ |
+ = note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior
+
+error[E0133]: use of extern static is unsafe and requires unsafe function or block
+ --> $DIR/safe-extern-statics.rs:15:14
+ |
+LL | let xa = XA;
+ | ^^ use of extern static
+ |
+ = note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior
+
+error[E0133]: use of extern static is unsafe and requires unsafe function or block
+ --> $DIR/safe-extern-statics.rs:16:16
+ |
+LL | let xra = &XA;
+ | ^^ use of extern static
+ |
+ = note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior
+
+error: aborting due to 4 previous errors
+
+For more information about this error, try `rustc --explain E0133`.
diff --git a/tests/ui/static/static-closures.rs b/tests/ui/static/static-closures.rs
new file mode 100644
index 000000000..1bd518d6f
--- /dev/null
+++ b/tests/ui/static/static-closures.rs
@@ -0,0 +1,4 @@
+fn main() {
+ static || {};
+ //~^ ERROR closures cannot be static
+}
diff --git a/tests/ui/static/static-closures.stderr b/tests/ui/static/static-closures.stderr
new file mode 100644
index 000000000..99235e26e
--- /dev/null
+++ b/tests/ui/static/static-closures.stderr
@@ -0,0 +1,9 @@
+error[E0697]: closures cannot be static
+ --> $DIR/static-closures.rs:2:5
+ |
+LL | static || {};
+ | ^^^^^^^^^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0697`.
diff --git a/tests/ui/static/static-drop-scope.rs b/tests/ui/static/static-drop-scope.rs
new file mode 100644
index 000000000..34afa9873
--- /dev/null
+++ b/tests/ui/static/static-drop-scope.rs
@@ -0,0 +1,37 @@
+struct WithDtor;
+
+impl Drop for WithDtor {
+ fn drop(&mut self) {}
+}
+
+static PROMOTION_FAIL_S: Option<&'static WithDtor> = Some(&WithDtor);
+//~^ ERROR destructor of
+//~| ERROR temporary value dropped while borrowed
+
+const PROMOTION_FAIL_C: Option<&'static WithDtor> = Some(&WithDtor);
+//~^ ERROR destructor of
+//~| ERROR temporary value dropped while borrowed
+
+static EARLY_DROP_S: i32 = (WithDtor, 0).1;
+//~^ ERROR destructor of
+
+const EARLY_DROP_C: i32 = (WithDtor, 0).1;
+//~^ ERROR destructor of
+
+const fn const_drop<T>(_: T) {}
+//~^ ERROR destructor of
+
+const fn const_drop2<T>(x: T) {
+ (x, ()).1
+ //~^ ERROR destructor of
+}
+
+const EARLY_DROP_C_OPTION: i32 = (Some(WithDtor), 0).1;
+//~^ ERROR destructor of
+
+const HELPER: Option<WithDtor> = Some(WithDtor);
+
+const EARLY_DROP_C_OPTION_CONSTANT: i32 = (HELPER, 0).1;
+//~^ ERROR destructor of
+
+fn main () {}
diff --git a/tests/ui/static/static-drop-scope.stderr b/tests/ui/static/static-drop-scope.stderr
new file mode 100644
index 000000000..cedcb7367
--- /dev/null
+++ b/tests/ui/static/static-drop-scope.stderr
@@ -0,0 +1,89 @@
+error[E0493]: destructor of `WithDtor` cannot be evaluated at compile-time
+ --> $DIR/static-drop-scope.rs:7:60
+ |
+LL | static PROMOTION_FAIL_S: Option<&'static WithDtor> = Some(&WithDtor);
+ | ^^^^^^^^- value is dropped here
+ | |
+ | the destructor for this type cannot be evaluated in statics
+
+error[E0716]: temporary value dropped while borrowed
+ --> $DIR/static-drop-scope.rs:7:60
+ |
+LL | static PROMOTION_FAIL_S: Option<&'static WithDtor> = Some(&WithDtor);
+ | ------^^^^^^^^-
+ | | | |
+ | | | temporary value is freed at the end of this statement
+ | | creates a temporary value which is freed while still in use
+ | using this value as a static requires that borrow lasts for `'static`
+
+error[E0493]: destructor of `WithDtor` cannot be evaluated at compile-time
+ --> $DIR/static-drop-scope.rs:11:59
+ |
+LL | const PROMOTION_FAIL_C: Option<&'static WithDtor> = Some(&WithDtor);
+ | ^^^^^^^^- value is dropped here
+ | |
+ | the destructor for this type cannot be evaluated in constants
+
+error[E0716]: temporary value dropped while borrowed
+ --> $DIR/static-drop-scope.rs:11:59
+ |
+LL | const PROMOTION_FAIL_C: Option<&'static WithDtor> = Some(&WithDtor);
+ | ------^^^^^^^^-
+ | | | |
+ | | | temporary value is freed at the end of this statement
+ | | creates a temporary value which is freed while still in use
+ | using this value as a constant requires that borrow lasts for `'static`
+
+error[E0493]: destructor of `(WithDtor, i32)` cannot be evaluated at compile-time
+ --> $DIR/static-drop-scope.rs:15:28
+ |
+LL | static EARLY_DROP_S: i32 = (WithDtor, 0).1;
+ | ^^^^^^^^^^^^^ - value is dropped here
+ | |
+ | the destructor for this type cannot be evaluated in statics
+
+error[E0493]: destructor of `(WithDtor, i32)` cannot be evaluated at compile-time
+ --> $DIR/static-drop-scope.rs:18:27
+ |
+LL | const EARLY_DROP_C: i32 = (WithDtor, 0).1;
+ | ^^^^^^^^^^^^^ - value is dropped here
+ | |
+ | the destructor for this type cannot be evaluated in constants
+
+error[E0493]: destructor of `T` cannot be evaluated at compile-time
+ --> $DIR/static-drop-scope.rs:21:24
+ |
+LL | const fn const_drop<T>(_: T) {}
+ | ^ - value is dropped here
+ | |
+ | the destructor for this type cannot be evaluated in constant functions
+
+error[E0493]: destructor of `(T, ())` cannot be evaluated at compile-time
+ --> $DIR/static-drop-scope.rs:25:5
+ |
+LL | (x, ()).1
+ | ^^^^^^^ the destructor for this type cannot be evaluated in constant functions
+LL |
+LL | }
+ | - value is dropped here
+
+error[E0493]: destructor of `(Option<WithDtor>, i32)` cannot be evaluated at compile-time
+ --> $DIR/static-drop-scope.rs:29:34
+ |
+LL | const EARLY_DROP_C_OPTION: i32 = (Some(WithDtor), 0).1;
+ | ^^^^^^^^^^^^^^^^^^^ - value is dropped here
+ | |
+ | the destructor for this type cannot be evaluated in constants
+
+error[E0493]: destructor of `(Option<WithDtor>, i32)` cannot be evaluated at compile-time
+ --> $DIR/static-drop-scope.rs:34:43
+ |
+LL | const EARLY_DROP_C_OPTION_CONSTANT: i32 = (HELPER, 0).1;
+ | ^^^^^^^^^^^ - value is dropped here
+ | |
+ | the destructor for this type cannot be evaluated in constants
+
+error: aborting due to 10 previous errors
+
+Some errors have detailed explanations: E0493, E0716.
+For more information about an error, try `rustc --explain E0493`.
diff --git a/tests/ui/static/static-extern-type.rs b/tests/ui/static/static-extern-type.rs
new file mode 100644
index 000000000..4fa48fa13
--- /dev/null
+++ b/tests/ui/static/static-extern-type.rs
@@ -0,0 +1,27 @@
+// build-pass (FIXME(62277): could be check-pass?)
+#![feature(extern_types)]
+
+pub mod a {
+ extern "C" {
+ pub type StartFn;
+ pub static start: StartFn;
+ }
+}
+
+pub mod b {
+ #[repr(transparent)]
+ pub struct TransparentType(::a::StartFn);
+ extern "C" {
+ pub static start: TransparentType;
+ }
+}
+
+pub mod c {
+ #[repr(C)]
+ pub struct CType(u32, ::b::TransparentType);
+ extern "C" {
+ pub static start: CType;
+ }
+}
+
+fn main() {}
diff --git a/tests/ui/static/static-items-cant-move.rs b/tests/ui/static/static-items-cant-move.rs
new file mode 100644
index 000000000..3e7aaa0b0
--- /dev/null
+++ b/tests/ui/static/static-items-cant-move.rs
@@ -0,0 +1,19 @@
+// Verifies that static items can't be moved
+
+struct B;
+
+struct Foo {
+ foo: isize,
+ b: B,
+}
+
+static BAR: Foo = Foo { foo: 5, b: B };
+
+
+fn test(f: Foo) {
+ let _f = Foo{foo: 4, ..f};
+}
+
+fn main() {
+ test(BAR); //~ ERROR cannot move out of static item
+}
diff --git a/tests/ui/static/static-items-cant-move.stderr b/tests/ui/static/static-items-cant-move.stderr
new file mode 100644
index 000000000..235e9ee9b
--- /dev/null
+++ b/tests/ui/static/static-items-cant-move.stderr
@@ -0,0 +1,9 @@
+error[E0507]: cannot move out of static item `BAR`
+ --> $DIR/static-items-cant-move.rs:18:10
+ |
+LL | test(BAR);
+ | ^^^ move occurs because `BAR` has type `Foo`, which does not implement the `Copy` trait
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0507`.
diff --git a/tests/ui/static/static-lifetime-bound.rs b/tests/ui/static/static-lifetime-bound.rs
new file mode 100644
index 000000000..b5da91ec3
--- /dev/null
+++ b/tests/ui/static/static-lifetime-bound.rs
@@ -0,0 +1,6 @@
+fn f<'a: 'static>(_: &'a i32) {} //~WARN unnecessary lifetime parameter `'a`
+
+fn main() {
+ let x = 0;
+ f(&x); //~ERROR does not live long enough
+}
diff --git a/tests/ui/static/static-lifetime-bound.stderr b/tests/ui/static/static-lifetime-bound.stderr
new file mode 100644
index 000000000..ef07a8931
--- /dev/null
+++ b/tests/ui/static/static-lifetime-bound.stderr
@@ -0,0 +1,22 @@
+warning: unnecessary lifetime parameter `'a`
+ --> $DIR/static-lifetime-bound.rs:1:6
+ |
+LL | fn f<'a: 'static>(_: &'a i32) {}
+ | ^^
+ |
+ = help: you can use the `'static` lifetime directly, in place of `'a`
+
+error[E0597]: `x` does not live long enough
+ --> $DIR/static-lifetime-bound.rs:5:7
+ |
+LL | f(&x);
+ | --^^-
+ | | |
+ | | borrowed value does not live long enough
+ | argument requires that `x` is borrowed for `'static`
+LL | }
+ | - `x` dropped here while still borrowed
+
+error: aborting due to previous error; 1 warning emitted
+
+For more information about this error, try `rustc --explain E0597`.
diff --git a/tests/ui/static/static-lifetime.rs b/tests/ui/static/static-lifetime.rs
new file mode 100644
index 000000000..ce1eeb610
--- /dev/null
+++ b/tests/ui/static/static-lifetime.rs
@@ -0,0 +1,6 @@
+pub trait Arbitrary: Sized + 'static {}
+
+impl<'a, A: Clone> Arbitrary for ::std::borrow::Cow<'a, A> {} //~ ERROR lifetime bound
+
+fn main() {
+}
diff --git a/tests/ui/static/static-lifetime.stderr b/tests/ui/static/static-lifetime.stderr
new file mode 100644
index 000000000..4af3370c7
--- /dev/null
+++ b/tests/ui/static/static-lifetime.stderr
@@ -0,0 +1,16 @@
+error[E0478]: lifetime bound not satisfied
+ --> $DIR/static-lifetime.rs:3:20
+ |
+LL | impl<'a, A: Clone> Arbitrary for ::std::borrow::Cow<'a, A> {}
+ | ^^^^^^^^^
+ |
+note: lifetime parameter instantiated with the lifetime `'a` as defined here
+ --> $DIR/static-lifetime.rs:3:6
+ |
+LL | impl<'a, A: Clone> Arbitrary for ::std::borrow::Cow<'a, A> {}
+ | ^^
+ = note: but lifetime parameter must outlive the static lifetime
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0478`.
diff --git a/tests/ui/static/static-method-privacy.rs b/tests/ui/static/static-method-privacy.rs
new file mode 100644
index 000000000..9ee59b320
--- /dev/null
+++ b/tests/ui/static/static-method-privacy.rs
@@ -0,0 +1,10 @@
+mod a {
+ pub struct S;
+ impl S {
+ fn new() -> S { S }
+ }
+}
+
+fn main() {
+ let _ = a::S::new(); //~ ERROR associated function `new` is private
+}
diff --git a/tests/ui/static/static-method-privacy.stderr b/tests/ui/static/static-method-privacy.stderr
new file mode 100644
index 000000000..4be1b22fc
--- /dev/null
+++ b/tests/ui/static/static-method-privacy.stderr
@@ -0,0 +1,12 @@
+error[E0624]: associated function `new` is private
+ --> $DIR/static-method-privacy.rs:9:19
+ |
+LL | fn new() -> S { S }
+ | ------------- private associated function defined here
+...
+LL | let _ = a::S::new();
+ | ^^^ private associated function
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0624`.
diff --git a/tests/ui/static/static-mut-bad-types.rs b/tests/ui/static/static-mut-bad-types.rs
new file mode 100644
index 000000000..8a98b1b7f
--- /dev/null
+++ b/tests/ui/static/static-mut-bad-types.rs
@@ -0,0 +1,7 @@
+static mut a: isize = 3;
+
+fn main() {
+ unsafe {
+ a = true; //~ ERROR: mismatched types
+ }
+}
diff --git a/tests/ui/static/static-mut-bad-types.stderr b/tests/ui/static/static-mut-bad-types.stderr
new file mode 100644
index 000000000..983e1026f
--- /dev/null
+++ b/tests/ui/static/static-mut-bad-types.stderr
@@ -0,0 +1,12 @@
+error[E0308]: mismatched types
+ --> $DIR/static-mut-bad-types.rs:5:13
+ |
+LL | static mut a: isize = 3;
+ | ----- expected due to this type
+...
+LL | a = true;
+ | ^^^^ expected `isize`, found `bool`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/tests/ui/static/static-mut-foreign-requires-unsafe.mir.stderr b/tests/ui/static/static-mut-foreign-requires-unsafe.mir.stderr
new file mode 100644
index 000000000..a4659bc87
--- /dev/null
+++ b/tests/ui/static/static-mut-foreign-requires-unsafe.mir.stderr
@@ -0,0 +1,27 @@
+error[E0133]: use of mutable static is unsafe and requires unsafe function or block
+ --> $DIR/static-mut-foreign-requires-unsafe.rs:9:5
+ |
+LL | a += 3;
+ | ^^^^^^ use of mutable static
+ |
+ = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior
+
+error[E0133]: use of mutable static is unsafe and requires unsafe function or block
+ --> $DIR/static-mut-foreign-requires-unsafe.rs:10:5
+ |
+LL | a = 4;
+ | ^^^^^ use of mutable static
+ |
+ = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior
+
+error[E0133]: use of mutable static is unsafe and requires unsafe function or block
+ --> $DIR/static-mut-foreign-requires-unsafe.rs:11:14
+ |
+LL | let _b = a;
+ | ^ use of mutable static
+ |
+ = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0133`.
diff --git a/tests/ui/static/static-mut-foreign-requires-unsafe.rs b/tests/ui/static/static-mut-foreign-requires-unsafe.rs
new file mode 100644
index 000000000..4f96acb33
--- /dev/null
+++ b/tests/ui/static/static-mut-foreign-requires-unsafe.rs
@@ -0,0 +1,12 @@
+// revisions: mir thir
+// [thir]compile-flags: -Z thir-unsafeck
+
+extern "C" {
+ static mut a: i32;
+}
+
+fn main() {
+ a += 3; //~ ERROR: requires unsafe
+ a = 4; //~ ERROR: requires unsafe
+ let _b = a; //~ ERROR: requires unsafe
+}
diff --git a/tests/ui/static/static-mut-foreign-requires-unsafe.thir.stderr b/tests/ui/static/static-mut-foreign-requires-unsafe.thir.stderr
new file mode 100644
index 000000000..2c62d4d8f
--- /dev/null
+++ b/tests/ui/static/static-mut-foreign-requires-unsafe.thir.stderr
@@ -0,0 +1,27 @@
+error[E0133]: use of mutable static is unsafe and requires unsafe function or block
+ --> $DIR/static-mut-foreign-requires-unsafe.rs:9:5
+ |
+LL | a += 3;
+ | ^ use of mutable static
+ |
+ = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior
+
+error[E0133]: use of mutable static is unsafe and requires unsafe function or block
+ --> $DIR/static-mut-foreign-requires-unsafe.rs:10:5
+ |
+LL | a = 4;
+ | ^ use of mutable static
+ |
+ = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior
+
+error[E0133]: use of mutable static is unsafe and requires unsafe function or block
+ --> $DIR/static-mut-foreign-requires-unsafe.rs:11:14
+ |
+LL | let _b = a;
+ | ^ use of mutable static
+ |
+ = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0133`.
diff --git a/tests/ui/static/static-mut-not-constant.rs b/tests/ui/static/static-mut-not-constant.rs
new file mode 100644
index 000000000..2091fffd4
--- /dev/null
+++ b/tests/ui/static/static-mut-not-constant.rs
@@ -0,0 +1,6 @@
+#![feature(box_syntax)]
+
+static mut a: Box<isize> = box 3;
+//~^ ERROR allocations are not allowed in statics
+
+fn main() {}
diff --git a/tests/ui/static/static-mut-not-constant.stderr b/tests/ui/static/static-mut-not-constant.stderr
new file mode 100644
index 000000000..a0fa24515
--- /dev/null
+++ b/tests/ui/static/static-mut-not-constant.stderr
@@ -0,0 +1,9 @@
+error[E0010]: allocations are not allowed in statics
+ --> $DIR/static-mut-not-constant.rs:3:28
+ |
+LL | static mut a: Box<isize> = box 3;
+ | ^^^^^ allocation not allowed in statics
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0010`.
diff --git a/tests/ui/static/static-mut-not-pat.rs b/tests/ui/static/static-mut-not-pat.rs
new file mode 100644
index 000000000..ce5ae164c
--- /dev/null
+++ b/tests/ui/static/static-mut-not-pat.rs
@@ -0,0 +1,43 @@
+// Constants (static variables) can be used to match in patterns, but mutable
+// statics cannot. This ensures that there's some form of error if this is
+// attempted.
+
+static mut a: isize = 3;
+
+fn main() {
+ // If they can't be matched against, then it's possible to capture the same
+ // name as a variable, hence this should be an unreachable pattern situation
+ // instead of spitting out a custom error about some identifier collisions
+ // (we should allow shadowing)
+ match 4 {
+ a => {} //~ ERROR match bindings cannot shadow statics
+ _ => {}
+ }
+}
+
+struct NewBool(bool);
+enum Direction {
+ North,
+ East,
+ South,
+ West
+}
+const NEW_FALSE: NewBool = NewBool(false);
+struct Foo {
+ bar: Option<Direction>,
+ baz: NewBool
+}
+
+static mut STATIC_MUT_FOO: Foo = Foo { bar: Some(Direction::West), baz: NEW_FALSE };
+
+fn mutable_statics() {
+ match (Foo { bar: Some(Direction::North), baz: NewBool(true) }) {
+ Foo { bar: None, baz: NewBool(true) } => (),
+ STATIC_MUT_FOO => (),
+ //~^ ERROR match bindings cannot shadow statics
+ Foo { bar: Some(Direction::South), .. } => (),
+ Foo { bar: Some(EAST), .. } => (),
+ Foo { bar: Some(Direction::North), baz: NewBool(true) } => (),
+ Foo { bar: Some(EAST), baz: NewBool(false) } => ()
+ }
+}
diff --git a/tests/ui/static/static-mut-not-pat.stderr b/tests/ui/static/static-mut-not-pat.stderr
new file mode 100644
index 000000000..33c1cd6a5
--- /dev/null
+++ b/tests/ui/static/static-mut-not-pat.stderr
@@ -0,0 +1,21 @@
+error[E0530]: match bindings cannot shadow statics
+ --> $DIR/static-mut-not-pat.rs:13:9
+ |
+LL | static mut a: isize = 3;
+ | ------------------------ the static `a` is defined here
+...
+LL | a => {}
+ | ^ cannot be named the same as a static
+
+error[E0530]: match bindings cannot shadow statics
+ --> $DIR/static-mut-not-pat.rs:36:9
+ |
+LL | static mut STATIC_MUT_FOO: Foo = Foo { bar: Some(Direction::West), baz: NEW_FALSE };
+ | ------------------------------------------------------------------------------------ the static `STATIC_MUT_FOO` is defined here
+...
+LL | STATIC_MUT_FOO => (),
+ | ^^^^^^^^^^^^^^ cannot be named the same as a static
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0530`.
diff --git a/tests/ui/static/static-mut-requires-unsafe.mir.stderr b/tests/ui/static/static-mut-requires-unsafe.mir.stderr
new file mode 100644
index 000000000..0d4ce056f
--- /dev/null
+++ b/tests/ui/static/static-mut-requires-unsafe.mir.stderr
@@ -0,0 +1,27 @@
+error[E0133]: use of mutable static is unsafe and requires unsafe function or block
+ --> $DIR/static-mut-requires-unsafe.rs:7:5
+ |
+LL | a += 3;
+ | ^^^^^^ use of mutable static
+ |
+ = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior
+
+error[E0133]: use of mutable static is unsafe and requires unsafe function or block
+ --> $DIR/static-mut-requires-unsafe.rs:8:5
+ |
+LL | a = 4;
+ | ^^^^^ use of mutable static
+ |
+ = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior
+
+error[E0133]: use of mutable static is unsafe and requires unsafe function or block
+ --> $DIR/static-mut-requires-unsafe.rs:9:14
+ |
+LL | let _b = a;
+ | ^ use of mutable static
+ |
+ = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0133`.
diff --git a/tests/ui/static/static-mut-requires-unsafe.rs b/tests/ui/static/static-mut-requires-unsafe.rs
new file mode 100644
index 000000000..ea3ba0950
--- /dev/null
+++ b/tests/ui/static/static-mut-requires-unsafe.rs
@@ -0,0 +1,10 @@
+// revisions: mir thir
+// [thir]compile-flags: -Z thir-unsafeck
+
+static mut a: isize = 3;
+
+fn main() {
+ a += 3; //~ ERROR: requires unsafe
+ a = 4; //~ ERROR: requires unsafe
+ let _b = a; //~ ERROR: requires unsafe
+}
diff --git a/tests/ui/static/static-mut-requires-unsafe.thir.stderr b/tests/ui/static/static-mut-requires-unsafe.thir.stderr
new file mode 100644
index 000000000..1a1cf1427
--- /dev/null
+++ b/tests/ui/static/static-mut-requires-unsafe.thir.stderr
@@ -0,0 +1,27 @@
+error[E0133]: use of mutable static is unsafe and requires unsafe function or block
+ --> $DIR/static-mut-requires-unsafe.rs:7:5
+ |
+LL | a += 3;
+ | ^ use of mutable static
+ |
+ = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior
+
+error[E0133]: use of mutable static is unsafe and requires unsafe function or block
+ --> $DIR/static-mut-requires-unsafe.rs:8:5
+ |
+LL | a = 4;
+ | ^ use of mutable static
+ |
+ = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior
+
+error[E0133]: use of mutable static is unsafe and requires unsafe function or block
+ --> $DIR/static-mut-requires-unsafe.rs:9:14
+ |
+LL | let _b = a;
+ | ^ use of mutable static
+ |
+ = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0133`.
diff --git a/tests/ui/static/static-priv-by-default2.rs b/tests/ui/static/static-priv-by-default2.rs
new file mode 100644
index 000000000..bbbdb253b
--- /dev/null
+++ b/tests/ui/static/static-priv-by-default2.rs
@@ -0,0 +1,30 @@
+// aux-build:static_priv_by_default.rs
+
+extern crate static_priv_by_default;
+
+mod child {
+ pub mod childs_child {
+ static private: isize = 0;
+ pub static public: isize = 0;
+ }
+}
+
+fn foo<T>(_: T) {}
+
+fn test1() {
+ use child::childs_child::private;
+ //~^ ERROR: static `private` is private
+ use child::childs_child::public;
+
+ foo(private);
+}
+
+fn test2() {
+ use static_priv_by_default::private;
+ //~^ ERROR: static `private` is private
+ use static_priv_by_default::public;
+
+ foo(private);
+}
+
+fn main() {}
diff --git a/tests/ui/static/static-priv-by-default2.stderr b/tests/ui/static/static-priv-by-default2.stderr
new file mode 100644
index 000000000..b14e096d6
--- /dev/null
+++ b/tests/ui/static/static-priv-by-default2.stderr
@@ -0,0 +1,27 @@
+error[E0603]: static `private` is private
+ --> $DIR/static-priv-by-default2.rs:15:30
+ |
+LL | use child::childs_child::private;
+ | ^^^^^^^ private static
+ |
+note: the static `private` is defined here
+ --> $DIR/static-priv-by-default2.rs:7:9
+ |
+LL | static private: isize = 0;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error[E0603]: static `private` is private
+ --> $DIR/static-priv-by-default2.rs:23:33
+ |
+LL | use static_priv_by_default::private;
+ | ^^^^^^^ private static
+ |
+note: the static `private` is defined here
+ --> $DIR/auxiliary/static_priv_by_default.rs:3:1
+ |
+LL | static private: isize = 0;
+ | ^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0603`.
diff --git a/tests/ui/static/static-reference-to-fn-1.rs b/tests/ui/static/static-reference-to-fn-1.rs
new file mode 100644
index 000000000..c15634dbf
--- /dev/null
+++ b/tests/ui/static/static-reference-to-fn-1.rs
@@ -0,0 +1,24 @@
+struct A<'a> {
+ func: &'a fn() -> Option<isize>
+}
+
+impl<'a> A<'a> {
+ fn call(&self) -> Option<isize> {
+ (*self.func)()
+ }
+}
+
+fn foo() -> Option<isize> {
+ None
+}
+
+fn create() -> A<'static> {
+ A {
+ func: &foo, //~ ERROR mismatched types
+ }
+}
+
+fn main() {
+ let a = create();
+ a.call();
+}
diff --git a/tests/ui/static/static-reference-to-fn-1.stderr b/tests/ui/static/static-reference-to-fn-1.stderr
new file mode 100644
index 000000000..67b478bdb
--- /dev/null
+++ b/tests/ui/static/static-reference-to-fn-1.stderr
@@ -0,0 +1,12 @@
+error[E0308]: mismatched types
+ --> $DIR/static-reference-to-fn-1.rs:17:15
+ |
+LL | func: &foo,
+ | ^^^^ expected fn pointer, found fn item
+ |
+ = note: expected reference `&fn() -> Option<isize>`
+ found reference `&fn() -> Option<isize> {foo}`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/tests/ui/static/static-reference-to-fn-2.rs b/tests/ui/static/static-reference-to-fn-2.rs
new file mode 100644
index 000000000..6693667c0
--- /dev/null
+++ b/tests/ui/static/static-reference-to-fn-2.rs
@@ -0,0 +1,54 @@
+fn id<T>(x: T) -> T { x }
+
+struct StateMachineIter<'a> {
+ statefn: &'a StateMachineFunc<'a>
+}
+
+type StateMachineFunc<'a> = fn(&mut StateMachineIter<'a>) -> Option<&'static str>;
+
+impl<'a> Iterator for StateMachineIter<'a> {
+ type Item = &'static str;
+
+ fn next(&mut self) -> Option<&'static str> {
+ return (*self.statefn)(self);
+ }
+}
+
+fn state1(self_: &mut StateMachineIter) -> Option<&'static str> {
+ self_.statefn = &id(state2 as StateMachineFunc);
+ //~^ ERROR temporary value dropped while borrowed
+ return Some("state1");
+}
+
+fn state2(self_: &mut StateMachineIter) -> Option<(&'static str)> {
+ self_.statefn = &id(state3 as StateMachineFunc);
+ //~^ ERROR temporary value dropped while borrowed
+ return Some("state2");
+}
+
+fn state3(self_: &mut StateMachineIter) -> Option<(&'static str)> {
+ self_.statefn = &id(finished as StateMachineFunc);
+ //~^ ERROR temporary value dropped while borrowed
+ return Some("state3");
+}
+
+fn finished(_: &mut StateMachineIter) -> Option<(&'static str)> {
+ return None;
+}
+
+fn state_iter() -> StateMachineIter<'static> {
+ StateMachineIter {
+ //~^ ERROR cannot return value referencing temporary value
+ statefn: &id(state1 as StateMachineFunc)
+ }
+}
+
+
+fn main() {
+ let mut it = state_iter();
+ println!("{:?}",it.next());
+ println!("{:?}",it.next());
+ println!("{:?}",it.next());
+ println!("{:?}",it.next());
+ println!("{:?}",it.next());
+}
diff --git a/tests/ui/static/static-reference-to-fn-2.stderr b/tests/ui/static/static-reference-to-fn-2.stderr
new file mode 100644
index 000000000..133d8ec2e
--- /dev/null
+++ b/tests/ui/static/static-reference-to-fn-2.stderr
@@ -0,0 +1,49 @@
+error[E0716]: temporary value dropped while borrowed
+ --> $DIR/static-reference-to-fn-2.rs:18:22
+ |
+LL | fn state1(self_: &mut StateMachineIter) -> Option<&'static str> {
+ | ----- has type `&mut StateMachineIter<'1>`
+LL | self_.statefn = &id(state2 as StateMachineFunc);
+ | -----------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- temporary value is freed at the end of this statement
+ | | |
+ | | creates a temporary value which is freed while still in use
+ | assignment requires that borrow lasts for `'1`
+
+error[E0716]: temporary value dropped while borrowed
+ --> $DIR/static-reference-to-fn-2.rs:24:22
+ |
+LL | fn state2(self_: &mut StateMachineIter) -> Option<(&'static str)> {
+ | ----- has type `&mut StateMachineIter<'1>`
+LL | self_.statefn = &id(state3 as StateMachineFunc);
+ | -----------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- temporary value is freed at the end of this statement
+ | | |
+ | | creates a temporary value which is freed while still in use
+ | assignment requires that borrow lasts for `'1`
+
+error[E0716]: temporary value dropped while borrowed
+ --> $DIR/static-reference-to-fn-2.rs:30:22
+ |
+LL | fn state3(self_: &mut StateMachineIter) -> Option<(&'static str)> {
+ | ----- has type `&mut StateMachineIter<'1>`
+LL | self_.statefn = &id(finished as StateMachineFunc);
+ | -----------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- temporary value is freed at the end of this statement
+ | | |
+ | | creates a temporary value which is freed while still in use
+ | assignment requires that borrow lasts for `'1`
+
+error[E0515]: cannot return value referencing temporary value
+ --> $DIR/static-reference-to-fn-2.rs:40:5
+ |
+LL | / StateMachineIter {
+LL | |
+LL | | statefn: &id(state1 as StateMachineFunc)
+ | | ------------------------------ temporary value created here
+LL | | }
+ | |_____^ returns a value referencing data owned by the current function
+ |
+ = help: use `.collect()` to allocate the iterator
+
+error: aborting due to 4 previous errors
+
+Some errors have detailed explanations: E0515, E0716.
+For more information about an error, try `rustc --explain E0515`.
diff --git a/tests/ui/static/static-region-bound.rs b/tests/ui/static/static-region-bound.rs
new file mode 100644
index 000000000..d70706e57
--- /dev/null
+++ b/tests/ui/static/static-region-bound.rs
@@ -0,0 +1,12 @@
+fn id<T>(x: T) -> T { x }
+
+fn f<T:'static>(_: T) {}
+
+fn main() {
+
+ let x: Box<_> = Box::new(3);
+ f(x);
+
+ let x = &id(3); //~ ERROR temporary value dropped while borrowed
+ f(x);
+}
diff --git a/tests/ui/static/static-region-bound.stderr b/tests/ui/static/static-region-bound.stderr
new file mode 100644
index 000000000..1a607e3c0
--- /dev/null
+++ b/tests/ui/static/static-region-bound.stderr
@@ -0,0 +1,13 @@
+error[E0716]: temporary value dropped while borrowed
+ --> $DIR/static-region-bound.rs:10:14
+ |
+LL | let x = &id(3);
+ | ^^^^^ creates a temporary value which is freed while still in use
+LL | f(x);
+ | ---- argument requires that borrow lasts for `'static`
+LL | }
+ | - temporary value is freed at the end of this statement
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0716`.
diff --git a/tests/ui/static/static-vec-repeat-not-constant.rs b/tests/ui/static/static-vec-repeat-not-constant.rs
new file mode 100644
index 000000000..61c87b144
--- /dev/null
+++ b/tests/ui/static/static-vec-repeat-not-constant.rs
@@ -0,0 +1,6 @@
+fn foo() -> isize { 23 }
+
+static a: [isize; 2] = [foo(); 2];
+//~^ ERROR: E0015
+
+fn main() {}
diff --git a/tests/ui/static/static-vec-repeat-not-constant.stderr b/tests/ui/static/static-vec-repeat-not-constant.stderr
new file mode 100644
index 000000000..dec012318
--- /dev/null
+++ b/tests/ui/static/static-vec-repeat-not-constant.stderr
@@ -0,0 +1,12 @@
+error[E0015]: cannot call non-const fn `foo` in statics
+ --> $DIR/static-vec-repeat-not-constant.rs:3:25
+ |
+LL | static a: [isize; 2] = [foo(); 2];
+ | ^^^^^
+ |
+ = note: calls in statics are limited to constant functions, tuple structs and tuple variants
+ = note: consider wrapping this expression in `Lazy::new(|| ...)` from the `once_cell` crate: https://crates.io/crates/once_cell
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0015`.
diff --git a/tests/ui/static/static_sized_requirement.rs b/tests/ui/static/static_sized_requirement.rs
new file mode 100644
index 000000000..3943b2608
--- /dev/null
+++ b/tests/ui/static/static_sized_requirement.rs
@@ -0,0 +1,12 @@
+// build-pass (FIXME(62277): could be check-pass?)
+
+#![feature(no_core, lang_items)]
+#![no_core]
+#![crate_type = "lib"]
+
+#[lang = "sized"]
+trait Sized {}
+
+extern "C" {
+ pub static A: u32;
+}
diff --git a/tests/ui/static/thread-local-in-ctfe.rs b/tests/ui/static/thread-local-in-ctfe.rs
new file mode 100644
index 000000000..547e5445a
--- /dev/null
+++ b/tests/ui/static/thread-local-in-ctfe.rs
@@ -0,0 +1,23 @@
+#![feature(thread_local)]
+
+#[thread_local]
+static A: u32 = 1;
+
+static B: u32 = A;
+//~^ ERROR thread-local statics cannot be accessed at compile-time
+
+static C: &u32 = &A;
+//~^ ERROR thread-local statics cannot be accessed at compile-time
+
+const D: u32 = A;
+//~^ ERROR thread-local statics cannot be accessed at compile-time
+
+const E: &u32 = &A;
+//~^ ERROR thread-local statics cannot be accessed at compile-time
+
+const fn f() -> u32 {
+ A
+ //~^ ERROR thread-local statics cannot be accessed at compile-time
+}
+
+fn main() {}
diff --git a/tests/ui/static/thread-local-in-ctfe.stderr b/tests/ui/static/thread-local-in-ctfe.stderr
new file mode 100644
index 000000000..fd9676046
--- /dev/null
+++ b/tests/ui/static/thread-local-in-ctfe.stderr
@@ -0,0 +1,33 @@
+error[E0625]: thread-local statics cannot be accessed at compile-time
+ --> $DIR/thread-local-in-ctfe.rs:6:17
+ |
+LL | static B: u32 = A;
+ | ^
+
+error[E0625]: thread-local statics cannot be accessed at compile-time
+ --> $DIR/thread-local-in-ctfe.rs:9:19
+ |
+LL | static C: &u32 = &A;
+ | ^
+
+error[E0625]: thread-local statics cannot be accessed at compile-time
+ --> $DIR/thread-local-in-ctfe.rs:12:16
+ |
+LL | const D: u32 = A;
+ | ^
+
+error[E0625]: thread-local statics cannot be accessed at compile-time
+ --> $DIR/thread-local-in-ctfe.rs:15:18
+ |
+LL | const E: &u32 = &A;
+ | ^
+
+error[E0625]: thread-local statics cannot be accessed at compile-time
+ --> $DIR/thread-local-in-ctfe.rs:19:5
+ |
+LL | A
+ | ^
+
+error: aborting due to 5 previous errors
+
+For more information about this error, try `rustc --explain E0625`.