Skip to content

Remove std::either #11149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 3, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions src/libextra/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,14 @@ pub enum TestResult {
TrBench(BenchSamples),
}

enum OutputLocation<T> {
Pretty(term::Terminal<T>),
Raw(T),
}

struct ConsoleTestState<T> {
log_out: Option<File>,
out: Either<term::Terminal<T>, T>,
out: OutputLocation<T>,
use_color: bool,
total: uint,
passed: uint,
Expand All @@ -358,8 +363,8 @@ impl<T: Writer> ConsoleTestState<T> {
None => None
};
let out = match term::Terminal::new(io::stdout()) {
Err(_) => Right(io::stdout()),
Ok(t) => Left(t)
Err(_) => Raw(io::stdout()),
Ok(t) => Pretty(t)
};
ConsoleTestState {
out: out,
Expand Down Expand Up @@ -416,7 +421,7 @@ impl<T: Writer> ConsoleTestState<T> {
word: &str,
color: term::color::Color) {
match self.out {
Left(ref mut term) => {
Pretty(ref mut term) => {
if self.use_color {
term.fg(color);
}
Expand All @@ -425,14 +430,14 @@ impl<T: Writer> ConsoleTestState<T> {
term.reset();
}
}
Right(ref mut stdout) => stdout.write(word.as_bytes())
Raw(ref mut stdout) => stdout.write(word.as_bytes())
}
}

pub fn write_plain(&mut self, s: &str) {
match self.out {
Left(ref mut term) => term.write(s.as_bytes()),
Right(ref mut stdout) => stdout.write(s.as_bytes())
Pretty(ref mut term) => term.write(s.as_bytes()),
Raw(ref mut stdout) => stdout.write(s.as_bytes())
}
}

Expand Down Expand Up @@ -683,7 +688,7 @@ fn should_sort_failures_before_printing_them() {

let mut st = ConsoleTestState {
log_out: None,
out: Right(MemWriter::new()),
out: Raw(MemWriter::new()),
use_color: false,
total: 0u,
passed: 0u,
Expand All @@ -697,8 +702,8 @@ fn should_sort_failures_before_printing_them() {

st.write_failures();
let s = match st.out {
Right(ref m) => str::from_utf8(*m.inner_ref()),
Left(_) => unreachable!()
Raw(ref m) => str::from_utf8(*m.inner_ref()),
Pretty(_) => unreachable!()
};

let apos = s.find_str("a").unwrap();
Expand Down
19 changes: 12 additions & 7 deletions src/librustc/middle/typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1705,9 +1705,12 @@ pub fn check_expr_with_unifier(fcx: @FnCtxt,
fn_inputs.map(|a| *a)
} else {
let msg = format!(
"this function takes at least {0, plural, =1{# parameter} \
other{# parameters}} but {1, plural, =1{# parameter was} \
other{# parameters were}} supplied", expected_arg_count, supplied_arg_count);
"this function takes at least {} parameter{} \
but {} parameter{} supplied",
expected_arg_count,
if expected_arg_count == 1 {""} else {"s"},
supplied_arg_count,
if supplied_arg_count == 1 {" was"} else {"s were"});

tcx.sess.span_err(sp, msg);

Expand All @@ -1722,10 +1725,12 @@ pub fn check_expr_with_unifier(fcx: @FnCtxt,
the `for` keyword)"
};
let msg = format!(
"this function takes {0, plural, =1{# parameter} \
other{# parameters}} but {1, plural, =1{# parameter was} \
other{# parameters were}} supplied{2}",
expected_arg_count, supplied_arg_count, suffix);
"this function takes {} parameter{} \
but {} parameter{} supplied{}",
expected_arg_count, if expected_arg_count == 1 {""} else {"s"},
supplied_arg_count,
if supplied_arg_count == 1 {" was"} else {"s were"},
suffix);

tcx.sess.span_err(sp, msg);

Expand Down
248 changes: 0 additions & 248 deletions src/libstd/either.rs

This file was deleted.

14 changes: 7 additions & 7 deletions src/libstd/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ impl<'a> Formatter<'a> {
// offsetted value
for s in selectors.iter() {
match s.selector {
Right(val) if value == val => {
rt::Literal(val) if value == val => {
return self.runplural(value, s.result);
}
_ => {}
Expand All @@ -769,17 +769,17 @@ impl<'a> Formatter<'a> {
let value = value - match offset { Some(i) => i, None => 0 };
for s in selectors.iter() {
let run = match s.selector {
Left(parse::Zero) => value == 0,
Left(parse::One) => value == 1,
Left(parse::Two) => value == 2,
rt::Keyword(parse::Zero) => value == 0,
rt::Keyword(parse::One) => value == 1,
rt::Keyword(parse::Two) => value == 2,

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

Right(..) => false
rt::Literal(..) => false
};
if run {
return self.runplural(value, s.result);
Expand Down
Loading