Skip to content

Commit dd2f6dc

Browse files
committed
Run most core::num tests in const context too
1 parent 68e4d96 commit dd2f6dc

File tree

3 files changed

+539
-525
lines changed

3 files changed

+539
-525
lines changed

library/core/tests/lib.rs

+35
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,17 @@
1717
#![feature(const_align_of_val_raw)]
1818
#![feature(const_align_offset)]
1919
#![feature(const_array_from_ref)]
20+
#![feature(const_bigint_helper_methods)]
2021
#![feature(const_black_box)]
22+
#![feature(const_eval_select)]
2123
#![feature(const_hash)]
2224
#![feature(const_heap)]
2325
#![feature(const_ip)]
2426
#![feature(const_ipv4)]
2527
#![feature(const_ipv6)]
2628
#![feature(const_likely)]
2729
#![feature(const_nonnull_new)]
30+
#![feature(const_num_midpoint)]
2831
#![feature(const_option)]
2932
#![feature(const_option_ext)]
3033
#![feature(const_pin)]
@@ -55,6 +58,7 @@
5558
#![feature(get_many_mut)]
5659
#![feature(hasher_prefixfree_extras)]
5760
#![feature(hashmap_internals)]
61+
#![feature(inline_const_pat)]
5862
#![feature(int_roundings)]
5963
#![feature(ip)]
6064
#![feature(is_ascii_octdigit)]
@@ -113,6 +117,37 @@
113117
#![deny(fuzzy_provenance_casts)]
114118
#![deny(unsafe_op_in_unsafe_fn)]
115119

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

0 commit comments

Comments
 (0)