Skip to content

Commit acaf7e2

Browse files
committed
Run most core::num tests in const context too
1 parent ecb3830 commit acaf7e2

File tree

3 files changed

+539
-525
lines changed

3 files changed

+539
-525
lines changed

core/tests/lib.rs

+35
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@
1616
#![feature(clone_to_uninit)]
1717
#![feature(const_align_of_val_raw)]
1818
#![feature(const_align_offset)]
19+
#![feature(const_bigint_helper_methods)]
1920
#![feature(const_black_box)]
21+
#![feature(const_eval_select)]
2022
#![feature(const_hash)]
2123
#![feature(const_heap)]
2224
#![feature(const_likely)]
2325
#![feature(const_nonnull_new)]
26+
#![feature(const_num_midpoint)]
2427
#![feature(const_option_ext)]
2528
#![feature(const_pin)]
2629
#![feature(const_pointer_is_aligned)]
@@ -45,6 +48,7 @@
4548
#![feature(get_many_mut)]
4649
#![feature(hasher_prefixfree_extras)]
4750
#![feature(hashmap_internals)]
51+
#![feature(inline_const_pat)]
4852
#![feature(int_roundings)]
4953
#![feature(ip)]
5054
#![feature(ip_from)]
@@ -104,6 +108,37 @@
104108
#![deny(fuzzy_provenance_casts)]
105109
#![deny(unsafe_op_in_unsafe_fn)]
106110

111+
/// Version of `assert_matches` that ignores fancy runtime printing in const context and uses structural equality.
112+
macro_rules! assert_eq_const_safe {
113+
($left:expr, $right:expr$(, $($arg:tt)+)?) => {
114+
{
115+
fn runtime() {
116+
assert_eq!($left, $right, $($arg)*);
117+
}
118+
const fn compiletime() {
119+
assert!(matches!($left, const { $right }));
120+
}
121+
core::intrinsics::const_eval_select((), compiletime, runtime)
122+
}
123+
};
124+
}
125+
126+
/// Creates a test for runtime and a test for constant-time.
127+
macro_rules! test_runtime_and_compiletime {
128+
($(
129+
$(#[$attr:meta])*
130+
fn $test:ident() $block:block
131+
)*) => {
132+
$(
133+
$(#[$attr])*
134+
#[test]
135+
fn $test() $block
136+
$(#[$attr])*
137+
const _: () = $block;
138+
)*
139+
}
140+
}
141+
107142
mod alloc;
108143
mod any;
109144
mod array;

0 commit comments

Comments
 (0)