Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retry failed macro matching for diagnostics #103898

Merged
merged 7 commits into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions compiler/rustc_expand/src/mbe/macro_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@

pub(crate) use NamedMatch::*;
pub(crate) use ParseResult::*;
use rustc_errors::ErrorGuaranteed;

use crate::mbe::{KleeneOp, TokenTree};

Expand Down Expand Up @@ -270,7 +271,7 @@ pub(crate) enum ParseResult<T> {
Failure(Token, &'static str),
/// Fatal error (malformed macro?). Abort compilation.
Error(rustc_span::Span, String),
ErrorReported,
ErrorReported(ErrorGuaranteed),
}

/// A `ParseResult` where the `Success` variant contains a mapping of
Expand Down Expand Up @@ -450,7 +451,7 @@ impl TtParser {
// Try zero matches of this sequence, by skipping over it.
self.cur_mps.push(MatcherPos {
idx: idx_first_after,
matches: mp.matches.clone(), // a cheap clone
matches: Lrc::clone(&mp.matches),
Noratrieb marked this conversation as resolved.
Show resolved Hide resolved
});
}

Expand All @@ -463,8 +464,8 @@ impl TtParser {
// sequence. If that's not possible, `ending_mp` will fail quietly when it is
// processed next time around the loop.
let ending_mp = MatcherPos {
idx: mp.idx + 1, // +1 skips the Kleene op
matches: mp.matches.clone(), // a cheap clone
idx: mp.idx + 1, // +1 skips the Kleene op
matches: Lrc::clone(&mp.matches),
};
self.cur_mps.push(ending_mp);

Expand All @@ -479,8 +480,8 @@ impl TtParser {
// separator yet. Try ending the sequence. If that's not possible, `ending_mp`
// will fail quietly when it is processed next time around the loop.
let ending_mp = MatcherPos {
idx: mp.idx + 2, // +2 skips the separator and the Kleene op
matches: mp.matches.clone(), // a cheap clone
idx: mp.idx + 2, // +2 skips the separator and the Kleene op
matches: Lrc::clone(&mp.matches),
};
self.cur_mps.push(ending_mp);

Expand Down Expand Up @@ -612,14 +613,14 @@ impl TtParser {
// edition-specific matching behavior for non-terminals.
let nt = match parser.to_mut().parse_nonterminal(kind) {
Err(mut err) => {
err.span_label(
let guarantee = err.span_label(
span,
format!(
"while parsing argument for this `{kind}` macro fragment"
),
)
.emit();
return ErrorReported;
return ErrorReported(guarantee);
}
Ok(nt) => nt,
};
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_expand/src/mbe/macro_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ fn expand_macro<'cx>(
cx.struct_span_err(span, &msg).emit();
return DummyResult::any(span);
}
ErrorReported => return DummyResult::any(sp),
ErrorReported(_) => return DummyResult::any(sp),
}

// The matcher was not `Success(..)`ful.
Expand Down Expand Up @@ -470,7 +470,7 @@ pub fn compile_declarative_macro(
.emit();
return dummy_syn_ext();
}
ErrorReported => {
ErrorReported(_) => {
return dummy_syn_ext();
}
};
Expand Down