Skip to content

Commit

Permalink
rustc_parse: Make Parser::unexpected public and use it in built-in …
Browse files Browse the repository at this point in the history
…macros
  • Loading branch information
petrochenkov committed Oct 5, 2020
1 parent 299136b commit 219c66c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_builtin_macros/src/asm.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_builtin_macros/src/assert.rs
Expand Up @@ -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 })
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/parser/mod.rs
Expand Up @@ -386,7 +386,7 @@ impl<'a> Parser<'a> {
next
}

crate fn unexpected<T>(&mut self) -> PResult<'a, T> {
pub fn unexpected<T>(&mut self) -> PResult<'a, T> {
match self.expect_one_of(&[], &[]) {
Err(e) => Err(e),
// We can get `Ok(true)` from `recover_closing_delimiter`
Expand Down

0 comments on commit 219c66c

Please sign in to comment.