Add test for dereferencing raw pointers and immediately referencing again
This commit is contained in:
parent
906a49eef2
commit
cc3470ce3b
2 changed files with 22 additions and 3 deletions
|
@ -47,6 +47,9 @@ const unsafe fn foo10_2() -> *const Vec<std::cell::Cell<u32>> {
|
|||
const unsafe fn foo30_3(x: *mut usize) -> usize { *x } //~ ERROR not allowed in const fn
|
||||
//~^ dereferencing raw pointers in constant functions
|
||||
|
||||
const unsafe fn foo30_4(x: *mut usize) -> &'static usize { &*x } //~ ERROR not allowed in const fn
|
||||
//~^ dereferencing raw pointers in constant functions
|
||||
|
||||
fn main() {}
|
||||
|
||||
const unsafe fn no_union() {
|
||||
|
|
|
@ -6,8 +6,16 @@ LL | const unsafe fn foo30_3(x: *mut usize) -> usize { *x } //~ ERROR not allowe
|
|||
|
|
||||
= 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:50:60
|
||||
|
|
||||
LL | const unsafe fn foo30_4(x: *mut usize) -> &'static 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_feature_gate.rs:54:5
|
||||
--> $DIR/min_const_fn_unsafe_feature_gate.rs:57:5
|
||||
|
|
||||
LL | Foo { x: () }.y //~ ERROR not allowed in const fn
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
@ -46,14 +54,22 @@ LL | const unsafe fn foo30_3(x: *mut usize) -> usize { *x } //~ ERROR not allowe
|
|||
|
|
||||
= 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:50:60
|
||||
|
|
||||
LL | const unsafe fn foo30_4(x: *mut usize) -> &'static 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_feature_gate.rs:54:5
|
||||
--> $DIR/min_const_fn_unsafe_feature_gate.rs:57: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 7 previous errors
|
||||
error: aborting due to 9 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
||||
|
|
Loading…
Reference in a new issue