Skip to content

Commit

Permalink
parser: {check,expect}_lifetime into ty.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
Centril committed Aug 11, 2019
1 parent 385d07f commit bcfcbfc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
18 changes: 1 addition & 17 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mod stmt;
mod generics;

use crate::ast::{self, AttrStyle, Attribute, Arg, BindingMode, StrStyle, SelfKind};
use crate::ast::{FnDecl, Ident, IsAsync, Lifetime, MacDelimiter, Mutability, TyKind};
use crate::ast::{FnDecl, Ident, IsAsync, MacDelimiter, Mutability, TyKind};
use crate::ast::{Visibility, VisibilityKind, Unsafety, CrateSugar};
use crate::ext::hygiene::SyntaxContext;
use crate::source_map::{self, respan};
Expand Down Expand Up @@ -1046,22 +1046,6 @@ impl<'a> Parser<'a> {
Ok(Arg { attrs: attrs.into(), id: ast::DUMMY_NODE_ID, pat, span, ty })
}

crate fn check_lifetime(&mut self) -> bool {
self.expected_tokens.push(TokenType::Lifetime);
self.token.is_lifetime()
}

/// Parses a single lifetime `'a` or panics.
crate fn expect_lifetime(&mut self) -> Lifetime {
if let Some(ident) = self.token.lifetime() {
let span = self.token.span;
self.bump();
Lifetime { ident: Ident::new(ident.name, span), id: ast::DUMMY_NODE_ID }
} else {
self.span_bug(self.token.span, "not a lifetime")
}
}

/// Parses mutability (`mut` or nothing).
fn parse_mutability(&mut self) -> Mutability {
if self.eat_keyword(kw::Mut) {
Expand Down
20 changes: 18 additions & 2 deletions src/libsyntax/parse/parser/ty.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use super::{Parser, PResult, PathStyle, PrevTokenKind};
use super::{Parser, PResult, PathStyle, PrevTokenKind, TokenType};

use crate::{maybe_whole, maybe_recover_from_interpolated_ty_qpath};
use crate::ptr::P;
use crate::ast::{self, Ty, TyKind, MutTy, BareFnTy, FunctionRetTy, GenericParam};
use crate::ast::{self, Ty, TyKind, MutTy, BareFnTy, FunctionRetTy, GenericParam, Lifetime, Ident};
use crate::ast::{TraitBoundModifier, TraitObjectSyntax, GenericBound, GenericBounds, PolyTraitRef};
use crate::ast::{Mutability, AnonConst, FnDecl, Mac_};
use crate::parse::token::{self, Token};
Expand Down Expand Up @@ -442,4 +442,20 @@ impl<'a> Parser<'a> {
Ok(Vec::new())
}
}

crate fn check_lifetime(&mut self) -> bool {
self.expected_tokens.push(TokenType::Lifetime);
self.token.is_lifetime()
}

/// Parses a single lifetime `'a` or panics.
crate fn expect_lifetime(&mut self) -> Lifetime {
if let Some(ident) = self.token.lifetime() {
let span = self.token.span;
self.bump();
Lifetime { ident: Ident::new(ident.name, span), id: ast::DUMMY_NODE_ID }
} else {
self.span_bug(self.token.span, "not a lifetime")
}
}
}

0 comments on commit bcfcbfc

Please sign in to comment.