Skip to content

Commit 2c4a593

Browse files
Add regression tests for keywords wrongly considered as macros
1 parent d1dda8d commit 2c4a593

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-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: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
#![feature(negative_impls)]
7+
8+
//@ has 'src/foo/keyword-macros.rs.html'
9+
10+
//@ has - '//*[@class="rust"]//*[@class="number"]' '2'
11+
//@ has - '//*[@class="rust"]//*[@class="number"]' '0'
12+
//@ has - '//*[@class="rust"]//*[@class="number"]' '1'
13+
const ARR: [u8; 2] = [!0,! 1];
14+
15+
trait X {}
16+
17+
//@ has - '//*[@class="rust"]//*[@class="kw"]' 'impl'
18+
impl !X for i32 {}
19+
20+
fn a() {
21+
//@ has - '//*[@class="rust"]//*[@class="kw"]' 'if'
22+
if! true{}
23+
//@ has - '//*[@class="rust"]//*[@class="kw"]' 'match'
24+
match !true { _ => {} }
25+
//@ has - '//*[@class="rust"]//*[@class="kw"]' 'while'
26+
let _ = while !true {
27+
//@ has - '//*[@class="rust"]//*[@class="kw"]' 'break'
28+
break !true;
29+
};
30+
}

0 commit comments

Comments
 (0)