Make Unique::as_ptr, NonNull::dangling and NonNull::cast const
Make `Unique::as_ptr` const without feature attribute as it's unstable Make `NonNull::dangling` and `NonNull::cast` const with `feature = "const_ptr_nonnull"`
This commit is contained in:
parent
7e001e5c6c
commit
797d8ea478
7 changed files with 97 additions and 3 deletions
11
src/test/ui/consts/const-ptr-nonnull.rs
Normal file
11
src/test/ui/consts/const-ptr-nonnull.rs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
use std::ptr::NonNull;
|
||||
|
||||
fn main() {
|
||||
let x: &'static NonNull<u32> = &(NonNull::dangling());
|
||||
//~^ ERROR borrowed value does not live long enough
|
||||
|
||||
let mut i: i32 = 10;
|
||||
let non_null = NonNull::new(&mut i).unwrap();
|
||||
let x: &'static NonNull<u32> = &(non_null.cast());
|
||||
//~^ ERROR borrowed value does not live long enough
|
||||
}
|
||||
25
src/test/ui/consts/const-ptr-nonnull.stderr
Normal file
25
src/test/ui/consts/const-ptr-nonnull.stderr
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
error[E0597]: borrowed value does not live long enough
|
||||
--> $DIR/const-ptr-nonnull.rs:4:37
|
||||
|
|
||||
LL | let x: &'static NonNull<u32> = &(NonNull::dangling());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ temporary value does not live long enough
|
||||
...
|
||||
LL | }
|
||||
| - temporary value only lives until here
|
||||
|
|
||||
= note: borrowed value must be valid for the static lifetime...
|
||||
|
||||
error[E0597]: borrowed value does not live long enough
|
||||
--> $DIR/const-ptr-nonnull.rs:9:37
|
||||
|
|
||||
LL | let x: &'static NonNull<u32> = &(non_null.cast());
|
||||
| ^^^^^^^^^^^^^^^^^ temporary value does not live long enough
|
||||
LL | //~^ ERROR borrowed value does not live long enough
|
||||
LL | }
|
||||
| - temporary value only lives until here
|
||||
|
|
||||
= note: borrowed value must be valid for the static lifetime...
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0597`.
|
||||
10
src/test/ui/consts/const-ptr-unique.rs
Normal file
10
src/test/ui/consts/const-ptr-unique.rs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#![feature(ptr_internals)]
|
||||
|
||||
use std::ptr::Unique;
|
||||
|
||||
fn main() {
|
||||
let mut i: u32 = 10;
|
||||
let unique = Unique::new(&mut i).unwrap();
|
||||
let x: &'static *mut u32 = &(unique.as_ptr());
|
||||
//~^ ERROR borrowed value does not live long enough
|
||||
}
|
||||
14
src/test/ui/consts/const-ptr-unique.stderr
Normal file
14
src/test/ui/consts/const-ptr-unique.stderr
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
error[E0597]: borrowed value does not live long enough
|
||||
--> $DIR/const-ptr-unique.rs:8:33
|
||||
|
|
||||
LL | let x: &'static *mut u32 = &(unique.as_ptr());
|
||||
| ^^^^^^^^^^^^^^^^^ temporary value does not live long enough
|
||||
LL | //~^ ERROR borrowed value does not live long enough
|
||||
LL | }
|
||||
| - temporary value only lives until here
|
||||
|
|
||||
= note: borrowed value must be valid for the static lifetime...
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0597`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue