Skip to content

Commit 08321f1

Browse files
committed
auto merge of #11149 : alexcrichton/rust/remove-either, r=brson
Had to change some stuff in typeck to bootstrap (getting methods in fmt off of Either), but other than that not so painful. Closes #9157
2 parents 11ce6b7 + 4bea679 commit 08321f1

18 files changed

+114
-341
lines changed

src/libextra/test.rs

+15-10
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,14 @@ pub enum TestResult {
337337
TrBench(BenchSamples),
338338
}
339339

340+
enum OutputLocation<T> {
341+
Pretty(term::Terminal<T>),
342+
Raw(T),
343+
}
344+
340345
struct ConsoleTestState<T> {
341346
log_out: Option<File>,
342-
out: Either<term::Terminal<T>, T>,
347+
out: OutputLocation<T>,
343348
use_color: bool,
344349
total: uint,
345350
passed: uint,
@@ -358,8 +363,8 @@ impl<T: Writer> ConsoleTestState<T> {
358363
None => None
359364
};
360365
let out = match term::Terminal::new(io::stdout()) {
361-
Err(_) => Right(io::stdout()),
362-
Ok(t) => Left(t)
366+
Err(_) => Raw(io::stdout()),
367+
Ok(t) => Pretty(t)
363368
};
364369
ConsoleTestState {
365370
out: out,
@@ -416,7 +421,7 @@ impl<T: Writer> ConsoleTestState<T> {
416421
word: &str,
417422
color: term::color::Color) {
418423
match self.out {
419-
Left(ref mut term) => {
424+
Pretty(ref mut term) => {
420425
if self.use_color {
421426
term.fg(color);
422427
}
@@ -425,14 +430,14 @@ impl<T: Writer> ConsoleTestState<T> {
425430
term.reset();
426431
}
427432
}
428-
Right(ref mut stdout) => stdout.write(word.as_bytes())
433+
Raw(ref mut stdout) => stdout.write(word.as_bytes())
429434
}
430435
}
431436

432437
pub fn write_plain(&mut self, s: &str) {
433438
match self.out {
434-
Left(ref mut term) => term.write(s.as_bytes()),
435-
Right(ref mut stdout) => stdout.write(s.as_bytes())
439+
Pretty(ref mut term) => term.write(s.as_bytes()),
440+
Raw(ref mut stdout) => stdout.write(s.as_bytes())
436441
}
437442
}
438443

@@ -683,7 +688,7 @@ fn should_sort_failures_before_printing_them() {
683688

684689
let mut st = ConsoleTestState {
685690
log_out: None,
686-
out: Right(MemWriter::new()),
691+
out: Raw(MemWriter::new()),
687692
use_color: false,
688693
total: 0u,
689694
passed: 0u,
@@ -697,8 +702,8 @@ fn should_sort_failures_before_printing_them() {
697702

698703
st.write_failures();
699704
let s = match st.out {
700-
Right(ref m) => str::from_utf8(*m.inner_ref()),
701-
Left(_) => unreachable!()
705+
Raw(ref m) => str::from_utf8(*m.inner_ref()),
706+
Pretty(_) => unreachable!()
702707
};
703708

704709
let apos = s.find_str("a").unwrap();

src/librustc/middle/typeck/check/mod.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -1705,9 +1705,12 @@ pub fn check_expr_with_unifier(fcx: @FnCtxt,
17051705
fn_inputs.map(|a| *a)
17061706
} else {
17071707
let msg = format!(
1708-
"this function takes at least {0, plural, =1{# parameter} \
1709-
other{# parameters}} but {1, plural, =1{# parameter was} \
1710-
other{# parameters were}} supplied", expected_arg_count, supplied_arg_count);
1708+
"this function takes at least {} parameter{} \
1709+
but {} parameter{} supplied",
1710+
expected_arg_count,
1711+
if expected_arg_count == 1 {""} else {"s"},
1712+
supplied_arg_count,
1713+
if supplied_arg_count == 1 {" was"} else {"s were"});
17111714

17121715
tcx.sess.span_err(sp, msg);
17131716

@@ -1722,10 +1725,12 @@ pub fn check_expr_with_unifier(fcx: @FnCtxt,
17221725
the `for` keyword)"
17231726
};
17241727
let msg = format!(
1725-
"this function takes {0, plural, =1{# parameter} \
1726-
other{# parameters}} but {1, plural, =1{# parameter was} \
1727-
other{# parameters were}} supplied{2}",
1728-
expected_arg_count, supplied_arg_count, suffix);
1728+
"this function takes {} parameter{} \
1729+
but {} parameter{} supplied{}",
1730+
expected_arg_count, if expected_arg_count == 1 {""} else {"s"},
1731+
supplied_arg_count,
1732+
if supplied_arg_count == 1 {" was"} else {"s were"},
1733+
suffix);
17291734

17301735
tcx.sess.span_err(sp, msg);
17311736

src/libstd/either.rs

-248
This file was deleted.

src/libstd/fmt/mod.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ impl<'a> Formatter<'a> {
757757
// offsetted value
758758
for s in selectors.iter() {
759759
match s.selector {
760-
Right(val) if value == val => {
760+
rt::Literal(val) if value == val => {
761761
return self.runplural(value, s.result);
762762
}
763763
_ => {}
@@ -769,17 +769,17 @@ impl<'a> Formatter<'a> {
769769
let value = value - match offset { Some(i) => i, None => 0 };
770770
for s in selectors.iter() {
771771
let run = match s.selector {
772-
Left(parse::Zero) => value == 0,
773-
Left(parse::One) => value == 1,
774-
Left(parse::Two) => value == 2,
772+
rt::Keyword(parse::Zero) => value == 0,
773+
rt::Keyword(parse::One) => value == 1,
774+
rt::Keyword(parse::Two) => value == 2,
775775

776776
// XXX: Few/Many should have a user-specified boundary
777777
// One possible option would be in the function
778778
// pointer of the 'arg: Argument' struct.
779-
Left(parse::Few) => value < 8,
780-
Left(parse::Many) => value >= 8,
779+
rt::Keyword(parse::Few) => value < 8,
780+
rt::Keyword(parse::Many) => value >= 8,
781781

782-
Right(..) => false
782+
rt::Literal(..) => false
783783
};
784784
if run {
785785
return self.runplural(value, s.result);

0 commit comments

Comments
 (0)