macros: fix an infinite loop ...

... introduced in fed5a41fb1, should fix #1102

Signed-off-by: Zixing Liu <liushuyu011@gmail.com>
This commit is contained in:
liushuyu 2022-04-11 15:20:41 -06:00
parent 68458036c8
commit 2fe4048f7f
No known key found for this signature in database
GPG Key ID: 23D1CE4534419437
2 changed files with 9 additions and 5 deletions

View File

@ -287,9 +287,12 @@ MacroBuiltin::concat (Location invoc_locus, AST::MacroInvocData &invoc)
}
else
{
rust_error_at (parser.peek_current_token ()->get_locus (),
auto current_token = parser.peek_current_token ();
rust_error_at (current_token->get_locus (),
"argument must be a constant literal");
has_error = true;
// Just crash if the current token can't be skipped
rust_assert (parser.skip_token (current_token->get_id ()));
}
parser.maybe_skip_token (COMMA);
}

View File

@ -3,13 +3,14 @@ macro_rules! concat {
}
fn main() {
// let not_literal = "identifier";
let not_literal = "identifier";
concat!();
// concat! (,); // { error "argument must be a constant literal" }
// concat!(not_literal); // { error "argument must be a constant literal" }
concat! (,); // { dg-error "argument must be a constant literal" }
concat!(not_literal); // { dg-error "argument must be a constant literal" }
concat!("message");
concat!("message",);
concat!("message", 1, true, false, 1.0, 10usize, 2000u64);
concat!("message", 1, true, false, 1.0, 10usize, 2000u64,);
// concat! ("m", not_literal); // { error "argument must be a constant literal" }
concat! ("m", not_literal); // { dg-error "argument must be a constant literal" }
concat!(not_literal invalid 'm' !!,); // { dg-error "argument must be a constant literal" }
}