Skip to content

Commit 219c66c

Browse files
committed
rustc_parse: Make Parser::unexpected public and use it in built-in macros
1 parent 299136b commit 219c66c

File tree

3 files changed

+4
-5
lines changed

3 files changed

+4
-5
lines changed

compiler/rustc_builtin_macros/src/asm.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ fn parse_args<'a>(
164164
args.templates.push(template);
165165
continue;
166166
} else {
167-
return Err(p.expect_one_of(&[], &[]).unwrap_err());
167+
return p.unexpected();
168168
};
169169

170170
allow_templates = false;
@@ -348,7 +348,7 @@ fn parse_options<'a>(p: &mut Parser<'a>, args: &mut AsmArgs) -> Result<(), Diagn
348348
} else if p.eat_keyword(sym::att_syntax) {
349349
try_set_option(p, args, sym::att_syntax, ast::InlineAsmOptions::ATT_SYNTAX);
350350
} else {
351-
return Err(p.expect_one_of(&[], &[]).unwrap_err());
351+
return p.unexpected();
352352
}
353353

354354
// Allow trailing commas

compiler/rustc_builtin_macros/src/assert.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,7 @@ fn parse_assert<'a>(
120120
};
121121

122122
if parser.token != token::Eof {
123-
parser.expect_one_of(&[], &[])?;
124-
unreachable!();
123+
return parser.unexpected();
125124
}
126125

127126
Ok(Assert { cond_expr, custom_message })

compiler/rustc_parse/src/parser/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ impl<'a> Parser<'a> {
386386
next
387387
}
388388

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

0 commit comments

Comments
 (0)