Skip to content

Commit 1aedc96

Browse files
committed
Auto merge of #123181 - stepancheg:pointee-metadata-debug, r=the8472,Amanieu
Require Debug for Pointee::Metadata Useful for debugging.
2 parents 5da1a1b + b110cb3 commit 1aedc96

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

Diff for: library/core/src/ptr/metadata.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub trait Pointee {
5757
// NOTE: Keep trait bounds in `static_assert_expected_bounds_for_metadata`
5858
// in `library/core/src/ptr/metadata.rs`
5959
// in sync with those here:
60-
type Metadata: Copy + Send + Sync + Ord + Hash + Unpin;
60+
type Metadata: fmt::Debug + Copy + Send + Sync + Ord + Hash + Unpin;
6161
}
6262

6363
/// Pointers to types implementing this trait alias are “thin”.

Diff for: library/core/tests/ptr.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -841,11 +841,19 @@ fn ptr_metadata_bounds() {
841841
fn static_assert_expected_bounds_for_metadata<Meta>()
842842
where
843843
// Keep this in sync with the associated type in `library/core/src/ptr/metadata.rs`
844-
Meta: Copy + Send + Sync + Ord + std::hash::Hash + Unpin,
844+
Meta: Debug + Copy + Send + Sync + Ord + std::hash::Hash + Unpin,
845845
{
846846
}
847847
}
848848

849+
#[test]
850+
fn pointee_metadata_debug() {
851+
assert_eq!("()", format!("{:?}", metadata::<u32>(&17)));
852+
assert_eq!("2", format!("{:?}", metadata::<[u32]>(&[19, 23])));
853+
let for_dyn = format!("{:?}", metadata::<dyn Debug>(&29));
854+
assert!(for_dyn.starts_with("DynMetadata(0x"), "{:?}", for_dyn);
855+
}
856+
849857
#[test]
850858
fn dyn_metadata() {
851859
#[derive(Debug)]

0 commit comments

Comments
 (0)