Skip to content

Commit 1602487

Browse files
committed
Run most core::num tests in const context too
1 parent 9322d18 commit 1602487

File tree

3 files changed

+541
-525
lines changed

3 files changed

+541
-525
lines changed

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

+37
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,16 @@
1616
#![feature(clone_to_uninit)]
1717
#![feature(const_align_of_val_raw)]
1818
#![feature(const_align_offset)]
19+
#![feature(const_array_from_ref)]
20+
#![feature(const_bigint_helper_methods)]
1921
#![feature(const_black_box)]
22+
#![feature(const_eval_select)]
2023
#![feature(const_hash)]
2124
#![feature(const_heap)]
2225
#![feature(const_likely)]
2326
#![feature(const_nonnull_new)]
27+
#![feature(const_num_midpoint)]
28+
#![feature(const_option)]
2429
#![feature(const_option_ext)]
2530
#![feature(const_pin)]
2631
#![feature(const_pointer_is_aligned)]
@@ -45,6 +50,7 @@
4550
#![feature(get_many_mut)]
4651
#![feature(hasher_prefixfree_extras)]
4752
#![feature(hashmap_internals)]
53+
#![feature(inline_const_pat)]
4854
#![feature(int_roundings)]
4955
#![feature(ip)]
5056
#![feature(ip_from)]
@@ -104,6 +110,37 @@
104110
#![deny(fuzzy_provenance_casts)]
105111
#![deny(unsafe_op_in_unsafe_fn)]
106112

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

0 commit comments

Comments
 (0)