Auto merge of #123181 - stepancheg:pointee-metadata-debug, r=the8472,Amanieu

Require Debug for Pointee::Metadata

Useful for debugging.
This commit is contained in:
bors 2024-03-31 00:09:41 +00:00
commit 1aedc9640c
2 changed files with 10 additions and 2 deletions

View File

@ -57,7 +57,7 @@ pub trait Pointee {
// NOTE: Keep trait bounds in `static_assert_expected_bounds_for_metadata`
// in `library/core/src/ptr/metadata.rs`
// 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”.

View File

@ -841,11 +841,19 @@ fn ptr_metadata_bounds() {
fn static_assert_expected_bounds_for_metadata<Meta>()
where
// 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]
fn dyn_metadata() {
#[derive(Debug)]