Skip to content

Commit a85563f

Browse files
authored
Merge pull request #584 from wojciech-graj/main
Fix macro hygiene in user-facing macros.
2 parents 5331517 + cb376c0 commit a85563f

File tree

1 file changed

+40
-38
lines changed

1 file changed

+40
-38
lines changed

proptest/src/sugar.rs

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ macro_rules! proptest {
158158
$(#[$meta])*
159159
fn $test_name() {
160160
let mut config = $crate::test_runner::contextualize_config($config.clone());
161-
config.test_name = Some(
162-
concat!(module_path!(), "::", stringify!($test_name)));
161+
config.test_name = ::core::option::Option::Some(
162+
::core::concat!(::core::module_path!(), "::", ::core::stringify!($test_name)));
163163
$crate::proptest_helper!(@_BODY config ($($parm in $strategy),+) [] $body);
164164
}
165165
)*
@@ -173,8 +173,8 @@ macro_rules! proptest {
173173
$(#[$meta])*
174174
fn $test_name() {
175175
let mut config = $crate::test_runner::contextualize_config($config.clone());
176-
config.test_name = Some(
177-
concat!(module_path!(), "::", stringify!($test_name)));
176+
config.test_name = ::core::option::Option::Some(
177+
::core::concat!(::core::module_path!(), "::", ::core::stringify!($test_name)));
178178
$crate::proptest_helper!(@_BODY2 config ($($arg)+) [] $body);
179179
}
180180
)*
@@ -260,15 +260,16 @@ macro_rules! proptest {
260260
#[macro_export]
261261
macro_rules! prop_assume {
262262
($expr:expr) => {
263-
$crate::prop_assume!($expr, "{}", stringify!($expr))
263+
$crate::prop_assume!($expr, "{}", ::core::stringify!($expr))
264264
};
265265

266266
($expr:expr, $fmt:tt $(, $fmt_arg:expr),* $(,)?) => {
267267
if !$expr {
268+
extern crate alloc;
268269
return ::core::result::Result::Err(
269270
$crate::test_runner::TestCaseError::reject(
270-
format!(concat!("{}:{}:{}: ", $fmt),
271-
file!(), line!(), column!()
271+
alloc::format!(::core::concat!("{}:{}:{}: ", $fmt),
272+
::core::file!(), ::core::line!(), ::core::column!()
272273
$(, $fmt_arg)*)));
273274
}
274275
};
@@ -746,13 +747,14 @@ macro_rules! prop_compose {
746747
#[macro_export]
747748
macro_rules! prop_assert {
748749
($cond:expr $(,) ?) => {
749-
$crate::prop_assert!($cond, concat!("assertion failed: ", stringify!($cond)))
750+
$crate::prop_assert!($cond, ::core::concat!("assertion failed: ", ::core::stringify!($cond)))
750751
};
751752

752753
($cond:expr, $($fmt:tt)*) => {
753754
if !$cond {
754-
let message = format!($($fmt)*);
755-
let message = format!("{} at {}:{}", message, file!(), line!());
755+
extern crate alloc;
756+
let message = alloc::format!($($fmt)*);
757+
let message = alloc::format!("{} at {}:{}", message, ::core::file!(), ::core::line!());
756758
return ::core::result::Result::Err(
757759
$crate::test_runner::TestCaseError::fail(message));
758760
}
@@ -918,46 +920,46 @@ macro_rules! proptest_helper {
918920
(@_WRAPPAT ($a:pat, $($rest:pat),*)) => {
919921
($a, $crate::proptest_helper!(@_WRAPPAT ($($rest),*)))
920922
};
921-
(@_WRAPSTR ($item:pat)) => { stringify!($item) };
922-
(@_WRAPSTR ($a0:pat, $a1:pat)) => { (stringify!($a0), stringify!($a1)) };
923+
(@_WRAPSTR ($item:pat)) => { ::core::stringify!($item) };
924+
(@_WRAPSTR ($a0:pat, $a1:pat)) => { (::core::stringify!($a0), ::core::stringify!($a1)) };
923925
(@_WRAPSTR ($a0:pat, $a1:pat, $a2:pat)) => {
924-
(stringify!($a0), stringify!($a1), stringify!($a2))
926+
(::core::stringify!($a0), ::core::stringify!($a1), ::core::stringify!($a2))
925927
};
926928
(@_WRAPSTR ($a0:pat, $a1:pat, $a2:pat, $a3:pat)) => {
927-
(stringify!($a0), stringify!($a1), stringify!($a2), stringify!($a3))
929+
(::core::stringify!($a0), ::core::stringify!($a1), ::core::stringify!($a2), ::core::stringify!($a3))
928930
};
929931
(@_WRAPSTR ($a0:pat, $a1:pat, $a2:pat, $a3:pat, $a4:pat)) => {
930-
(stringify!($a0), stringify!($a1), stringify!($a2),
931-
stringify!($a3), stringify!($a4))
932+
(::core::stringify!($a0), ::core::stringify!($a1), ::core::stringify!($a2),
933+
::core::stringify!($a3), ::core::stringify!($a4))
932934
};
933935
(@_WRAPSTR ($a0:pat, $a1:pat, $a2:pat, $a3:pat, $a4:pat, $a5:pat)) => {
934-
(stringify!($a0), stringify!($a1), stringify!($a2), stringify!($a3),
935-
stringify!($a4), stringify!($a5))
936+
(::core::stringify!($a0), ::core::stringify!($a1), ::core::stringify!($a2), ::core::stringify!($a3),
937+
::core::stringify!($a4), ::core::stringify!($a5))
936938
};
937939
(@_WRAPSTR ($a0:pat, $a1:pat, $a2:pat, $a3:pat,
938940
$a4:pat, $a5:pat, $a6:pat)) => {
939-
(stringify!($a0), stringify!($a1), stringify!($a2), stringify!($a3),
940-
stringify!($a4), stringify!($a5), stringify!($a6))
941+
(::core::stringify!($a0), ::core::stringify!($a1), ::core::stringify!($a2), ::core::stringify!($a3),
942+
::core::stringify!($a4), ::core::stringify!($a5), ::core::stringify!($a6))
941943
};
942944
(@_WRAPSTR ($a0:pat, $a1:pat, $a2:pat, $a3:pat,
943945
$a4:pat, $a5:pat, $a6:pat, $a7:pat)) => {
944-
(stringify!($a0), stringify!($a1), stringify!($a2), stringify!($a3),
945-
stringify!($a4), stringify!($a5), stringify!($a6), stringify!($a7))
946+
(::core::stringify!($a0), ::core::stringify!($a1), ::core::stringify!($a2), ::core::stringify!($a3),
947+
::core::stringify!($a4), ::core::stringify!($a5), ::core::stringify!($a6), ::core::stringify!($a7))
946948
};
947949
(@_WRAPSTR ($a0:pat, $a1:pat, $a2:pat, $a3:pat, $a4:pat,
948950
$a5:pat, $a6:pat, $a7:pat, $a8:pat)) => {
949-
(stringify!($a0), stringify!($a1), stringify!($a2), stringify!($a3),
950-
stringify!($a4), stringify!($a5), stringify!($a6), stringify!($a7),
951-
stringify!($a8))
951+
(::core::stringify!($a0), ::core::stringify!($a1), ::core::stringify!($a2), ::core::stringify!($a3),
952+
::core::stringify!($a4), ::core::stringify!($a5), ::core::stringify!($a6), ::core::stringify!($a7),
953+
::core::stringify!($a8))
952954
};
953955
(@_WRAPSTR ($a0:pat, $a1:pat, $a2:pat, $a3:pat, $a4:pat,
954956
$a5:pat, $a6:pat, $a7:pat, $a8:pat, $a9:pat)) => {
955-
(stringify!($a0), stringify!($a1), stringify!($a2), stringify!($a3),
956-
stringify!($a4), stringify!($a5), stringify!($a6), stringify!($a7),
957-
stringify!($a8), stringify!($a9))
957+
(::core::stringify!($a0), ::core::stringify!($a1), ::core::stringify!($a2), ::core::stringify!($a3),
958+
::core::stringify!($a4), ::core::stringify!($a5), ::core::stringify!($a6), ::core::stringify!($a7),
959+
::core::stringify!($a8), ::core::stringify!($a9))
958960
};
959961
(@_WRAPSTR ($a:pat, $($rest:pat),*)) => {
960-
(stringify!($a), $crate::proptest_helper!(@_WRAPSTR ($($rest),*)))
962+
(::core::stringify!($a), $crate::proptest_helper!(@_WRAPSTR ($($rest),*)))
961963
};
962964
// build a property testing block that when executed, executes the full property test.
963965
(@_BODY $config:ident ($($parm:pat in $strategy:expr),+) [$($mod:tt)*] $body:expr) => {{
@@ -972,16 +974,16 @@ macro_rules! proptest_helper {
972974
_, $crate::proptest_helper!(@_WRAPPAT ($($parm),*)))|
973975
{
974976
let (): () = $body;
975-
Ok(())
977+
::core::result::Result::Ok(())
976978
})
977979
{
978-
Ok(()) => (),
979-
Err(e) => panic!("{}\n{}", e, runner),
980+
::core::result::Result::Ok(()) => (),
981+
::core::result::Result::Err(e) => ::core::panic!("{}\n{}", e, runner),
980982
}
981983
}};
982984
// build a property testing block that when executed, executes the full property test.
983985
(@_BODY2 $config:ident ($($arg:tt)+) [$($mod:tt)*] $body:expr) => {{
984-
$config.source_file = Some(file!());
986+
$config.source_file = Some(::core::file!());
985987
let mut runner = $crate::test_runner::TestRunner::new($config);
986988
let names = $crate::proptest_helper!(@_EXT _STR ($($arg)*));
987989
match runner.run(
@@ -992,11 +994,11 @@ macro_rules! proptest_helper {
992994
_, $crate::proptest_helper!(@_EXT _PAT ($($arg)*)))|
993995
{
994996
let (): () = $body;
995-
Ok(())
997+
::core::result::Result::Ok(())
996998
})
997999
{
998-
Ok(()) => (),
999-
Err(e) => panic!("{}\n{}", e, runner),
1000+
::core::result::Result::Ok(()) => (),
1001+
::core::result::Result::Err(e) => ::core::panic!("{}\n{}", e, runner),
10001002
}
10011003
}};
10021004

@@ -1005,10 +1007,10 @@ macro_rules! proptest_helper {
10051007
// These matchers define the actual logic:
10061008
(@_STRAT [$s:ty] [$p:pat]) => { $crate::arbitrary::any::<$s>() };
10071009
(@_PAT [$s:ty] [$p:pat]) => { $p };
1008-
(@_STR [$s:ty] [$p:pat]) => { stringify!($p) };
1010+
(@_STR [$s:ty] [$p:pat]) => { ::core::stringify!($p) };
10091011
(@_STRAT in [$s:expr] [$p:pat]) => { $s };
10101012
(@_PAT in [$s:expr] [$p:pat]) => { $p };
1011-
(@_STR in [$s:expr] [$p:pat]) => { stringify!($p) };
1013+
(@_STR in [$s:expr] [$p:pat]) => { ::core::stringify!($p) };
10121014

10131015
// These matchers rewrite into the above extractors.
10141016
// We have to do this because `:` can't FOLLOW(pat).

0 commit comments

Comments
 (0)