diff options
Diffstat (limited to 'tests/ui/static')
4 files changed, 66 insertions, 0 deletions
diff --git a/tests/ui/static/global-variable-promotion-error-7364.rs b/tests/ui/static/global-variable-promotion-error-7364.rs new file mode 100644 index 00000000000..dba4a484d61 --- /dev/null +++ b/tests/ui/static/global-variable-promotion-error-7364.rs @@ -0,0 +1,9 @@ +// https://github.com/rust-lang/rust/issues/7364 +use std::cell::RefCell; + +// Regression test for issue 7364 +static boxed: Box<RefCell<isize>> = Box::new(RefCell::new(0)); +//~^ ERROR `RefCell<isize>` cannot be shared between threads safely [E0277] +//~| ERROR cannot call non-const associated function + +fn main() { } diff --git a/tests/ui/static/global-variable-promotion-error-7364.stderr b/tests/ui/static/global-variable-promotion-error-7364.stderr new file mode 100644 index 00000000000..b9d75676bef --- /dev/null +++ b/tests/ui/static/global-variable-promotion-error-7364.stderr @@ -0,0 +1,26 @@ +error[E0277]: `RefCell<isize>` cannot be shared between threads safely + --> $DIR/global-variable-promotion-error-7364.rs:5:15 + | +LL | static boxed: Box<RefCell<isize>> = Box::new(RefCell::new(0)); + | ^^^^^^^^^^^^^^^^^^^ `RefCell<isize>` cannot be shared between threads safely + | + = help: the trait `Sync` is not implemented for `RefCell<isize>` + = note: if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` instead + = note: required for `Unique<RefCell<isize>>` to implement `Sync` +note: required because it appears within the type `Box<RefCell<isize>>` + --> $SRC_DIR/alloc/src/boxed.rs:LL:COL + = note: shared static variables must have a type that implements `Sync` + +error[E0015]: cannot call non-const associated function `Box::<RefCell<isize>>::new` in statics + --> $DIR/global-variable-promotion-error-7364.rs:5:37 + | +LL | static boxed: Box<RefCell<isize>> = Box::new(RefCell::new(0)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: calls in statics are limited to constant functions, tuple structs and tuple variants + = note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)` + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0015, E0277. +For more information about an error, try `rustc --explain E0015`. diff --git a/tests/ui/static/static-list-initialization-5917.rs b/tests/ui/static/static-list-initialization-5917.rs new file mode 100644 index 00000000000..c6c32f7582e --- /dev/null +++ b/tests/ui/static/static-list-initialization-5917.rs @@ -0,0 +1,10 @@ +// https://github.com/rust-lang/rust/issues/5917 +//@ run-pass +#![allow(non_upper_case_globals)] + +struct T (&'static [isize]); +static t : T = T (&[5, 4, 3]); +pub fn main () { + let T(ref v) = t; + assert_eq!(v[0], 5); +} diff --git a/tests/ui/static/static-struct-initialization-5688.rs b/tests/ui/static/static-struct-initialization-5688.rs new file mode 100644 index 00000000000..6a4c2f45b6b --- /dev/null +++ b/tests/ui/static/static-struct-initialization-5688.rs @@ -0,0 +1,21 @@ +// https://github.com/rust-lang/rust/issues/5688 +//@ run-pass +/* +# Corrupted initialization in the static struct + +...should print &[1, 2, 3] but instead prints something like +&[4492532864, 24]. It is pretty evident that the compiler messed up +with the representation of [isize; n] and [isize] somehow, or at least +failed to typecheck correctly. +*/ + +#[derive(Copy, Clone)] +struct X { vec: &'static [isize] } + +static V: &'static [X] = &[X { vec: &[1, 2, 3] }]; + +pub fn main() { + for &v in V { + println!("{:?}", v.vec); + } +} |
