提交 92c4c077 编写于 作者: B blake2-ppc

syntax: Remove use of Either in parse.rs

The arg or capture type alias was actually never used for the capture
case, so the code is simplified with `Either<arg, ()>` replaced by `arg`
上级 150b4ffc
......@@ -80,8 +80,6 @@
use opt_vec;
use opt_vec::OptVec;
use std::either::Either;
use std::either;
use std::hashmap::HashSet;
use std::util;
use std::vec;
......@@ -94,7 +92,6 @@ enum restriction {
RESTRICT_NO_BAR_OR_DOUBLEBAR_OP,
}
type arg_or_capture_item = Either<arg, ()>;
type item_info = (Ident, item_, Option<~[Attribute]>);
/// How to parse a path. There are four different kinds of paths, all of which
......@@ -936,7 +933,7 @@ pub fn parse_trait_methods(&self) -> ~[trait_method] {
let (explicit_self, d) = do self.parse_fn_decl_with_self() |p| {
// This is somewhat dubious; We don't want to allow argument
// names to be left off if there is a definition...
either::Left(p.parse_arg_general(false))
p.parse_arg_general(false)
};
let hi = p.last_span.hi;
......@@ -1290,12 +1287,12 @@ pub fn parse_arg_general(&self, require_name: bool) -> arg {
}
// parse a single function argument
pub fn parse_arg(&self) -> arg_or_capture_item {
either::Left(self.parse_arg_general(true))
pub fn parse_arg(&self) -> arg {
self.parse_arg_general(true)
}
// parse an argument in a lambda header e.g. |arg, arg|
pub fn parse_fn_block_arg(&self) -> arg_or_capture_item {
pub fn parse_fn_block_arg(&self) -> arg {
self.parse_arg_mode();
let is_mutbl = self.eat_keyword(keywords::Mut);
let pat = self.parse_pat();
......@@ -1308,12 +1305,12 @@ pub fn parse_fn_block_arg(&self) -> arg_or_capture_item {
span: mk_sp(self.span.lo, self.span.hi),
}
};
either::Left(ast::arg {
ast::arg {
is_mutbl: is_mutbl,
ty: t,
pat: pat,
id: ast::DUMMY_NODE_ID
})
}
}
pub fn maybe_parse_fixed_vstore(&self) -> Option<@ast::Expr> {
......@@ -3500,7 +3497,7 @@ fn parse_generic_values_after_lt(&self) -> (OptVec<ast::Lifetime>, ~[Ty]) {
// parse the argument list and result type of a function declaration
pub fn parse_fn_decl(&self) -> fn_decl {
let args_or_capture_items: ~[arg_or_capture_item] =
let args: ~[arg] =
self.parse_unspanned_seq(
&token::LPAREN,
&token::RPAREN,
......@@ -3508,11 +3505,9 @@ pub fn parse_fn_decl(&self) -> fn_decl {
|p| p.parse_arg()
);
let inputs = either::lefts(args_or_capture_items.move_iter()).collect();
let (ret_style, ret_ty) = self.parse_ret_ty();
ast::fn_decl {
inputs: inputs,
inputs: args,
output: ret_ty,
cf: ret_style,
}
......@@ -3542,7 +3537,7 @@ fn expect_self_ident(&self) {
fn parse_fn_decl_with_self(
&self,
parse_arg_fn:
&fn(&Parser) -> arg_or_capture_item
&fn(&Parser) -> arg
) -> (explicit_self, fn_decl) {
fn maybe_parse_explicit_self(
cnstr: &fn(v: Mutability) -> ast::explicit_self_,
......@@ -3650,20 +3645,20 @@ fn maybe_parse_borrowed_explicit_self(this: &Parser) -> ast::explicit_self_ {
};
// If we parsed a self type, expect a comma before the argument list.
let args_or_capture_items;
let fn_inputs;
if explicit_self != sty_static {
match *self.token {
token::COMMA => {
self.bump();
let sep = seq_sep_trailing_disallowed(token::COMMA);
args_or_capture_items = self.parse_seq_to_before_end(
fn_inputs = self.parse_seq_to_before_end(
&token::RPAREN,
sep,
parse_arg_fn
);
}
token::RPAREN => {
args_or_capture_items = ~[];
fn_inputs = ~[];
}
_ => {
self.fatal(
......@@ -3676,7 +3671,7 @@ fn maybe_parse_borrowed_explicit_self(this: &Parser) -> ast::explicit_self_ {
}
} else {
let sep = seq_sep_trailing_disallowed(token::COMMA);
args_or_capture_items = self.parse_seq_to_before_end(
fn_inputs = self.parse_seq_to_before_end(
&token::RPAREN,
sep,
parse_arg_fn
......@@ -3687,11 +3682,10 @@ fn maybe_parse_borrowed_explicit_self(this: &Parser) -> ast::explicit_self_ {
let hi = self.span.hi;
let inputs = either::lefts(args_or_capture_items.move_iter()).collect();
let (ret_style, ret_ty) = self.parse_ret_ty();
let fn_decl = ast::fn_decl {
inputs: inputs,
inputs: fn_inputs,
output: ret_ty,
cf: ret_style
};
......@@ -3720,7 +3714,7 @@ fn parse_fn_block_decl(&self) -> fn_decl {
};
ast::fn_decl {
inputs: either::lefts(inputs_captures.move_iter()).collect(),
inputs: inputs_captures,
output: output,
cf: return_val,
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册