rustc_parse: Make `Parser::unexpected` public and use it in built-in macros

This commit is contained in:
Vadim Petrochenkov 2020-10-06 00:21:03 +03:00
parent 299136b9c7
commit 219c66c55c
3 changed files with 4 additions and 5 deletions

View File

@ -164,7 +164,7 @@ fn parse_args<'a>(
args.templates.push(template); args.templates.push(template);
continue; continue;
} else { } else {
return Err(p.expect_one_of(&[], &[]).unwrap_err()); return p.unexpected();
}; };
allow_templates = false; allow_templates = false;
@ -348,7 +348,7 @@ fn parse_options<'a>(p: &mut Parser<'a>, args: &mut AsmArgs) -> Result<(), Diagn
} else if p.eat_keyword(sym::att_syntax) { } else if p.eat_keyword(sym::att_syntax) {
try_set_option(p, args, sym::att_syntax, ast::InlineAsmOptions::ATT_SYNTAX); try_set_option(p, args, sym::att_syntax, ast::InlineAsmOptions::ATT_SYNTAX);
} else { } else {
return Err(p.expect_one_of(&[], &[]).unwrap_err()); return p.unexpected();
} }
// Allow trailing commas // Allow trailing commas

View File

@ -120,8 +120,7 @@ fn parse_assert<'a>(
}; };
if parser.token != token::Eof { if parser.token != token::Eof {
parser.expect_one_of(&[], &[])?; return parser.unexpected();
unreachable!();
} }
Ok(Assert { cond_expr, custom_message }) Ok(Assert { cond_expr, custom_message })

View File

@ -386,7 +386,7 @@ impl<'a> Parser<'a> {
next next
} }
crate fn unexpected<T>(&mut self) -> PResult<'a, T> { pub fn unexpected<T>(&mut self) -> PResult<'a, T> {
match self.expect_one_of(&[], &[]) { match self.expect_one_of(&[], &[]) {
Err(e) => Err(e), Err(e) => Err(e),
// We can get `Ok(true)` from `recover_closing_delimiter` // We can get `Ok(true)` from `recover_closing_delimiter`