From 219c66c55c86db51a1a278c2d3cb7f8a1f4426e9 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Tue, 6 Oct 2020 00:21:03 +0300 Subject: [PATCH] rustc_parse: Make `Parser::unexpected` public and use it in built-in macros --- compiler/rustc_builtin_macros/src/asm.rs | 4 ++-- compiler/rustc_builtin_macros/src/assert.rs | 3 +-- compiler/rustc_parse/src/parser/mod.rs | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_builtin_macros/src/asm.rs b/compiler/rustc_builtin_macros/src/asm.rs index 2cdfc3f6c9cc9..36cd6c281b42a 100644 --- a/compiler/rustc_builtin_macros/src/asm.rs +++ b/compiler/rustc_builtin_macros/src/asm.rs @@ -164,7 +164,7 @@ fn parse_args<'a>( args.templates.push(template); continue; } else { - return Err(p.expect_one_of(&[], &[]).unwrap_err()); + return p.unexpected(); }; 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) { try_set_option(p, args, sym::att_syntax, ast::InlineAsmOptions::ATT_SYNTAX); } else { - return Err(p.expect_one_of(&[], &[]).unwrap_err()); + return p.unexpected(); } // Allow trailing commas diff --git a/compiler/rustc_builtin_macros/src/assert.rs b/compiler/rustc_builtin_macros/src/assert.rs index 2518171554073..5bfd8a2bf561c 100644 --- a/compiler/rustc_builtin_macros/src/assert.rs +++ b/compiler/rustc_builtin_macros/src/assert.rs @@ -120,8 +120,7 @@ fn parse_assert<'a>( }; if parser.token != token::Eof { - parser.expect_one_of(&[], &[])?; - unreachable!(); + return parser.unexpected(); } Ok(Assert { cond_expr, custom_message }) diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index 7340c5744808c..070fc140ec479 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -386,7 +386,7 @@ impl<'a> Parser<'a> { next } - crate fn unexpected(&mut self) -> PResult<'a, T> { + pub fn unexpected(&mut self) -> PResult<'a, T> { match self.expect_one_of(&[], &[]) { Err(e) => Err(e), // We can get `Ok(true)` from `recover_closing_delimiter`