Skip to content

Commit 56b54fb

Browse files
committed
extract recover_paren_lifetime
1 parent 8e8ac02 commit 56b54fb

File tree

1 file changed

+21
-15
lines changed
  • src/librustc_parse/parser

1 file changed

+21
-15
lines changed

src/librustc_parse/parser/ty.rs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -386,21 +386,7 @@ impl<'a> Parser<'a> {
386386
self.error_opt_out_lifetime(question);
387387
bounds.push(GenericBound::Outlives(self.expect_lifetime()));
388388
if has_parens {
389-
let inner_span = inner_lo.to(self.prev_span);
390-
self.expect(&token::CloseDelim(token::Paren))?;
391-
let mut err = self.struct_span_err(
392-
lo.to(self.prev_span),
393-
"parenthesized lifetime bounds are not supported"
394-
);
395-
if let Ok(snippet) = self.span_to_snippet(inner_span) {
396-
err.span_suggestion_short(
397-
lo.to(self.prev_span),
398-
"remove the parentheses",
399-
snippet.to_owned(),
400-
Applicability::MachineApplicable
401-
);
402-
}
403-
err.emit();
389+
self.recover_paren_lifetime(lo, inner_lo)?;
404390
}
405391
} else {
406392
let lifetime_defs = self.parse_late_bound_lifetime_defs()?;
@@ -477,6 +463,26 @@ impl<'a> Parser<'a> {
477463
}
478464
}
479465

466+
/// Recover on `('lifetime)` with `(` already eaten.
467+
fn recover_paren_lifetime(&mut self, lo: Span, inner_lo: Span) -> PResult<'a, ()> {
468+
let inner_span = inner_lo.to(self.prev_span);
469+
self.expect(&token::CloseDelim(token::Paren))?;
470+
let mut err = self.struct_span_err(
471+
lo.to(self.prev_span),
472+
"parenthesized lifetime bounds are not supported"
473+
);
474+
if let Ok(snippet) = self.span_to_snippet(inner_span) {
475+
err.span_suggestion_short(
476+
lo.to(self.prev_span),
477+
"remove the parentheses",
478+
snippet.to_owned(),
479+
Applicability::MachineApplicable
480+
);
481+
}
482+
err.emit();
483+
Ok(())
484+
}
485+
480486
pub(super) fn parse_late_bound_lifetime_defs(&mut self) -> PResult<'a, Vec<GenericParam>> {
481487
if self.eat_keyword(kw::For) {
482488
self.expect_lt()?;

0 commit comments

Comments
 (0)