parse_ptr -> parse_ty_ptr & refactor

This commit is contained in:
Mazdak Farrokhzad 2019-12-08 07:58:45 +01:00
parent c67c30dba6
commit 3838b602f5

View File

@ -79,8 +79,7 @@ impl<'a> Parser<'a> {
// Never type `!` // Never type `!`
TyKind::Never TyKind::Never
} else if self.eat(&token::BinOp(token::Star)) { } else if self.eat(&token::BinOp(token::Star)) {
// Raw pointer self.parse_ty_ptr()?
TyKind::Ptr(self.parse_ptr()?)
} else if self.eat(&token::OpenDelim(token::Bracket)) { } else if self.eat(&token::OpenDelim(token::Bracket)) {
// Array or slice // Array or slice
let t = self.parse_ty()?; let t = self.parse_ty()?;
@ -251,7 +250,8 @@ impl<'a> Parser<'a> {
Ok(TyKind::TraitObject(bounds, TraitObjectSyntax::None)) Ok(TyKind::TraitObject(bounds, TraitObjectSyntax::None))
} }
fn parse_ptr(&mut self) -> PResult<'a, MutTy> { /// Parses a raw pointer type: `*[const | mut] $type`.
fn parse_ty_ptr(&mut self) -> PResult<'a, TyKind> {
let mutbl = self.parse_const_or_mut().unwrap_or_else(|| { let mutbl = self.parse_const_or_mut().unwrap_or_else(|| {
let span = self.prev_span; let span = self.prev_span;
let msg = "expected mut or const in raw pointer type"; let msg = "expected mut or const in raw pointer type";
@ -261,8 +261,8 @@ impl<'a> Parser<'a> {
.emit(); .emit();
Mutability::Immutable Mutability::Immutable
}); });
let t = self.parse_ty_no_plus()?; let ty = self.parse_ty_no_plus()?;
Ok(MutTy { ty: t, mutbl }) Ok(TyKind::Ptr(MutTy { ty, mutbl }))
} }
fn maybe_parse_fixed_length_of_vec(&mut self) -> PResult<'a, Option<P<ast::Expr>>> { fn maybe_parse_fixed_length_of_vec(&mut self) -> PResult<'a, Option<P<ast::Expr>>> {