Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/compile_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
38 changes: 38 additions & 0 deletions test/intrinsics/is_val_statically_known.rs
Original file line number Diff line number Diff line change
@@ -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
}
}
38 changes: 38 additions & 0 deletions test/intrinsics/ptr_mask.rs
Original file line number Diff line number Diff line change
@@ -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));
}
27 changes: 27 additions & 0 deletions test/intrinsics/type_name.rs
Original file line number Diff line number Diff line change
@@ -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::<Option<u32>>(),
black_box("core::option::Option<core::primitive::u32>")
);
}