Skip to content

Commit ca79f82

Browse files
committed
Add test for Rust hygiene bug.
1 parent 91047ba commit ca79f82

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

tests/check.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,20 @@ fn non_debug_refs() {
104104
assert!(let I(10) = & &I(10));
105105
}
106106

107+
#[test]
108+
fn test_hygiene_bug() {
109+
// Test to see if we work around a hygiene bug in the Rust compiler.
110+
// See https://github.com/rust-lang/rust/issues/74036
111+
// and https://github.com/rust-lang/rust/issues/67062
112+
macro_rules! assert_square {
113+
($val:expr, $expected:expr) => { assert!($val * $val == $expected) }
114+
};
115+
116+
// If the hygiene bug is not fixed, this evaluates as 2 + 2 * 2 + 2 instead of (2 + 2) * (2 + ).
117+
// So it will fail with assert!(8 == 16).
118+
assert_square!(2 + 2, 16);
119+
}
120+
107121
#[test]
108122
fn no_copy() {
109123
let a = String::new();

0 commit comments

Comments
 (0)