Skip to content

Commit 5f086cc

Browse files
committed
tests: Add regression test for Debug impl of raw pointers
1 parent 8206d70 commit 5f086cc

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

library/Cargo.lock

+26
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ version = "0.0.0"
7979
dependencies = [
8080
"rand",
8181
"rand_xorshift",
82+
"regex",
8283
]
8384

8485
[[package]]
@@ -275,6 +276,31 @@ dependencies = [
275276
"rand_core",
276277
]
277278

279+
[[package]]
280+
name = "regex"
281+
version = "1.11.1"
282+
source = "registry+https://github.com/rust-lang/crates.io-index"
283+
checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191"
284+
dependencies = [
285+
"regex-automata",
286+
"regex-syntax",
287+
]
288+
289+
[[package]]
290+
name = "regex-automata"
291+
version = "0.4.9"
292+
source = "registry+https://github.com/rust-lang/crates.io-index"
293+
checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908"
294+
dependencies = [
295+
"regex-syntax",
296+
]
297+
298+
[[package]]
299+
name = "regex-syntax"
300+
version = "0.8.5"
301+
source = "registry+https://github.com/rust-lang/crates.io-index"
302+
checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
303+
278304
[[package]]
279305
name = "rustc-demangle"
280306
version = "0.1.24"

library/coretests/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ test = true
2525
[dev-dependencies]
2626
rand = { version = "0.8.5", default-features = false }
2727
rand_xorshift = { version = "0.3.0", default-features = false }
28+
regex = { version = "1.11.1", default-features = false }

library/coretests/tests/fmt/mod.rs

+31
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,37 @@ fn test_pointer_formats_data_pointer() {
1919
assert_eq!(format!("{b:p}"), format!("{:p}", b as *const _));
2020
}
2121

22+
#[test]
23+
fn test_fmt_debug_of_raw_pointers() {
24+
use core::fmt::Debug;
25+
26+
fn check_fmt<T: Debug>(t: T, expected: &str) {
27+
use std::sync::LazyLock;
28+
29+
use regex::Regex;
30+
31+
static ADDR_REGEX: LazyLock<Regex> =
32+
LazyLock::new(|| Regex::new(r"0x[0-9a-fA-F]+").unwrap());
33+
34+
let formatted = format!("{:?}", t);
35+
let normalized = ADDR_REGEX.replace_all(&formatted, "$$HEX");
36+
37+
assert_eq!(normalized, expected);
38+
}
39+
40+
let plain = &mut 100;
41+
check_fmt(plain as *mut i32, "$HEX");
42+
check_fmt(plain as *const i32, "$HEX");
43+
44+
let slice = &mut [200, 300, 400][..];
45+
check_fmt(slice as *mut [i32], "$HEX");
46+
check_fmt(slice as *const [i32], "$HEX");
47+
48+
let vtable = &mut 500 as &mut dyn Debug;
49+
check_fmt(vtable as *mut dyn Debug, "$HEX");
50+
check_fmt(vtable as *const dyn Debug, "$HEX");
51+
}
52+
2253
#[test]
2354
fn test_estimated_capacity() {
2455
assert_eq!(format_args!("").estimated_capacity(), 0);

0 commit comments

Comments
 (0)