#[macro_use] extern crate rustc_data_structures;
extern crate rustc_serialize;
-use rustc_serialize::{Decodable, Decoder};
use rustc_data_structures::indexed_vec::Idx;
const fn i32_ops3(c: i32, d: i32) -> bool { c != d }
const fn i32_ops4(c: i32, d: i32) -> i32 { c + d }
const fn char_cast(u: u8) -> char { u as char }
-const unsafe fn foo4() -> i32 { 42 }
-const unsafe fn foo5<T>() -> *const T { 0 as *const T }
-const unsafe fn foo6<T>() -> *mut T { 0 as *mut T }
+const unsafe fn ret_i32_no_unsafe() -> i32 { 42 }
+const unsafe fn ret_null_ptr_no_unsafe<T>() -> *const T { 0 as *const T }
+const unsafe fn ret_null_mut_ptr_no_unsafe<T>() -> *mut T { 0 as *mut T }
// not ok
const fn foo11<T: std::fmt::Display>(t: T) -> T { t }
// gate-test-min_const_unsafe_fn
// ok
-const unsafe fn foo4() -> i32 { 42 }
-const unsafe fn foo5<T>() -> *const T { 0 as *const T }
-const unsafe fn foo6<T>() -> *mut T { 0 as *mut T }
+const unsafe fn ret_i32_no_unsafe() -> i32 { 42 }
+const unsafe fn ret_null_ptr_no_unsafe<T>() -> *const T { 0 as *const T }
+const unsafe fn ret_null_mut_ptr_no_unsafe<T>() -> *mut T { 0 as *mut T }
const fn no_unsafe() { unsafe {} }
// not ok
-const fn foo8() -> i32 {
- unsafe { foo4() } //~ ERROR calls to `const unsafe fn` in const fns are unstable
+const fn call_unsafe_const_fn() -> i32 {
+ unsafe { ret_i32_no_unsafe() } //~ ERROR calls to `const unsafe fn` in const fns are unstable
}
-const fn foo9() -> *const String {
- unsafe { foo5::<String>() } //~ ERROR calls to `const unsafe fn` in const fns are unstable
+const fn call_unsafe_generic_const_fn() -> *const String {
+ unsafe { ret_null_ptr_no_unsafe::<String>() }
+ //~^ ERROR calls to `const unsafe fn` in const fns are unstable
}
-const fn foo10() -> *const Vec<std::cell::Cell<u32>> {
- unsafe { foo6::<Vec<std::cell::Cell<u32>>>() } //~ ERROR calls to `const unsafe fn` in const fns
+const fn call_unsafe_generic_cell_const_fn() -> *const Vec<std::cell::Cell<u32>> {
+ unsafe { ret_null_mut_ptr_no_unsafe::<Vec<std::cell::Cell<u32>>>() }
+ //~^ ERROR calls to `const unsafe fn` in const fns
}
-const unsafe fn foo30_3(x: *mut usize) -> usize { *x } //~ ERROR not allowed in const fn
+const unsafe fn deref_forbidden(x: *mut usize) -> usize { *x } //~ ERROR not allowed in const fn
//~^ dereferencing raw pointers in constant functions
fn main() {}
error[E0658]: dereferencing raw pointers in constant functions is unstable (see issue #51911)
- --> $DIR/min_const_fn_unsafe.rs:29:51
+ --> $DIR/min_const_fn_unsafe.rs:31:59
|
-LL | const unsafe fn foo30_3(x: *mut usize) -> usize { *x } //~ ERROR not allowed in const fn
- | ^^
+LL | const unsafe fn deref_forbidden(x: *mut usize) -> usize { *x } //~ ERROR not allowed in const fn
+ | ^^
|
= help: add #![feature(const_raw_ptr_deref)] to the crate attributes to enable
error[E0658]: unions in const fn are unstable (see issue #51909)
- --> $DIR/min_const_fn_unsafe.rs:36:5
+ --> $DIR/min_const_fn_unsafe.rs:38:5
|
LL | Foo { x: () }.y //~ ERROR not allowed in const fn
| ^^^^^^^^^^^^^^^
error[E0658]: calls to `const unsafe fn` in const fns are unstable (see issue #55607)
--> $DIR/min_const_fn_unsafe.rs:21:14
|
-LL | unsafe { foo4() } //~ ERROR calls to `const unsafe fn` in const fns are unstable
- | ^^^^^^
+LL | unsafe { ret_i32_no_unsafe() } //~ ERROR calls to `const unsafe fn` in const fns are unstable
+ | ^^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(min_const_unsafe_fn)] to the crate attributes to enable
error[E0658]: calls to `const unsafe fn` in const fns are unstable (see issue #55607)
--> $DIR/min_const_fn_unsafe.rs:24:14
|
-LL | unsafe { foo5::<String>() } //~ ERROR calls to `const unsafe fn` in const fns are unstable
- | ^^^^^^^^^^^^^^^^
+LL | unsafe { ret_null_ptr_no_unsafe::<String>() }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(min_const_unsafe_fn)] to the crate attributes to enable
error[E0658]: calls to `const unsafe fn` in const fns are unstable (see issue #55607)
- --> $DIR/min_const_fn_unsafe.rs:27:14
+ --> $DIR/min_const_fn_unsafe.rs:28:14
|
-LL | unsafe { foo6::<Vec<std::cell::Cell<u32>>>() } //~ ERROR calls to `const unsafe fn` in const fns
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL | unsafe { ret_null_mut_ptr_no_unsafe::<Vec<std::cell::Cell<u32>>>() }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(min_const_unsafe_fn)] to the crate attributes to enable
error: dereference of raw pointer is unsafe and unsafe operations are not allowed in const fn
- --> $DIR/min_const_fn_unsafe.rs:29:51
+ --> $DIR/min_const_fn_unsafe.rs:31:59
|
-LL | const unsafe fn foo30_3(x: *mut usize) -> usize { *x } //~ ERROR not allowed in const fn
- | ^^ dereference of raw pointer
+LL | const unsafe fn deref_forbidden(x: *mut usize) -> usize { *x } //~ ERROR not allowed in const fn
+ | ^^ dereference of raw pointer
|
= note: raw pointers may be NULL, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior
error: access to union field is unsafe and unsafe operations are not allowed in const fn
- --> $DIR/min_const_fn_unsafe.rs:36:5
+ --> $DIR/min_const_fn_unsafe.rs:38:5
|
LL | Foo { x: () }.y //~ ERROR not allowed in const fn
| ^^^^^^^^^^^^^^^ access to union field
const unsafe fn foo30_4(x: *mut usize) -> &'static usize { &*x } //~ ERROR not allowed in const fn
//~^ dereferencing raw pointers in constant functions
+const fn foo30_5(x: *mut usize) -> &'static usize { unsafe { &*x } } //~ ERROR not allowed
+//~^ dereferencing raw pointers in constant functions
+
fn main() {}
const unsafe fn no_union() {
|
= help: add #![feature(const_raw_ptr_deref)] to the crate attributes to enable
+error[E0658]: dereferencing raw pointers in constant functions is unstable (see issue #51911)
+ --> $DIR/min_const_fn_unsafe_feature_gate.rs:53:62
+ |
+LL | const fn foo30_5(x: *mut usize) -> &'static usize { unsafe { &*x } } //~ ERROR not allowed
+ | ^^^
+ |
+ = help: add #![feature(const_raw_ptr_deref)] to the crate attributes to enable
+
error[E0658]: unions in const fn are unstable (see issue #51909)
- --> $DIR/min_const_fn_unsafe_feature_gate.rs:57:5
+ --> $DIR/min_const_fn_unsafe_feature_gate.rs:60:5
|
LL | Foo { x: () }.y //~ ERROR not allowed in const fn
| ^^^^^^^^^^^^^^^
|
= note: raw pointers may be NULL, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior
+error: dereference of raw pointer is unsafe and unsafe operations are not allowed in const fn
+ --> $DIR/min_const_fn_unsafe_feature_gate.rs:53:62
+ |
+LL | const fn foo30_5(x: *mut usize) -> &'static usize { unsafe { &*x } } //~ ERROR not allowed
+ | ^^^ dereference of raw pointer
+ |
+ = note: raw pointers may be NULL, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior
+
error: access to union field is unsafe and unsafe operations are not allowed in const fn
- --> $DIR/min_const_fn_unsafe_feature_gate.rs:57:5
+ --> $DIR/min_const_fn_unsafe_feature_gate.rs:60:5
|
LL | Foo { x: () }.y //~ ERROR not allowed in const fn
| ^^^^^^^^^^^^^^^ access to union field
|
= note: the field may not be properly initialized: using uninitialized data will cause undefined behavior
-error: aborting due to 9 previous errors
+error: aborting due to 11 previous errors
For more information about this error, try `rustc --explain E0658`.
const fn foo() -> NonZero<u32> {
let mut x = unsafe { NonZero(1) };
- x.0 = 0; //~ ERROR statements in constant functions are unstable
+ x.0 = 0;
//~^ ERROR mutation of layout constrained field is unsafe
x
}
const fn bar() -> NonZero<u32> {
let mut x = unsafe { NonZero(1) };
- unsafe { x.0 = 0 }; //~ ERROR statements in constant functions are unstable
+ unsafe { x.0 = 0 }; // this is UB
x
}
-error[E0658]: statements in constant functions are unstable (see issue #48821)
- --> $DIR/ranged_ints4_const.rs:10:5
- |
-LL | x.0 = 0; //~ ERROR statements in constant functions are unstable
- | ^^^^^^^
- |
- = help: add #![feature(const_let)] to the crate attributes to enable
-
-error[E0658]: statements in constant functions are unstable (see issue #48821)
- --> $DIR/ranged_ints4_const.rs:17:14
- |
-LL | unsafe { x.0 = 0 }; //~ ERROR statements in constant functions are unstable
- | ^^^^^^^
- |
- = help: add #![feature(const_let)] to the crate attributes to enable
-
error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block
--> $DIR/ranged_ints4_const.rs:10:5
|
-LL | x.0 = 0; //~ ERROR statements in constant functions are unstable
+LL | x.0 = 0;
| ^^^^^^^ mutation of layout constrained field
|
= note: mutating layout constrained fields cannot statically be checked for valid values
-error: aborting due to 3 previous errors
+error: aborting due to previous error
-Some errors occurred: E0133, E0658.
-For more information about an error, try `rustc --explain E0133`.
+For more information about this error, try `rustc --explain E0133`.