Skip to content

Commit b205bf1

Browse files
add issue link comments and bless
1 parent 2e30fef commit b205bf1

14 files changed

Lines changed: 76 additions & 34 deletions

tests/ui/statics/static-cannot-use-local-variable.fixed

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
//! Regression test for https://github.com/rust-lang/rust/issues/3521
2+
//!
3+
//! Tests that using a local variable in a `static` item inside a
4+
//! function body produces error E0435.
15
//@ run-rustfix
26
fn main() {
37
let foo = 100;

tests/ui/statics/static-cannot-use-local-variable.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
//! Regression test for https://github.com/rust-lang/rust/issues/3521
2+
//!
3+
//! Tests that using a local variable in a `static` item inside a
4+
//! function body produces error E0435.
15
//@ run-rustfix
26
fn main() {
37
let foo = 100;

tests/ui/statics/static-cannot-use-local-variable.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0435]: attempt to use a non-constant value in a constant
2-
--> $DIR/issue-3521-2.rs:5:23
2+
--> $DIR/static-cannot-use-local-variable.rs:9:23
33
|
44
LL | static y: isize = foo + 1;
55
| ^^^ non-constant value

tests/ui/statics/static-in-fn-cannot-use-param.fixed

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1+
//! Regression test for https://github.com/rust-lang/rust/issues/3668
2+
//!
3+
//! Tests that using a function parameter in a `static` item
4+
//! inside a function body produces error E0435 instead of
5+
//! crashing the compiler (ICE).
6+
17
//@ run-rustfix
28
#![allow(unused_variables, dead_code)]
3-
fn f(x:isize) {
9+
fn f(x: isize) {
410
let child: isize = x + 1;
511
//~^ ERROR attempt to use a non-constant value in a constant
612
}

tests/ui/statics/static-in-fn-cannot-use-param.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1+
//! Regression test for https://github.com/rust-lang/rust/issues/3668
2+
//!
3+
//! Tests that using a function parameter in a `static` item
4+
//! inside a function body produces error E0435 instead of
5+
//! crashing the compiler (ICE).
6+
17
//@ run-rustfix
28
#![allow(unused_variables, dead_code)]
3-
fn f(x:isize) {
9+
fn f(x: isize) {
410
static child: isize = x + 1;
511
//~^ ERROR attempt to use a non-constant value in a constant
612
}

tests/ui/statics/static-in-fn-cannot-use-param.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0435]: attempt to use a non-constant value in a constant
2-
--> $DIR/issue-3668-2.rs:4:27
2+
--> $DIR/static-in-fn-cannot-use-param.rs:10:27
33
|
44
LL | static child: isize = x + 1;
55
| ^ non-constant value
Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1-
struct P { child: Option<Box<P>> }
1+
//! Regression test for https://github.com/rust-lang/rust/issues/3668
2+
//!
3+
//! Tests that using `self` in a `static` item inside a trait impl
4+
//! method produces error E0435 instead of crashing the compiler.
5+
struct P {
6+
child: Option<Box<P>>,
7+
}
28
trait PTrait {
3-
fn getChildOption(&self) -> Option<Box<P>>;
9+
fn getChildOption(&self) -> Option<Box<P>>;
410
}
511

612
impl PTrait for P {
7-
fn getChildOption(&self) -> Option<Box<P>> {
8-
static childVal: Box<P> = self.child.get();
9-
//~^ ERROR attempt to use a non-constant value in a constant
10-
panic!();
11-
}
13+
fn getChildOption(&self) -> Option<Box<P>> {
14+
static childVal: Box<P> = self.child.get();
15+
//~^ ERROR attempt to use a non-constant value in a constant
16+
panic!();
17+
}
1218
}
1319

1420
fn main() {}

tests/ui/statics/static-in-method-cannot-use-self.stderr

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
error[E0435]: attempt to use a non-constant value in a constant
2-
--> $DIR/issue-3668.rs:8:34
2+
--> $DIR/static-in-method-cannot-use-self.rs:14:35
33
|
4-
LL | static childVal: Box<P> = self.child.get();
5-
| ^^^^ non-constant value
4+
LL | static childVal: Box<P> = self.child.get();
5+
| ^^^^ non-constant value
66
|
77
help: consider using `let` instead of `static`
88
|
9-
LL - static childVal: Box<P> = self.child.get();
10-
LL + let childVal: Box<P> = self.child.get();
9+
LL - static childVal: Box<P> = self.child.get();
10+
LL + let childVal: Box<P> = self.child.get();
1111
|
1212

1313
error: aborting due to 1 previous error

tests/ui/statics/static-lazy-init-with-arena-set.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,34 @@
1+
//! Regression test for https://github.com/rust-lang/rust/issues/39367
2+
//!
3+
//! Tests that lazy static initialization using `Once` and `transmute`
4+
//! works correctly with a struct that has a default type parameter.
15
//@ run-pass
26

37
use std::ops::Deref;
48

5-
struct ArenaSet<U: Deref, V=<U as Deref>::Target>(U, &'static V)
6-
where V: 'static + ?Sized;
9+
struct ArenaSet<U: Deref, V = <U as Deref>::Target>(U, &'static V)
10+
where
11+
V: 'static + ?Sized;
712

8-
static Z: [u8; 4] = [1,2,3,4];
13+
static Z: [u8; 4] = [1, 2, 3, 4];
914

1015
fn arena() -> &'static ArenaSet<Vec<u8>> {
1116
fn __static_ref_initialize() -> ArenaSet<Vec<u8>> {
1217
ArenaSet(vec![], &Z)
1318
}
1419
unsafe {
1520
use std::sync::Once;
16-
fn require_sync<T: Sync>(_: &T) { }
21+
fn require_sync<T: Sync>(_: &T) {}
1722
unsafe fn __stability() -> &'static ArenaSet<Vec<u8>> {
1823
use std::mem::transmute;
1924
static mut DATA: *const ArenaSet<Vec<u8>> = std::ptr::null_mut();
2025

2126
static mut ONCE: Once = Once::new();
2227
ONCE.call_once(|| {
23-
//~^ WARN creating a shared reference to mutable static [static_mut_refs]
24-
DATA = transmute
25-
::<Box<ArenaSet<Vec<u8>>>, *const ArenaSet<Vec<u8>>>
26-
(Box::new(__static_ref_initialize()));
28+
//~^ WARN creating a shared reference to mutable static [static_mut_refs]
29+
DATA = transmute::<Box<ArenaSet<Vec<u8>>>, *const ArenaSet<Vec<u8>>>(Box::new(
30+
__static_ref_initialize(),
31+
));
2732
});
2833

2934
&*DATA

tests/ui/statics/static-lazy-init-with-arena-set.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
warning: creating a shared reference to mutable static
2-
--> $DIR/issue-39367.rs:22:13
2+
--> $DIR/static-lazy-init-with-arena-set.rs:27:13
33
|
44
LL | / ONCE.call_once(|| {
55
LL | |
6-
LL | | DATA = transmute
7-
LL | | ::<Box<ArenaSet<Vec<u8>>>, *const ArenaSet<Vec<u8>>>
8-
LL | | (Box::new(__static_ref_initialize()));
6+
LL | | DATA = transmute::<Box<ArenaSet<Vec<u8>>>, *const ArenaSet<Vec<u8>>>(Box::new(
7+
LL | | __static_ref_initialize(),
8+
LL | | ));
99
LL | | });
1010
| |______________^ shared reference to mutable static
1111
|

0 commit comments

Comments
 (0)