Skip to content

Commit

Permalink
Use const eval instead of const fn
Browse files Browse the repository at this point in the history
  • Loading branch information
TimDiekmann committed Feb 26, 2019
1 parent baea3c7 commit c5f3830
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
17 changes: 6 additions & 11 deletions src/test/run-pass/consts/const-ptr-nonnull.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,14 @@

use std::ptr::NonNull;

const fn dangling() -> NonNull<u32> {
NonNull::dangling()
}
const DANGLING: NonNull<u32> = NonNull::dangling();
const CASTED: NonNull<u32> = NonNull::cast(NonNull::<i32>::dangling());

const fn cast<T, U>(non_null: NonNull<T>) -> NonNull<U> {
non_null.cast()
fn ident<T>(ident: T) -> T {
ident
}

pub fn main() {
assert_eq!(dangling(), NonNull::dangling());

let mut i: i32 = 10;
let non_null_t = NonNull::new(&mut i).unwrap();
let non_null_u: NonNull<u32> = cast(non_null_t);
assert_eq!(non_null_t.as_ptr(), non_null_u.as_ptr() as *mut i32);
assert_eq!(DANGLING, ident(NonNull::dangling()));
assert_eq!(CASTED, ident(NonNull::dangling()));
}
10 changes: 5 additions & 5 deletions src/test/run-pass/consts/const-ptr-unique.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

use std::ptr::Unique;

const fn as_ptr<T>(ptr: Unique<T>) -> *mut T {
ptr.as_ptr()
const PTR: *mut u32 = Unique::empty().as_ptr();

fn ident<T>(ident: T) -> T {
ident
}

pub fn main() {
let mut i: i32 = 10;
let unique = Unique::new(&mut i).unwrap();
assert_eq!(unique.as_ptr(), as_ptr(unique));
assert_eq!(PTR, ident(Unique::<u32>::empty().as_ptr()));
}

0 comments on commit c5f3830

Please sign in to comment.