Add regression tests for keywords wrongly considered as macros

This commit is contained in:
Guillaume Gomez 2025-11-07 16:41:36 +01:00
parent d1dda8d25e
commit 2c4a593b5c
2 changed files with 43 additions and 0 deletions

View file

@ -0,0 +1,13 @@
// This code crashed because a `if` followed by a `!` was considered a macro,
// creating an invalid class stack.
// Regression test for <https://github.com/rust-lang/rust/issues/148617>.
//@ compile-flags: -Zunstable-options --generate-macro-expansion
enum Enum {
Variant,
}
pub fn repro() {
if !matches!(Enum::Variant, Enum::Variant) {}
}

View file

@ -0,0 +1,30 @@
// This test ensures that keywords which can be followed by values (and therefore `!`)
// are not considered as macros.
// This is a regression test for <https://github.com/rust-lang/rust/issues/148617>.
#![crate_name = "foo"]
#![feature(negative_impls)]
//@ has 'src/foo/keyword-macros.rs.html'
//@ has - '//*[@class="rust"]//*[@class="number"]' '2'
//@ has - '//*[@class="rust"]//*[@class="number"]' '0'
//@ has - '//*[@class="rust"]//*[@class="number"]' '1'
const ARR: [u8; 2] = [!0,! 1];
trait X {}
//@ has - '//*[@class="rust"]//*[@class="kw"]' 'impl'
impl !X for i32 {}
fn a() {
//@ has - '//*[@class="rust"]//*[@class="kw"]' 'if'
if! true{}
//@ has - '//*[@class="rust"]//*[@class="kw"]' 'match'
match !true { _ => {} }
//@ has - '//*[@class="rust"]//*[@class="kw"]' 'while'
let _ = while !true {
//@ has - '//*[@class="rust"]//*[@class="kw"]' 'break'
break !true;
};
}