Make generics always have a valid span

This commit is contained in:
Esteban Küber
2019-05-31 22:19:30 -07:00
parent 7840a0b753
commit 8e595f5610
5 changed files with 19 additions and 22 deletions

View File

@@ -5050,21 +5050,22 @@ impl<'a> Parser<'a> {
/// where typaramseq = ( typaram ) | ( typaram , typaramseq )
fn parse_generics(&mut self) -> PResult<'a, ast::Generics> {
let span_lo = self.span;
if self.eat_lt() {
let (params, span) = if self.eat_lt() {
let params = self.parse_generic_params()?;
self.expect_gt()?;
Ok(ast::Generics {
params,
where_clause: WhereClause {
id: ast::DUMMY_NODE_ID,
predicates: Vec::new(),
span: DUMMY_SP,
},
span: span_lo.to(self.prev_span),
})
(params, span_lo.to(self.prev_span))
} else {
Ok(ast::Generics::default())
}
(vec![], self.prev_span.between(self.span))
};
Ok(ast::Generics {
params,
where_clause: WhereClause {
id: ast::DUMMY_NODE_ID,
predicates: Vec::new(),
span: DUMMY_SP,
},
span,
})
}
/// Parses generic args (within a path segment) with recovery for extra leading angle brackets.