Skip to content

Commit 2eaf1cb

Browse files
committed
Remove the regex dependency from coretests
It is only used by a single test, yet would take up unnecessary space once stdlib deps get vendored.
1 parent d2d682f commit 2eaf1cb

File tree

3 files changed

+11
-46
lines changed

3 files changed

+11
-46
lines changed

Cargo.lock

-26
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coretests/Cargo.toml

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

coretests/tests/fmt/mod.rs

+11-19
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,24 @@ fn test_pointer_formats_data_pointer() {
2222
#[test]
2323
fn test_fmt_debug_of_raw_pointers() {
2424
use core::fmt::Debug;
25+
use core::ptr;
2526

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-
27+
fn check_fmt<T: Debug>(t: T, start: &str, contains: &str) {
3428
let formatted = format!("{:?}", t);
35-
let normalized = ADDR_REGEX.replace_all(&formatted, "$$HEX");
36-
37-
assert_eq!(normalized, expected);
29+
assert!(formatted.starts_with(start), "{formatted:?} doesn't start with {start:?}");
30+
assert!(formatted.contains(contains), "{formatted:?} doesn't contain {contains:?}");
3831
}
3932

40-
let plain = &mut 100;
41-
check_fmt(plain as *mut i32, "$HEX");
42-
check_fmt(plain as *const i32, "$HEX");
33+
assert_eq!(format!("{:?}", ptr::without_provenance_mut::<i32>(0x100)), "0x100");
34+
assert_eq!(format!("{:?}", ptr::without_provenance::<i32>(0x100)), "0x100");
4335

44-
let slice = &mut [200, 300, 400][..];
45-
check_fmt(slice as *mut [i32], "Pointer { addr: $HEX, metadata: 3 }");
46-
check_fmt(slice as *const [i32], "Pointer { addr: $HEX, metadata: 3 }");
36+
let slice = ptr::slice_from_raw_parts(ptr::without_provenance::<i32>(0x100), 3);
37+
assert_eq!(format!("{:?}", slice as *mut [i32]), "Pointer { addr: 0x100, metadata: 3 }");
38+
assert_eq!(format!("{:?}", slice as *const [i32]), "Pointer { addr: 0x100, metadata: 3 }");
4739

4840
let vtable = &mut 500 as &mut dyn Debug;
49-
check_fmt(vtable as *mut dyn Debug, "Pointer { addr: $HEX, metadata: DynMetadata($HEX) }");
50-
check_fmt(vtable as *const dyn Debug, "Pointer { addr: $HEX, metadata: DynMetadata($HEX) }");
41+
check_fmt(vtable as *mut dyn Debug, "Pointer { addr: ", ", metadata: DynMetadata(");
42+
check_fmt(vtable as *const dyn Debug, "Pointer { addr: ", ", metadata: DynMetadata(");
5143
}
5244

5345
#[test]

0 commit comments

Comments
 (0)