defatalize compile_declarative_macro
This commit is contained in:
parent
df9cec2df4
commit
1bfa2483d5
@ -15,7 +15,7 @@ use rustc_ast_pretty::pprust;
|
||||
use rustc_attr::{self as attr, TransparencyError};
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use rustc_errors::{Applicability, DiagnosticBuilder, FatalError};
|
||||
use rustc_errors::{Applicability, DiagnosticBuilder};
|
||||
use rustc_feature::Features;
|
||||
use rustc_parse::parser::Parser;
|
||||
use rustc_session::parse::ParseSess;
|
||||
@ -180,6 +180,19 @@ impl TTMacroExpander for MacroRulesMacroExpander {
|
||||
}
|
||||
}
|
||||
|
||||
struct MacroRulesDummyExpander;
|
||||
|
||||
impl TTMacroExpander for MacroRulesDummyExpander {
|
||||
fn expand<'cx>(
|
||||
&self,
|
||||
_: &'cx mut ExtCtxt<'_>,
|
||||
sp: Span,
|
||||
_: TokenStream,
|
||||
) -> Box<dyn MacResult + 'cx> {
|
||||
DummyResult::any(sp)
|
||||
}
|
||||
}
|
||||
|
||||
fn trace_macros_note(cx_expansions: &mut FxHashMap<Span, Vec<String>>, sp: Span, message: String) {
|
||||
let sp = sp.macro_backtrace().last().map(|trace| trace.call_site).unwrap_or(sp);
|
||||
cx_expansions.entry(sp).or_default().push(message);
|
||||
@ -362,6 +375,18 @@ pub fn compile_declarative_macro(
|
||||
def: &ast::Item,
|
||||
edition: Edition,
|
||||
) -> SyntaxExtension {
|
||||
let mk_syn_ext = |expander| {
|
||||
SyntaxExtension::new(
|
||||
sess,
|
||||
SyntaxExtensionKind::LegacyBang(expander),
|
||||
def.span,
|
||||
Vec::new(),
|
||||
edition,
|
||||
def.ident.name,
|
||||
&def.attrs,
|
||||
)
|
||||
};
|
||||
|
||||
let diag = &sess.span_diagnostic;
|
||||
let lhs_nm = ast::Ident::new(sym::lhs, def.span);
|
||||
let rhs_nm = ast::Ident::new(sym::rhs, def.span);
|
||||
@ -416,13 +441,12 @@ pub fn compile_declarative_macro(
|
||||
Failure(token, msg) => {
|
||||
let s = parse_failure_msg(&token);
|
||||
let sp = token.span.substitute_dummy(def.span);
|
||||
let mut err = sess.span_diagnostic.struct_span_fatal(sp, &s);
|
||||
err.span_label(sp, msg);
|
||||
err.emit();
|
||||
FatalError.raise();
|
||||
sess.span_diagnostic.struct_span_err(sp, &s).span_label(sp, msg).emit();
|
||||
return mk_syn_ext(Box::new(MacroRulesDummyExpander));
|
||||
}
|
||||
Error(sp, s) => {
|
||||
sess.span_diagnostic.span_fatal(sp.substitute_dummy(def.span), &s).raise();
|
||||
Error(sp, msg) => {
|
||||
sess.span_diagnostic.struct_span_err(sp.substitute_dummy(def.span), &msg).emit();
|
||||
return mk_syn_ext(Box::new(MacroRulesDummyExpander));
|
||||
}
|
||||
};
|
||||
|
||||
@ -494,15 +518,7 @@ pub fn compile_declarative_macro(
|
||||
valid,
|
||||
});
|
||||
|
||||
SyntaxExtension::new(
|
||||
sess,
|
||||
SyntaxExtensionKind::LegacyBang(expander),
|
||||
def.span,
|
||||
Vec::new(),
|
||||
edition,
|
||||
def.ident.name,
|
||||
&def.attrs,
|
||||
)
|
||||
mk_syn_ext(expander)
|
||||
}
|
||||
|
||||
fn check_lhs_nt_follows(
|
||||
|
@ -0,0 +1,8 @@
|
||||
fn main() {}
|
||||
|
||||
macro_rules! ambiguity {
|
||||
($($i:ident)* $j:ident) => {};
|
||||
}
|
||||
|
||||
ambiguity!(error); //~ ERROR local ambiguity
|
||||
ambiguity!(error); //~ ERROR local ambiguity
|
@ -0,0 +1,14 @@
|
||||
error: local ambiguity: multiple parsing options: built-in NTs ident ('i') or ident ('j').
|
||||
--> $DIR/local-ambiguity-multiple-parsing-options.rs:7:12
|
||||
|
|
||||
LL | ambiguity!(error);
|
||||
| ^^^^^
|
||||
|
||||
error: local ambiguity: multiple parsing options: built-in NTs ident ('i') or ident ('j').
|
||||
--> $DIR/local-ambiguity-multiple-parsing-options.rs:8:12
|
||||
|
|
||||
LL | ambiguity!(error);
|
||||
| ^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
Loading…
x
Reference in New Issue
Block a user