Skip to content

Commit 92c4c07

Browse files
author
blake2-ppc
committed
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`
1 parent 150b4ff commit 92c4c07

File tree

1 file changed

+15
-21
lines changed

1 file changed

+15
-21
lines changed

src/libsyntax/parse/parser.rs

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ use parse::{new_sub_parser_from_file, ParseSess};
8080
use opt_vec;
8181
use opt_vec::OptVec;
8282

83-
use std::either::Either;
84-
use std::either;
8583
use std::hashmap::HashSet;
8684
use std::util;
8785
use std::vec;
@@ -94,7 +92,6 @@ enum restriction {
9492
RESTRICT_NO_BAR_OR_DOUBLEBAR_OP,
9593
}
9694

97-
type arg_or_capture_item = Either<arg, ()>;
9895
type item_info = (Ident, item_, Option<~[Attribute]>);
9996

10097
/// How to parse a path. There are four different kinds of paths, all of which
@@ -936,7 +933,7 @@ impl Parser {
936933
let (explicit_self, d) = do self.parse_fn_decl_with_self() |p| {
937934
// This is somewhat dubious; We don't want to allow argument
938935
// names to be left off if there is a definition...
939-
either::Left(p.parse_arg_general(false))
936+
p.parse_arg_general(false)
940937
};
941938

942939
let hi = p.last_span.hi;
@@ -1290,12 +1287,12 @@ impl Parser {
12901287
}
12911288

12921289
// parse a single function argument
1293-
pub fn parse_arg(&self) -> arg_or_capture_item {
1294-
either::Left(self.parse_arg_general(true))
1290+
pub fn parse_arg(&self) -> arg {
1291+
self.parse_arg_general(true)
12951292
}
12961293

12971294
// parse an argument in a lambda header e.g. |arg, arg|
1298-
pub fn parse_fn_block_arg(&self) -> arg_or_capture_item {
1295+
pub fn parse_fn_block_arg(&self) -> arg {
12991296
self.parse_arg_mode();
13001297
let is_mutbl = self.eat_keyword(keywords::Mut);
13011298
let pat = self.parse_pat();
@@ -1308,12 +1305,12 @@ impl Parser {
13081305
span: mk_sp(self.span.lo, self.span.hi),
13091306
}
13101307
};
1311-
either::Left(ast::arg {
1308+
ast::arg {
13121309
is_mutbl: is_mutbl,
13131310
ty: t,
13141311
pat: pat,
13151312
id: ast::DUMMY_NODE_ID
1316-
})
1313+
}
13171314
}
13181315

13191316
pub fn maybe_parse_fixed_vstore(&self) -> Option<@ast::Expr> {
@@ -3500,19 +3497,17 @@ impl Parser {
35003497

35013498
// parse the argument list and result type of a function declaration
35023499
pub fn parse_fn_decl(&self) -> fn_decl {
3503-
let args_or_capture_items: ~[arg_or_capture_item] =
3500+
let args: ~[arg] =
35043501
self.parse_unspanned_seq(
35053502
&token::LPAREN,
35063503
&token::RPAREN,
35073504
seq_sep_trailing_disallowed(token::COMMA),
35083505
|p| p.parse_arg()
35093506
);
35103507

3511-
let inputs = either::lefts(args_or_capture_items.move_iter()).collect();
3512-
35133508
let (ret_style, ret_ty) = self.parse_ret_ty();
35143509
ast::fn_decl {
3515-
inputs: inputs,
3510+
inputs: args,
35163511
output: ret_ty,
35173512
cf: ret_style,
35183513
}
@@ -3542,7 +3537,7 @@ impl Parser {
35423537
fn parse_fn_decl_with_self(
35433538
&self,
35443539
parse_arg_fn:
3545-
&fn(&Parser) -> arg_or_capture_item
3540+
&fn(&Parser) -> arg
35463541
) -> (explicit_self, fn_decl) {
35473542
fn maybe_parse_explicit_self(
35483543
cnstr: &fn(v: Mutability) -> ast::explicit_self_,
@@ -3650,20 +3645,20 @@ impl Parser {
36503645
};
36513646

36523647
// If we parsed a self type, expect a comma before the argument list.
3653-
let args_or_capture_items;
3648+
let fn_inputs;
36543649
if explicit_self != sty_static {
36553650
match *self.token {
36563651
token::COMMA => {
36573652
self.bump();
36583653
let sep = seq_sep_trailing_disallowed(token::COMMA);
3659-
args_or_capture_items = self.parse_seq_to_before_end(
3654+
fn_inputs = self.parse_seq_to_before_end(
36603655
&token::RPAREN,
36613656
sep,
36623657
parse_arg_fn
36633658
);
36643659
}
36653660
token::RPAREN => {
3666-
args_or_capture_items = ~[];
3661+
fn_inputs = ~[];
36673662
}
36683663
_ => {
36693664
self.fatal(
@@ -3676,7 +3671,7 @@ impl Parser {
36763671
}
36773672
} else {
36783673
let sep = seq_sep_trailing_disallowed(token::COMMA);
3679-
args_or_capture_items = self.parse_seq_to_before_end(
3674+
fn_inputs = self.parse_seq_to_before_end(
36803675
&token::RPAREN,
36813676
sep,
36823677
parse_arg_fn
@@ -3687,11 +3682,10 @@ impl Parser {
36873682

36883683
let hi = self.span.hi;
36893684

3690-
let inputs = either::lefts(args_or_capture_items.move_iter()).collect();
36913685
let (ret_style, ret_ty) = self.parse_ret_ty();
36923686

36933687
let fn_decl = ast::fn_decl {
3694-
inputs: inputs,
3688+
inputs: fn_inputs,
36953689
output: ret_ty,
36963690
cf: ret_style
36973691
};
@@ -3720,7 +3714,7 @@ impl Parser {
37203714
};
37213715

37223716
ast::fn_decl {
3723-
inputs: either::lefts(inputs_captures.move_iter()).collect(),
3717+
inputs: inputs_captures,
37243718
output: output,
37253719
cf: return_val,
37263720
}

0 commit comments

Comments
 (0)