Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ impl<'tcx> InterpCx<'tcx, CompileTimeMachine<'tcx>> {
},
dest,
|ecx, place, (sig, fn_header)| {
let sig = sig.skip_binder(); // FIXME: handle lifetime bounds
// FIXME: handle lifetime bounds
let sig = ecx.tcx.instantiate_bound_regions_with_erased(*sig);
ecx.write_fn_ptr_type_info(place, &sig, fn_header)
},
)?
Expand Down
18 changes: 12 additions & 6 deletions library/coretests/tests/mem/fn_ptr.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use std::any::TypeId;
use std::mem::type_info::{Abi, FnPtr, TypeKind};
use std::mem::type_info::{Abi, TypeKind};

const STRING_TY: TypeId = const { TypeId::of::<String>() };
const U8_TY: TypeId = const { TypeId::of::<u8>() };
const UNIT_TY: TypeId = const { TypeId::of::<()>() };
const TUPLE_STRING_U8_TY: TypeId = const { TypeId::of::<(String, u8)>() };
const STATIC_REGION_UNIT_TY: TypeId = const { TypeId::of::<&'static ()>() };

#[test]
fn test_fn_ptrs() {
Expand All @@ -28,11 +29,16 @@ fn test_type() {

#[test]
fn test_ref() {
// references are tricky because the lifetimes give the references different type ids
// so we check the pointees instead
const F: FnPtr = TypeId::of::<fn(&u8, &u8)>().function_ptr().unwrap();
assert_eq!(const { F.inputs()[0].points_to() }, Some(U8_TY));
assert_eq!(const { F.inputs()[1].points_to() }, Some(U8_TY));
// function_ptr replaces bound regions with erased ones.
// So, check if TypeId of &'a () is identical to &'static ()
let f1 = const { TypeId::of::<for<'a> fn(&'a ()) -> &'a ()>().function_ptr().unwrap() };
assert_eq!(f1.inputs(), [STATIC_REGION_UNIT_TY]);
assert_eq!(f1.output(), STATIC_REGION_UNIT_TY);

// function_ptr() does not replace inner bound regions of a nested fn
let f2 =
const { TypeId::of::<for<'a> fn(for<'x> fn(&'x u8, &'a u8))>().function_ptr().unwrap() };
assert_eq!(f2.inputs(), [const { TypeId::of::<for<'x> fn(&'x u8, &'static u8)>() }]);
}

#[test]
Expand Down
11 changes: 11 additions & 0 deletions library/coretests/tests/mem/trait_info_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,24 @@ impl Blah for Garlic {
}
unsafe impl Send for Garlic {}

trait RefUnit {}
impl<'a> RefUnit for &'a () {}

#[test]
fn test_implements_trait() {
const {
assert!(TypeId::of::<Garlic>().trait_info_of::<dyn Blah>().is_some());
assert!(TypeId::of::<Garlic>().trait_info_of::<dyn Blah + Send>().is_some());
assert!(TypeId::of::<*const Box<Garlic>>().trait_info_of::<dyn Sync>().is_none());
assert!(TypeId::of::<u8>().trait_info_of_trait_type_id(TypeId::of::<dyn Blah>()).is_none());
assert!(
TypeId::of::<for<'a> fn(&'a ()) -> &'a ()>()
.function_ptr()
.unwrap()
.output()
.trait_info_of::<dyn RefUnit>()
.is_some()
);
}
}

Expand Down
Loading