Skip to content

Commit 60c62dc

Browse files
authored
Merge pull request #406 from dtolnay/error
Parse rustc's representation of macro expansion error
2 parents 2e96778 + 14a481d commit 60c62dc

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/parse.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ fn word_break(input: Cursor) -> Result<Cursor, Reject> {
161161
}
162162
}
163163

164+
// Rustc's representation of a macro expansion error in expression position or
165+
// type position.
166+
const ERROR: &str = "(/*ERROR*/)";
167+
164168
pub(crate) fn token_stream(mut input: Cursor) -> Result<TokenStream, LexError> {
165169
let mut trees = TokenStreamBuilder::new();
166170
let mut stack = Vec::new();
@@ -192,7 +196,7 @@ pub(crate) fn token_stream(mut input: Cursor) -> Result<TokenStream, LexError> {
192196
};
193197

194198
if let Some(open_delimiter) = match first {
195-
b'(' => Some(Delimiter::Parenthesis),
199+
b'(' if !input.starts_with(ERROR) => Some(Delimiter::Parenthesis),
196200
b'[' => Some(Delimiter::Bracket),
197201
b'{' => Some(Delimiter::Brace),
198202
_ => None,
@@ -267,6 +271,10 @@ fn leaf_token(input: Cursor) -> PResult<TokenTree> {
267271
Ok((input, TokenTree::Punct(p)))
268272
} else if let Ok((input, i)) = ident(input) {
269273
Ok((input, TokenTree::Ident(i)))
274+
} else if input.starts_with(ERROR) {
275+
let rest = input.advance(ERROR.len());
276+
let repr = crate::Literal::_new_fallback(Literal::_new(ERROR.to_owned()));
277+
Ok((rest, TokenTree::Literal(repr)))
270278
} else {
271279
Err(Reject)
272280
}

0 commit comments

Comments
 (0)