From b81905eedbf56e026e8144a32056fd5dd0265d3b Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Tue, 1 Jul 2014 22:11:47 -0700 Subject: [PATCH] Fix ICE with nested macro_rules!-style macros Fixes #10536. --- src/libsyntax/parse/parser.rs | 4 ++-- src/test/compile-fail/issue-10536.rs | 34 ++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 src/test/compile-fail/issue-10536.rs diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 2aa2da3ba4b..f3789e25bc8 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -3248,7 +3248,7 @@ fn check_expected_item(p: &mut Parser, found_attrs: bool) { None => { // we only expect an ident if we didn't parse one // above. - let ident_str = if id == token::special_idents::invalid { + let ident_str = if id.name == token::special_idents::invalid.name { "identifier, " } else { "" @@ -3268,7 +3268,7 @@ fn check_expected_item(p: &mut Parser, found_attrs: bool) { ); let hi = self.span.hi; - if id == token::special_idents::invalid { + if id.name == token::special_idents::invalid.name { return box(GC) spanned(lo, hi, StmtMac( spanned(lo, hi, MacInvocTT(pth, tts, EMPTY_CTXT)), false)); } else { diff --git a/src/test/compile-fail/issue-10536.rs b/src/test/compile-fail/issue-10536.rs new file mode 100644 index 00000000000..36afc729de9 --- /dev/null +++ b/src/test/compile-fail/issue-10536.rs @@ -0,0 +1,34 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// We only want to assert that this doesn't ICE, we don't particularly care +// about whether it nor it fails to compile. + +// error-pattern: + +#![feature(macro_rules)] + +macro_rules! foo{ + () => {{ + macro_rules! bar{() => (())} + 1 + }} +} + +pub fn main() { + foo!(); + + assert!({one! two()}); + + // regardless of whether nested macro_rules works, the following should at + // least throw a conventional error. + assert!({one! two}); +} + -- 2.44.0