Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Regression test for https://github.com/rust-lang/rust/issues/3521
//!
//@ run-rustfix
fn main() {
let foo = 100;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Regression test for https://github.com/rust-lang/rust/issues/3521
//!
//@ run-rustfix
fn main() {
let foo = 100;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0435]: attempt to use a non-constant value in a constant
--> $DIR/issue-3521-2.rs:5:23
--> $DIR/static-cannot-use-local-variable.rs:7:23
|
LL | static y: isize = foo + 1;
| ^^^ non-constant value
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//! Regression test for https://github.com/rust-lang/rust/issues/3668
//!
//@ run-rustfix
#![allow(unused_variables, dead_code)]
fn f(x:isize) {
fn f(x: isize) {
let child: isize = x + 1;
//~^ ERROR attempt to use a non-constant value in a constant
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//! Regression test for https://github.com/rust-lang/rust/issues/3668
//!
//@ run-rustfix
#![allow(unused_variables, dead_code)]
fn f(x:isize) {
fn f(x: isize) {
static child: isize = x + 1;
//~^ ERROR attempt to use a non-constant value in a constant
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0435]: attempt to use a non-constant value in a constant
--> $DIR/issue-3668-2.rs:4:27
--> $DIR/static-in-fn-cannot-use-param.rs:6:27
|
LL | static child: isize = x + 1;
| ^ non-constant value
Expand Down
18 changes: 18 additions & 0 deletions tests/ui/statics/static-in-method-cannot-use-self.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//! Regression test for https://github.com/rust-lang/rust/issues/3668
//!
struct P {
child: Option<Box<P>>,
}
trait PTrait {
fn getChildOption(&self) -> Option<Box<P>>;
}

impl PTrait for P {
fn getChildOption(&self) -> Option<Box<P>> {
static childVal: Box<P> = self.child.get();
//~^ ERROR attempt to use a non-constant value in a constant
panic!();
}
}

fn main() {}
15 changes: 15 additions & 0 deletions tests/ui/statics/static-in-method-cannot-use-self.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error[E0435]: attempt to use a non-constant value in a constant
--> $DIR/static-in-method-cannot-use-self.rs:12:35
|
LL | static childVal: Box<P> = self.child.get();
| ^^^^ non-constant value
|
help: consider using `let` instead of `static`
|
LL - static childVal: Box<P> = self.child.get();
LL + let childVal: Box<P> = self.child.get();
|

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0435`.
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
//! Regression test for https://github.com/rust-lang/rust/issues/39367
//!
//! Tests that lazy static initialization using `Once` and `transmute`
//! works correctly with a struct that has a default type parameter.
Comment on lines +3 to +4
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove all such comments except this one

//@ run-pass

use std::ops::Deref;

struct ArenaSet<U: Deref, V=<U as Deref>::Target>(U, &'static V)
where V: 'static + ?Sized;
struct ArenaSet<U: Deref, V = <U as Deref>::Target>(U, &'static V)
where
V: 'static + ?Sized;

static Z: [u8; 4] = [1,2,3,4];
static Z: [u8; 4] = [1, 2, 3, 4];

fn arena() -> &'static ArenaSet<Vec<u8>> {
fn __static_ref_initialize() -> ArenaSet<Vec<u8>> {
ArenaSet(vec![], &Z)
}
unsafe {
use std::sync::Once;
fn require_sync<T: Sync>(_: &T) { }
fn require_sync<T: Sync>(_: &T) {}
unsafe fn __stability() -> &'static ArenaSet<Vec<u8>> {
use std::mem::transmute;
static mut DATA: *const ArenaSet<Vec<u8>> = std::ptr::null_mut();

static mut ONCE: Once = Once::new();
ONCE.call_once(|| {
//~^ WARN creating a shared reference to mutable static [static_mut_refs]
DATA = transmute
::<Box<ArenaSet<Vec<u8>>>, *const ArenaSet<Vec<u8>>>
(Box::new(__static_ref_initialize()));
//~^ WARN creating a shared reference to mutable static [static_mut_refs]
DATA = transmute::<Box<ArenaSet<Vec<u8>>>, *const ArenaSet<Vec<u8>>>(Box::new(
__static_ref_initialize(),
));
});

&*DATA
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
warning: creating a shared reference to mutable static
--> $DIR/issue-39367.rs:22:13
--> $DIR/static-lazy-init-with-arena-set.rs:27:13
|
LL | / ONCE.call_once(|| {
LL | |
LL | | DATA = transmute
LL | | ::<Box<ArenaSet<Vec<u8>>>, *const ArenaSet<Vec<u8>>>
LL | | (Box::new(__static_ref_initialize()));
LL | | DATA = transmute::<Box<ArenaSet<Vec<u8>>>, *const ArenaSet<Vec<u8>>>(Box::new(
LL | | __static_ref_initialize(),
LL | | ));
LL | | });
| |______________^ shared reference to mutable static
|
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Regression test for https://github.com/rust-lang/rust/issues/46604
//!
static buf: &mut [u8] = &mut [1u8,2,3,4,5,7]; //~ ERROR mutable borrows of temporaries
fn write<T: AsRef<[u8]>>(buffer: T) { }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0764]: mutable borrows of temporaries that have their lifetime extended until the end of the program are not allowed
--> $DIR/issue-46604.rs:1:25
--> $DIR/static-mut-borrow-of-temporary.rs:3:25
|
LL | static buf: &mut [u8] = &mut [1u8,2,3,4,5,7];
| ^^^^^^^^^^^^^^^^^^^^ this mutable borrow refers to such a temporary
Expand All @@ -9,7 +9,7 @@ LL | static buf: &mut [u8] = &mut [1u8,2,3,4,5,7];
= help: if you really want global mutable state, try replacing the temporary by an interior mutable `static` or a `static mut`

error[E0594]: cannot assign to `buf[_]`, as `buf` is an immutable static item
--> $DIR/issue-46604.rs:6:5
--> $DIR/static-mut-borrow-of-temporary.rs:8:5
|
LL | static buf: &mut [u8] = &mut [1u8,2,3,4,5,7];
| --------------------- this `static` cannot be written to
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
//! Regression test for https://github.com/rust-lang/rust/issues/29821
//!
//@ build-pass

pub trait Foo {
type FooAssoc;
}

pub struct Bar<F: Foo> {
id: F::FooAssoc
id: F::FooAssoc,
}

pub struct Baz;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Regression test for https://github.com/rust-lang/rust/issues/25901
//!
struct A;
struct B;

Expand All @@ -8,7 +10,10 @@ use std::ops::Deref;

impl Deref for A {
type Target = B;
fn deref(&self)->&B { static B_: B = B; &B_ }
fn deref(&self) -> &B {
static B_: B = B;
&B_
}
}

fn main(){}
fn main() {}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0277]: the trait bound `A: const Deref` is not satisfied
--> $DIR/issue-25901.rs:4:24
--> $DIR/static-ref-deref-non-const-trait.rs:6:24
|
LL | static S: &'static B = &A;
| ^^
Expand Down
Loading