diff options
| author | bors <bors@rust-lang.org> | 2024-03-31 00:09:41 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-03-31 00:09:41 +0000 |
| commit | 1aedc9640cd740976f49480c4efefe0c0311fbb9 (patch) | |
| tree | 0938489032aaa4ee03f637e911e37a84d8ed108a | |
| parent | 5da1a1b59a52339845804fa39b1a21b7322a513f (diff) | |
| parent | b110cb3dc6da68fc46b08d7b0ed40a48b3503306 (diff) | |
| download | rust-1aedc9640cd740976f49480c4efefe0c0311fbb9.tar.gz rust-1aedc9640cd740976f49480c4efefe0c0311fbb9.zip | |
Auto merge of #123181 - stepancheg:pointee-metadata-debug, r=the8472,Amanieu
Require Debug for Pointee::Metadata Useful for debugging.
| -rw-r--r-- | library/core/src/ptr/metadata.rs | 2 | ||||
| -rw-r--r-- | library/core/tests/ptr.rs | 10 |
2 files changed, 10 insertions, 2 deletions
diff --git a/library/core/src/ptr/metadata.rs b/library/core/src/ptr/metadata.rs index 7f9d8e677d2..9b5da935e07 100644 --- a/library/core/src/ptr/metadata.rs +++ b/library/core/src/ptr/metadata.rs @@ -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”. diff --git a/library/core/tests/ptr.rs b/library/core/tests/ptr.rs index 5c518e2d593..f0656f997fd 100644 --- a/library/core/tests/ptr.rs +++ b/library/core/tests/ptr.rs @@ -841,12 +841,20 @@ 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)] #[repr(align(32))] |
