use rustc_session::parse::ParseSess;
use rustc_span::symbol::{kw, sym, Ident, MacroRulesNormalizedIdent, Symbol};
-use rustc_errors::{FatalError, PResult};
+use rustc_errors::PResult;
use rustc_span::Span;
use smallvec::{smallvec, SmallVec};
Failure(Token, &'static str),
/// Fatal error (malformed macro?). Abort compilation.
Error(rustc_span::Span, String),
+ ErrorReported,
}
/// A `ParseResult` where the `Success` variant contains a mapping of
Success(_) => {}
Failure(token, msg) => return Failure(token, msg),
Error(sp, msg) => return Error(sp, msg),
+ ErrorReported => return ErrorReported,
}
// inner parse loop handled all cur_items, so it's empty
let mut item = bb_items.pop().unwrap();
if let TokenTree::MetaVarDecl(span, _, ident) = item.top_elts.get_tt(item.idx) {
let match_cur = item.match_cur;
- item.push_match(
- match_cur,
- MatchedNonterminal(Lrc::new(parse_nt(parser.to_mut(), span, ident.name))),
- );
+ let nt = match parse_nt(parser.to_mut(), span, ident.name) {
+ Err(()) => return ErrorReported,
+ Ok(nt) => nt,
+ };
+ item.push_match(match_cur, MatchedNonterminal(Lrc::new(nt)));
item.idx += 1;
item.match_cur += 1;
} else {
/// # Returns
///
/// The parsed non-terminal.
-fn parse_nt(p: &mut Parser<'_>, sp: Span, name: Symbol) -> Nonterminal {
+fn parse_nt(p: &mut Parser<'_>, sp: Span, name: Symbol) -> Result<Nonterminal, ()> {
// FIXME(Centril): Consider moving this to `parser.rs` to make
// the visibilities of the methods used below `pub(super)` at most.
-
if name == sym::tt {
- return token::NtTT(p.parse_token_tree());
- }
- match parse_nt_inner(p, sp, name) {
- Ok(nt) => nt,
- Err(mut err) => {
- err.emit();
- FatalError.raise();
- }
+ return Ok(token::NtTT(p.parse_token_tree()));
}
+ parse_nt_inner(p, sp, name).map_err(|mut err| {
+ err.span_label(sp, format!("while parsing argument for this `{}` macro fragment", name))
+ .emit()
+ })
}
fn parse_nt_inner<'a>(p: &mut Parser<'a>, sp: Span, name: Symbol) -> PResult<'a, Nonterminal> {
use crate::mbe;
use crate::mbe::macro_check;
use crate::mbe::macro_parser::parse_tt;
-use crate::mbe::macro_parser::{Error, Failure, Success};
+use crate::mbe::macro_parser::{Error, ErrorReported, Failure, Success};
use crate::mbe::macro_parser::{MatchedNonterminal, MatchedSeq};
use crate::mbe::transcribe::transcribe;
cx.struct_span_err(span, &msg).emit();
return DummyResult::any(span);
}
+ ErrorReported => return DummyResult::any(sp),
}
// The matcher was not `Success(..)`ful.
sess.span_diagnostic.struct_span_err(sp.substitute_dummy(def.span), &msg).emit();
return mk_syn_ext(Box::new(MacroRulesDummyExpander));
}
+ ErrorReported => {
+ return mk_syn_ext(Box::new(MacroRulesDummyExpander));
+ }
};
let mut valid = true;
--- /dev/null
+error: expected expression, found `@`
+ --> $DIR/nt-parsing-has-recovery.rs:5:10
+ |
+LL | ($e:expr) => {}
+ | ------- while parsing argument for this `expr` macro fragment
+...
+LL | foo!(1 + @);
+ | ^ expected expression
+
+error: expected expression, found `@`
+ --> $DIR/nt-parsing-has-recovery.rs:6:10
+ |
+LL | ($e:expr) => {}
+ | ------- while parsing argument for this `expr` macro fragment
+...
+LL | foo!(1 + @);
+ | ^ expected expression
+
+error[E0308]: mismatched types
+ --> $DIR/nt-parsing-has-recovery.rs:9:33
+ |
+LL | let _recovery_witness: () = 0;
+ | -- ^ expected `()`, found integer
+ | |
+ | expected due to this
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0308`.