extract can_begin_bound

This commit is contained in:
Mazdak Farrokhzad 2019-12-08 10:04:31 +01:00
parent e61cb44f2f
commit fd89104966

View File

@ -367,19 +367,7 @@ impl<'a> Parser<'a> {
let mut negative_bounds = Vec::new();
let mut last_plus_span = None;
let mut was_negative = false;
loop {
// This needs to be synchronized with `TokenKind::can_begin_bound`.
let is_bound_start = self.check_path()
|| self.check_lifetime()
|| self.check(&token::Not) // Used for error reporting only.
|| self.check(&token::Question)
|| self.check_keyword(kw::For)
|| self.check(&token::OpenDelim(token::Paren));
if !is_bound_start {
break;
}
while self.can_begin_bound() {
let lo = self.token.span;
let has_parens = self.eat(&token::OpenDelim(token::Paren));
let inner_lo = self.token.span;
@ -456,6 +444,17 @@ impl<'a> Parser<'a> {
return Ok(bounds);
}
/// Can the current token begin a bound?
fn can_begin_bound(&mut self) -> bool {
// This needs to be synchronized with `TokenKind::can_begin_bound`.
self.check_path()
|| self.check_lifetime()
|| self.check(&token::Not) // Used for error reporting only.
|| self.check(&token::Question)
|| self.check_keyword(kw::For)
|| self.check(&token::OpenDelim(token::Paren))
}
fn error_opt_out_lifetime(&self, question: Option<Span>) {
if let Some(span) = question {
self.struct_span_err(span, "`?` may only modify trait bounds, not lifetime bounds")