提交 8b4bdc2f 编写于 作者: M Matt Peterson

refactor lifetime out of is_lifetime

上级 f5524258
......@@ -2036,19 +2036,12 @@ fn check_lifetime(&mut self) -> bool {
/// Parse single lifetime 'a or panic.
pub fn expect_lifetime(&mut self) -> Lifetime {
let lifetime = match self.token {
token::Lifetime(ident) =>
Lifetime { ident: ident, span: self.span, id: ast::DUMMY_NODE_ID },
token::Interpolated(ref nt) => match nt.0 {
token::NtLifetime(lifetime) =>
lifetime,
_ => self.span_bug(self.span, "not a lifetime")
}
_ => self.span_bug(self.span, "not a lifetime")
};
self.bump();
lifetime
if let Some(lifetime) = self.token.lifetime(self.span) {
self.bump();
lifetime
} else {
self.span_bug(self.span, "not a lifetime")
}
}
/// Parse mutability (`mut` or nothing).
......
......@@ -314,18 +314,26 @@ pub fn is_path(&self) -> bool {
false
}
/// Returns `true` if the token is a lifetime.
pub fn is_lifetime(&self) -> bool {
/// Returns a lifetime with the span and a dummy id if it is a lifetime,
/// or the original lifetime if it is an interpolated lifetime, ignoring
/// the span.
pub fn lifetime(&self, span: Span) -> Option<ast::Lifetime> {
match *self {
Lifetime(..) => true,
Lifetime(ident) =>
Some(ast::Lifetime { ident: ident, span: span, id: ast::DUMMY_NODE_ID }),
Interpolated(ref nt) => match nt.0 {
NtLifetime(..) => true,
_ => false,
NtLifetime(lifetime) => Some(lifetime),
_ => None,
},
_ => false,
_ => None,
}
}
/// Returns `true` if the token is a lifetime.
pub fn is_lifetime(&self) -> bool {
self.lifetime(syntax_pos::DUMMY_SP).is_some()
}
/// Returns `true` if the token is either the `mut` or `const` keyword.
pub fn is_mutability(&self) -> bool {
self.is_keyword(keywords::Mut) ||
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册