Skip to content

Commit ae0b00c

Browse files
committed
Add and update tests
1 parent 137a640 commit ae0b00c

File tree

8 files changed

+57
-54
lines changed

8 files changed

+57
-54
lines changed

src/test/run-pass-fulldeps/newtype_index.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
#[macro_use] extern crate rustc_data_structures;
44
extern crate rustc_serialize;
5-
use rustc_serialize::{Decodable, Decoder};
65

76
use rustc_data_structures::indexed_vec::Idx;
87

src/test/ui/consts/min_const_fn/min_const_fn.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ const fn i32_ops2(c: i32, d: i32) -> bool { c < d }
7878
const fn i32_ops3(c: i32, d: i32) -> bool { c != d }
7979
const fn i32_ops4(c: i32, d: i32) -> i32 { c + d }
8080
const fn char_cast(u: u8) -> char { u as char }
81-
const unsafe fn foo4() -> i32 { 42 }
82-
const unsafe fn foo5<T>() -> *const T { 0 as *const T }
83-
const unsafe fn foo6<T>() -> *mut T { 0 as *mut T }
81+
const unsafe fn ret_i32_no_unsafe() -> i32 { 42 }
82+
const unsafe fn ret_null_ptr_no_unsafe<T>() -> *const T { 0 as *const T }
83+
const unsafe fn ret_null_mut_ptr_no_unsafe<T>() -> *mut T { 0 as *mut T }
8484

8585
// not ok
8686
const fn foo11<T: std::fmt::Display>(t: T) -> T { t }

src/test/ui/consts/min_const_fn/min_const_fn_unsafe.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,24 @@
1111
// gate-test-min_const_unsafe_fn
1212

1313
// ok
14-
const unsafe fn foo4() -> i32 { 42 }
15-
const unsafe fn foo5<T>() -> *const T { 0 as *const T }
16-
const unsafe fn foo6<T>() -> *mut T { 0 as *mut T }
14+
const unsafe fn ret_i32_no_unsafe() -> i32 { 42 }
15+
const unsafe fn ret_null_ptr_no_unsafe<T>() -> *const T { 0 as *const T }
16+
const unsafe fn ret_null_mut_ptr_no_unsafe<T>() -> *mut T { 0 as *mut T }
1717
const fn no_unsafe() { unsafe {} }
1818

1919
// not ok
20-
const fn foo8() -> i32 {
21-
unsafe { foo4() } //~ ERROR calls to `const unsafe fn` in const fns are unstable
20+
const fn call_unsafe_const_fn() -> i32 {
21+
unsafe { ret_i32_no_unsafe() } //~ ERROR calls to `const unsafe fn` in const fns are unstable
2222
}
23-
const fn foo9() -> *const String {
24-
unsafe { foo5::<String>() } //~ ERROR calls to `const unsafe fn` in const fns are unstable
23+
const fn call_unsafe_generic_const_fn() -> *const String {
24+
unsafe { ret_null_ptr_no_unsafe::<String>() }
25+
//~^ ERROR calls to `const unsafe fn` in const fns are unstable
2526
}
26-
const fn foo10() -> *const Vec<std::cell::Cell<u32>> {
27-
unsafe { foo6::<Vec<std::cell::Cell<u32>>>() } //~ ERROR calls to `const unsafe fn` in const fns
27+
const fn call_unsafe_generic_cell_const_fn() -> *const Vec<std::cell::Cell<u32>> {
28+
unsafe { ret_null_mut_ptr_no_unsafe::<Vec<std::cell::Cell<u32>>>() }
29+
//~^ ERROR calls to `const unsafe fn` in const fns
2830
}
29-
const unsafe fn foo30_3(x: *mut usize) -> usize { *x } //~ ERROR not allowed in const fn
31+
const unsafe fn deref_forbidden(x: *mut usize) -> usize { *x } //~ ERROR not allowed in const fn
3032
//~^ dereferencing raw pointers in constant functions
3133

3234
fn main() {}

src/test/ui/consts/min_const_fn/min_const_fn_unsafe.stderr

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
error[E0658]: dereferencing raw pointers in constant functions is unstable (see issue #51911)
2-
--> $DIR/min_const_fn_unsafe.rs:29:51
2+
--> $DIR/min_const_fn_unsafe.rs:31:59
33
|
4-
LL | const unsafe fn foo30_3(x: *mut usize) -> usize { *x } //~ ERROR not allowed in const fn
5-
| ^^
4+
LL | const unsafe fn deref_forbidden(x: *mut usize) -> usize { *x } //~ ERROR not allowed in const fn
5+
| ^^
66
|
77
= help: add #![feature(const_raw_ptr_deref)] to the crate attributes to enable
88

99
error[E0658]: unions in const fn are unstable (see issue #51909)
10-
--> $DIR/min_const_fn_unsafe.rs:36:5
10+
--> $DIR/min_const_fn_unsafe.rs:38:5
1111
|
1212
LL | Foo { x: () }.y //~ ERROR not allowed in const fn
1313
| ^^^^^^^^^^^^^^^
@@ -17,37 +17,37 @@ LL | Foo { x: () }.y //~ ERROR not allowed in const fn
1717
error[E0658]: calls to `const unsafe fn` in const fns are unstable (see issue #55607)
1818
--> $DIR/min_const_fn_unsafe.rs:21:14
1919
|
20-
LL | unsafe { foo4() } //~ ERROR calls to `const unsafe fn` in const fns are unstable
21-
| ^^^^^^
20+
LL | unsafe { ret_i32_no_unsafe() } //~ ERROR calls to `const unsafe fn` in const fns are unstable
21+
| ^^^^^^^^^^^^^^^^^^^
2222
|
2323
= help: add #![feature(min_const_unsafe_fn)] to the crate attributes to enable
2424

2525
error[E0658]: calls to `const unsafe fn` in const fns are unstable (see issue #55607)
2626
--> $DIR/min_const_fn_unsafe.rs:24:14
2727
|
28-
LL | unsafe { foo5::<String>() } //~ ERROR calls to `const unsafe fn` in const fns are unstable
29-
| ^^^^^^^^^^^^^^^^
28+
LL | unsafe { ret_null_ptr_no_unsafe::<String>() }
29+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3030
|
3131
= help: add #![feature(min_const_unsafe_fn)] to the crate attributes to enable
3232

3333
error[E0658]: calls to `const unsafe fn` in const fns are unstable (see issue #55607)
34-
--> $DIR/min_const_fn_unsafe.rs:27:14
34+
--> $DIR/min_const_fn_unsafe.rs:28:14
3535
|
36-
LL | unsafe { foo6::<Vec<std::cell::Cell<u32>>>() } //~ ERROR calls to `const unsafe fn` in const fns
37-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
36+
LL | unsafe { ret_null_mut_ptr_no_unsafe::<Vec<std::cell::Cell<u32>>>() }
37+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3838
|
3939
= help: add #![feature(min_const_unsafe_fn)] to the crate attributes to enable
4040

4141
error: dereference of raw pointer is unsafe and unsafe operations are not allowed in const fn
42-
--> $DIR/min_const_fn_unsafe.rs:29:51
42+
--> $DIR/min_const_fn_unsafe.rs:31:59
4343
|
44-
LL | const unsafe fn foo30_3(x: *mut usize) -> usize { *x } //~ ERROR not allowed in const fn
45-
| ^^ dereference of raw pointer
44+
LL | const unsafe fn deref_forbidden(x: *mut usize) -> usize { *x } //~ ERROR not allowed in const fn
45+
| ^^ dereference of raw pointer
4646
|
4747
= note: raw pointers may be NULL, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior
4848

4949
error: access to union field is unsafe and unsafe operations are not allowed in const fn
50-
--> $DIR/min_const_fn_unsafe.rs:36:5
50+
--> $DIR/min_const_fn_unsafe.rs:38:5
5151
|
5252
LL | Foo { x: () }.y //~ ERROR not allowed in const fn
5353
| ^^^^^^^^^^^^^^^ access to union field

src/test/ui/consts/min_const_fn/min_const_fn_unsafe_feature_gate.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ const unsafe fn foo30_3(x: *mut usize) -> usize { *x } //~ ERROR not allowed in
5050
const unsafe fn foo30_4(x: *mut usize) -> &'static usize { &*x } //~ ERROR not allowed in const fn
5151
//~^ dereferencing raw pointers in constant functions
5252

53+
const fn foo30_5(x: *mut usize) -> &'static usize { unsafe { &*x } } //~ ERROR not allowed
54+
//~^ dereferencing raw pointers in constant functions
55+
5356
fn main() {}
5457

5558
const unsafe fn no_union() {

src/test/ui/consts/min_const_fn/min_const_fn_unsafe_feature_gate.stderr

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,16 @@ LL | const unsafe fn foo30_4(x: *mut usize) -> &'static usize { &*x } //~ ERROR
1414
|
1515
= help: add #![feature(const_raw_ptr_deref)] to the crate attributes to enable
1616

17+
error[E0658]: dereferencing raw pointers in constant functions is unstable (see issue #51911)
18+
--> $DIR/min_const_fn_unsafe_feature_gate.rs:53:62
19+
|
20+
LL | const fn foo30_5(x: *mut usize) -> &'static usize { unsafe { &*x } } //~ ERROR not allowed
21+
| ^^^
22+
|
23+
= help: add #![feature(const_raw_ptr_deref)] to the crate attributes to enable
24+
1725
error[E0658]: unions in const fn are unstable (see issue #51909)
18-
--> $DIR/min_const_fn_unsafe_feature_gate.rs:57:5
26+
--> $DIR/min_const_fn_unsafe_feature_gate.rs:60:5
1927
|
2028
LL | Foo { x: () }.y //~ ERROR not allowed in const fn
2129
| ^^^^^^^^^^^^^^^
@@ -62,14 +70,22 @@ LL | const unsafe fn foo30_4(x: *mut usize) -> &'static usize { &*x } //~ ERROR
6270
|
6371
= note: raw pointers may be NULL, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior
6472

73+
error: dereference of raw pointer is unsafe and unsafe operations are not allowed in const fn
74+
--> $DIR/min_const_fn_unsafe_feature_gate.rs:53:62
75+
|
76+
LL | const fn foo30_5(x: *mut usize) -> &'static usize { unsafe { &*x } } //~ ERROR not allowed
77+
| ^^^ dereference of raw pointer
78+
|
79+
= note: raw pointers may be NULL, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior
80+
6581
error: access to union field is unsafe and unsafe operations are not allowed in const fn
66-
--> $DIR/min_const_fn_unsafe_feature_gate.rs:57:5
82+
--> $DIR/min_const_fn_unsafe_feature_gate.rs:60:5
6783
|
6884
LL | Foo { x: () }.y //~ ERROR not allowed in const fn
6985
| ^^^^^^^^^^^^^^^ access to union field
7086
|
7187
= note: the field may not be properly initialized: using uninitialized data will cause undefined behavior
7288

73-
error: aborting due to 9 previous errors
89+
error: aborting due to 11 previous errors
7490

7591
For more information about this error, try `rustc --explain E0658`.

src/test/ui/unsafe/ranged_ints4_const.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ fn main() {}
77

88
const fn foo() -> NonZero<u32> {
99
let mut x = unsafe { NonZero(1) };
10-
x.0 = 0; //~ ERROR statements in constant functions are unstable
10+
x.0 = 0;
1111
//~^ ERROR mutation of layout constrained field is unsafe
1212
x
1313
}
1414

1515
const fn bar() -> NonZero<u32> {
1616
let mut x = unsafe { NonZero(1) };
17-
unsafe { x.0 = 0 }; //~ ERROR statements in constant functions are unstable
17+
unsafe { x.0 = 0 }; // this is UB
1818
x
1919
}
Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,11 @@
1-
error[E0658]: statements in constant functions are unstable (see issue #48821)
2-
--> $DIR/ranged_ints4_const.rs:10:5
3-
|
4-
LL | x.0 = 0; //~ ERROR statements in constant functions are unstable
5-
| ^^^^^^^
6-
|
7-
= help: add #![feature(const_let)] to the crate attributes to enable
8-
9-
error[E0658]: statements in constant functions are unstable (see issue #48821)
10-
--> $DIR/ranged_ints4_const.rs:17:14
11-
|
12-
LL | unsafe { x.0 = 0 }; //~ ERROR statements in constant functions are unstable
13-
| ^^^^^^^
14-
|
15-
= help: add #![feature(const_let)] to the crate attributes to enable
16-
171
error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block
182
--> $DIR/ranged_ints4_const.rs:10:5
193
|
20-
LL | x.0 = 0; //~ ERROR statements in constant functions are unstable
4+
LL | x.0 = 0;
215
| ^^^^^^^ mutation of layout constrained field
226
|
237
= note: mutating layout constrained fields cannot statically be checked for valid values
248

25-
error: aborting due to 3 previous errors
9+
error: aborting due to previous error
2610

27-
Some errors occurred: E0133, E0658.
28-
For more information about an error, try `rustc --explain E0133`.
11+
For more information about this error, try `rustc --explain E0133`.

0 commit comments

Comments
 (0)