diff --git a/src/librustc_parse/parser/ty.rs b/src/librustc_parse/parser/ty.rs index a4c1f530ef8..b9537100ce1 100644 --- a/src/librustc_parse/parser/ty.rs +++ b/src/librustc_parse/parser/ty.rs @@ -383,10 +383,7 @@ impl<'a> Parser<'a> { let is_negative = self.eat(&token::Not); let question = if self.eat(&token::Question) { Some(self.prev_span) } else { None }; if self.token.is_lifetime() { - if let Some(question_span) = question { - self.span_err(question_span, - "`?` may only modify trait bounds, not lifetime bounds"); - } + self.error_opt_out_lifetime(question); bounds.push(GenericBound::Outlives(self.expect_lifetime())); if has_parens { let inner_span = inner_lo.to(self.prev_span); @@ -473,6 +470,13 @@ impl<'a> Parser<'a> { return Ok(bounds); } + fn error_opt_out_lifetime(&self, question: Option) { + if let Some(span) = question { + self.struct_span_err(span, "`?` may only modify trait bounds, not lifetime bounds") + .emit(); + } + } + pub(super) fn parse_late_bound_lifetime_defs(&mut self) -> PResult<'a, Vec> { if self.eat_keyword(kw::For) { self.expect_lt()?;