mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-05 11:33:04 +00:00
refactor lifetime out of is_lifetime
This commit is contained in:
parent
f55242583c
commit
8b4bdc2f3f
@ -2036,19 +2036,12 @@ impl<'a> Parser<'a> {
|
||||
|
||||
/// 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,16 +314,24 @@ impl Token {
|
||||
false
|
||||
}
|
||||
|
||||
/// 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(ident) =>
|
||||
Some(ast::Lifetime { ident: ident, span: span, id: ast::DUMMY_NODE_ID }),
|
||||
Interpolated(ref nt) => match nt.0 {
|
||||
NtLifetime(lifetime) => Some(lifetime),
|
||||
_ => None,
|
||||
},
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns `true` if the token is a lifetime.
|
||||
pub fn is_lifetime(&self) -> bool {
|
||||
match *self {
|
||||
Lifetime(..) => true,
|
||||
Interpolated(ref nt) => match nt.0 {
|
||||
NtLifetime(..) => true,
|
||||
_ => false,
|
||||
},
|
||||
_ => false,
|
||||
}
|
||||
self.lifetime(syntax_pos::DUMMY_SP).is_some()
|
||||
}
|
||||
|
||||
/// Returns `true` if the token is either the `mut` or `const` keyword.
|
||||
|
Loading…
Reference in New Issue
Block a user