Skip to content

Commit 3f877d5

Browse files
Add regression tests for keywords wrongly considered as macros
1 parent caff0ba commit 3f877d5

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// This code crashed because a `if` followed by a `!` was considered a macro,
2+
// creating an invalid class stack.
3+
// Regression test for <https://github.com/rust-lang/rust/issues/148617>.
4+
5+
//@ compile-flags: -Zunstable-options --generate-macro-expansion
6+
7+
enum Enum {
8+
Variant,
9+
}
10+
11+
pub fn repro() {
12+
if !matches!(Enum::Variant, Enum::Variant) {}
13+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// This test ensures that keywords which can be followed by values (and therefore `!`)
2+
// are not considered as macros.
3+
// This is a regression test for <https://github.com/rust-lang/rust/issues/148617>.
4+
5+
#![crate_name = "foo"]
6+
7+
//@ has 'src/foo/keyword-macros.rs.html'
8+
9+
//@ has - '//*[@class="rust"]//*[@class="number"]' '2'
10+
//@ has - '//*[@class="rust"]//*[@class="number"]' '0'
11+
//@ has - '//*[@class="rust"]//*[@class="number"]' '1'
12+
const ARR: [u8; 2] = [!0,! 1];
13+
14+
fn a() {
15+
//@ has - '//*[@class="rust"]//*[@class="kw"]' 'if'
16+
if! true{}
17+
//@ has - '//*[@class="rust"]//*[@class="kw"]' 'match'
18+
match !true { _ => {} }
19+
//@ has - '//*[@class="rust"]//*[@class="kw"]' 'while'
20+
let _ = while !true {
21+
//@ has - '//*[@class="rust"]//*[@class="kw"]' 'break'
22+
break !true;
23+
};
24+
}

0 commit comments

Comments
 (0)