Require Debug for Pointee::Metadata
Useful for debugging
This commit is contained in:
parent
db2f9759f4
commit
b110cb3dc6
2 changed files with 10 additions and 2 deletions
|
@ -57,7 +57,7 @@ pub trait Pointee {
|
||||||
// NOTE: Keep trait bounds in `static_assert_expected_bounds_for_metadata`
|
// NOTE: Keep trait bounds in `static_assert_expected_bounds_for_metadata`
|
||||||
// in `library/core/src/ptr/metadata.rs`
|
// in `library/core/src/ptr/metadata.rs`
|
||||||
// in sync with those here:
|
// in sync with those here:
|
||||||
type Metadata: Copy + Send + Sync + Ord + Hash + Unpin;
|
type Metadata: fmt::Debug + Copy + Send + Sync + Ord + Hash + Unpin;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Pointers to types implementing this trait alias are “thin”.
|
/// Pointers to types implementing this trait alias are “thin”.
|
||||||
|
|
|
@ -841,11 +841,19 @@ fn ptr_metadata_bounds() {
|
||||||
fn static_assert_expected_bounds_for_metadata<Meta>()
|
fn static_assert_expected_bounds_for_metadata<Meta>()
|
||||||
where
|
where
|
||||||
// Keep this in sync with the associated type in `library/core/src/ptr/metadata.rs`
|
// Keep this in sync with the associated type in `library/core/src/ptr/metadata.rs`
|
||||||
Meta: Copy + Send + Sync + Ord + std::hash::Hash + Unpin,
|
Meta: Debug + Copy + Send + Sync + Ord + std::hash::Hash + Unpin,
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn pointee_metadata_debug() {
|
||||||
|
assert_eq!("()", format!("{:?}", metadata::<u32>(&17)));
|
||||||
|
assert_eq!("2", format!("{:?}", metadata::<[u32]>(&[19, 23])));
|
||||||
|
let for_dyn = format!("{:?}", metadata::<dyn Debug>(&29));
|
||||||
|
assert!(for_dyn.starts_with("DynMetadata(0x"), "{:?}", for_dyn);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn dyn_metadata() {
|
fn dyn_metadata() {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue