diff --git a/src/compile_test.rs b/src/compile_test.rs index 28100085..1d425433 100644 --- a/src/compile_test.rs +++ b/src/compile_test.rs @@ -705,17 +705,20 @@ run_test! {intrinsics,catch,stable} run_test! {intrinsics,cmp_bytes,stable} run_test! {intrinsics,copy_nonoverlaping,stable} run_test! {intrinsics,ctpop,stable} +run_test! {intrinsics,is_val_statically_known,stable} run_test! {intrinsics,malloc,stable} run_test! {intrinsics,offset_of,unstable} run_test! {intrinsics,overflow_ops,stable} run_test! {intrinsics,pow_sqrt,stable} run_test! {intrinsics,printf,stable} +run_test! {intrinsics,ptr_mask,stable} run_test! {intrinsics,ptr_offset_from_unsigned,stable} run_test! {intrinsics,round,stable} run_test! {intrinsics,size_of_val,stable} run_test! {intrinsics,transmute,stable} run_test! {intrinsics,trigonometry,stable} run_test! {intrinsics,type_id,stable} +run_test! {intrinsics,type_name,stable} run_test! {intrinsics,wrapping_ops,stable} run_test! {iter,fold,stable} run_test! {statics,thread_local,stable} diff --git a/test/intrinsics/is_val_statically_known.rs b/test/intrinsics/is_val_statically_known.rs new file mode 100644 index 00000000..74127d21 --- /dev/null +++ b/test/intrinsics/is_val_statically_known.rs @@ -0,0 +1,38 @@ +#![feature( + lang_items, + adt_const_params, + associated_type_defaults, + core_intrinsics, + start, + unsized_const_params +)] +#![allow(internal_features, incomplete_features, unused_variables, dead_code)] +#![no_std] +include!("../common.rs"); +extern crate core; + +use core::intrinsics::is_val_statically_known; + +fn main() { + test_eq!(is_val_statically_known(42), black_box(true)); + test_eq!(is_val_statically_known([42]), black_box(false)); + test_eq!(is_val_statically_known("42"), black_box(false)); + test_eq!(is_val_statically_known(FortyTwo {}), black_box(false)); + test_eq!( + is_val_statically_known(FortyTwo {}.forty_two()), + black_box(false) + ); +} + +#[derive(Copy, Clone)] +struct FortyTwo {} + +trait Return { + fn forty_two(&self) -> usize; +} + +impl Return for FortyTwo { + fn forty_two(&self) -> usize { + 42 + } +} diff --git a/test/intrinsics/ptr_mask.rs b/test/intrinsics/ptr_mask.rs new file mode 100644 index 00000000..ec43d4ee --- /dev/null +++ b/test/intrinsics/ptr_mask.rs @@ -0,0 +1,38 @@ +#![feature( + lang_items, + adt_const_params, + associated_type_defaults, + core_intrinsics, + start, + unsized_const_params, + ptr_mask, + strict_provenance +)] +#![allow(internal_features, incomplete_features, unused_variables, dead_code)] +#![no_std] +include!("../common.rs"); +extern crate core; + +use core::intrinsics::ptr_mask; + +fn main() { + let v = 17_u32; + let ptr: *const u32 = &v; + + // `u32` is 4 bytes aligned, + // which means that lower 2 bits are always 0. + let tag_mask = 0b11; + let mask = !tag_mask; + + // We can store something in these lower bits + let tagged_ptr = ptr.map_addr(|a| a | 0b10); + + // Get the "tag" back + let tag = tagged_ptr.addr() & tag_mask; + assert_eq!(tag, black_box(0b10)); + + // Note that `tagged_ptr` is unaligned, it's UB to read from it. + // To get original pointer `mask` can be used: + let masked_ptr = ptr_mask(tagged_ptr, mask); + assert_eq!(unsafe { *masked_ptr }, black_box(17)); +} diff --git a/test/intrinsics/type_name.rs b/test/intrinsics/type_name.rs new file mode 100644 index 00000000..f1c231d1 --- /dev/null +++ b/test/intrinsics/type_name.rs @@ -0,0 +1,27 @@ +#![feature( + lang_items, + adt_const_params, + associated_type_defaults, + core_intrinsics, + start, + unsized_const_params +)] +#![allow( + internal_features, + incomplete_features, + unused_variables, + dead_code, + unused_imports +)] +#![no_std] + +use core::intrinsics::type_name; + +include!("../common.rs"); + +fn main() { + test_eq!( + type_name::>(), + black_box("core::option::Option") + ); +}