Skip to content

Commit 20454da

Browse files
committed
auto merge of #8069 : erickt/rust/maikklein, r=erickt
Good evening, This is a superset of @MaikKlein's #7969 commit, that I've fixed up to compile. I had a couple commits I wanted to do on top of @MaikKlein's work that I didn't want to bitrot.
2 parents 9325535 + b147d70 commit 20454da

File tree

15 files changed

+379
-436
lines changed

15 files changed

+379
-436
lines changed

src/libextra/json.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -1867,35 +1867,34 @@ mod tests {
18671867
col: 8u,
18681868
msg: @~"EOF while parsing object"}));
18691869
1870-
assert_eq!(result::unwrap(from_str("{}")), mk_object([]));
1871-
assert_eq!(result::unwrap(from_str("{\"a\": 3}")),
1870+
assert_eq!(from_str("{}").unwrap(), mk_object([]));
1871+
assert_eq!(from_str("{\"a\": 3}").unwrap(),
18721872
mk_object([(~"a", Number(3.0f))]));
18731873
1874-
assert_eq!(result::unwrap(from_str(
1875-
"{ \"a\": null, \"b\" : true }")),
1874+
assert_eq!(from_str(
1875+
"{ \"a\": null, \"b\" : true }").unwrap(),
18761876
mk_object([
18771877
(~"a", Null),
18781878
(~"b", Boolean(true))]));
1879-
assert_eq!(result::unwrap(
1880-
from_str("\n{ \"a\": null, \"b\" : true }\n")),
1879+
assert_eq!(from_str("\n{ \"a\": null, \"b\" : true }\n").unwrap(),
18811880
mk_object([
18821881
(~"a", Null),
18831882
(~"b", Boolean(true))]));
1884-
assert_eq!(result::unwrap(from_str(
1885-
"{\"a\" : 1.0 ,\"b\": [ true ]}")),
1883+
assert_eq!(from_str(
1884+
"{\"a\" : 1.0 ,\"b\": [ true ]}").unwrap(),
18861885
mk_object([
18871886
(~"a", Number(1.0)),
18881887
(~"b", List(~[Boolean(true)]))
18891888
]));
1890-
assert_eq!(result::unwrap(from_str(
1889+
assert_eq!(from_str(
18911890
~"{" +
18921891
"\"a\": 1.0, " +
18931892
"\"b\": [" +
18941893
"true," +
18951894
"\"foo\\nbar\", " +
18961895
"{ \"c\": {\"d\": null} } " +
18971896
"]" +
1898-
"}")),
1897+
"}").unwrap(),
18991898
mk_object([
19001899
(~"a", Number(1.0f)),
19011900
(~"b", List(~[

src/libextra/time.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1132,13 +1132,13 @@ mod tests {
11321132
assert!(test("6", "%w"));
11331133
assert!(test("2009", "%Y"));
11341134
assert!(test("09", "%y"));
1135-
assert!(result::unwrap(strptime("UTC", "%Z")).tm_zone ==
1135+
assert!(strptime("UTC", "%Z").unwrap().tm_zone ==
11361136
~"UTC");
1137-
assert!(result::unwrap(strptime("PST", "%Z")).tm_zone ==
1137+
assert!(strptime("PST", "%Z").unwrap().tm_zone ==
11381138
~"");
1139-
assert!(result::unwrap(strptime("-0000", "%z")).tm_gmtoff ==
1139+
assert!(strptime("-0000", "%z").unwrap().tm_gmtoff ==
11401140
0);
1141-
assert!(result::unwrap(strptime("-0800", "%z")).tm_gmtoff ==
1141+
assert!(strptime("-0800", "%z").unwrap().tm_gmtoff ==
11421142
0);
11431143
assert!(test("%", "%%"));
11441144

src/libextra/workcache.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use std::cell::Cell;
2222
use std::comm::{PortOne, oneshot, send_one, recv_one};
2323
use std::either::{Either, Left, Right};
2424
use std::io;
25-
use std::result;
2625
use std::run;
2726
use std::task;
2827

@@ -208,7 +207,7 @@ fn json_encode<T:Encodable<json::Encoder>>(t: &T) -> ~str {
208207
// FIXME(#5121)
209208
fn json_decode<T:Decodable<json::Decoder>>(s: &str) -> T {
210209
do io::with_str_reader(s) |rdr| {
211-
let j = result::unwrap(json::from_reader(rdr));
210+
let j = json::from_reader(rdr).unwrap();
212211
let mut decoder = json::Decoder(j);
213212
Decodable::decode(&mut decoder)
214213
}

src/librustc/metadata/filesearch.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ pub fn get_rustpkg_root() -> Result<Path, ~str> {
147147
}
148148

149149
pub fn get_rustpkg_root_nearest() -> Result<Path, ~str> {
150-
do result::chain(get_rustpkg_root()) |p| {
150+
do get_rustpkg_root().chain |p| {
151151
let cwd = os::getcwd();
152152
let cwd_rustpkg = cwd.push(".rustpkg");
153153
let rustpkg_is_non_root_file =
@@ -173,13 +173,13 @@ pub fn get_rustpkg_root_nearest() -> Result<Path, ~str> {
173173
}
174174

175175
fn get_rustpkg_lib_path() -> Result<Path, ~str> {
176-
do result::chain(get_rustpkg_root()) |p| {
176+
do get_rustpkg_root().chain |p| {
177177
result::Ok(p.push(libdir()))
178178
}
179179
}
180180

181181
fn get_rustpkg_lib_path_nearest() -> Result<Path, ~str> {
182-
do result::chain(get_rustpkg_root_nearest()) |p| {
182+
do get_rustpkg_root_nearest().chain |p| {
183183
result::Ok(p.push(libdir()))
184184
}
185185
}

src/librustdoc/config.rs

+10-16
Original file line numberDiff line numberDiff line change
@@ -138,36 +138,30 @@ fn config_from_opts(
138138

139139
let config = default_config(input_crate);
140140
let result = result::Ok(config);
141-
let result = do result::chain(result) |config| {
141+
let result = do result.chain |config| {
142142
let output_dir = getopts::opt_maybe_str(matches, opt_output_dir());
143143
let output_dir = output_dir.map(|s| Path(*s));
144144
result::Ok(Config {
145145
output_dir: output_dir.get_or_default(config.output_dir.clone()),
146146
.. config
147147
})
148148
};
149-
let result = do result::chain(result) |config| {
150-
let output_format = getopts::opt_maybe_str(
151-
matches, opt_output_format());
152-
do output_format.map_default(result::Ok(config.clone()))
153-
|output_format| {
154-
do result::chain(parse_output_format(*output_format))
155-
|output_format| {
156-
149+
let result = do result.chain |config| {
150+
let output_format = getopts::opt_maybe_str(matches, opt_output_format());
151+
do output_format.map_default(result::Ok(config.clone())) |output_format| {
152+
do parse_output_format(*output_format).chain |output_format| {
157153
result::Ok(Config {
158154
output_format: output_format,
159155
.. config.clone()
160156
})
161157
}
162158
}
163159
};
164-
let result = do result::chain(result) |config| {
160+
let result = do result.chain |config| {
165161
let output_style =
166162
getopts::opt_maybe_str(matches, opt_output_style());
167-
do output_style.map_default(result::Ok(config.clone()))
168-
|output_style| {
169-
do result::chain(parse_output_style(*output_style))
170-
|output_style| {
163+
do output_style.map_default(result::Ok(config.clone())) |output_style| {
164+
do parse_output_style(*output_style).chain |output_style| {
171165
result::Ok(Config {
172166
output_style: output_style,
173167
.. config.clone()
@@ -176,11 +170,11 @@ fn config_from_opts(
176170
}
177171
};
178172
let process_output = Cell::new(process_output);
179-
let result = do result::chain(result) |config| {
173+
let result = do result.chain |config| {
180174
let pandoc_cmd = getopts::opt_maybe_str(matches, opt_pandoc_cmd());
181175
let pandoc_cmd = maybe_find_pandoc(
182176
&config, pandoc_cmd, process_output.take());
183-
do result::chain(pandoc_cmd) |pandoc_cmd| {
177+
do pandoc_cmd.chain |pandoc_cmd| {
184178
result::Ok(Config {
185179
pandoc_cmd: pandoc_cmd,
186180
.. config.clone()

src/librustpkg/tests.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ fn git_repo_pkg() -> PkgId {
6262
}
6363

6464
fn writeFile(file_path: &Path, contents: &str) {
65-
let out: @io::Writer =
66-
result::unwrap(io::file_writer(file_path,
67-
[io::Create, io::Truncate]));
65+
let out = io::file_writer(file_path, [io::Create, io::Truncate]).unwrap();
6866
out.write_line(contents);
6967
}
7068

src/libstd/io.rs

+31-35
Original file line numberDiff line numberDiff line change
@@ -46,28 +46,26 @@ implement `Reader` and `Writer`, where appropriate.
4646

4747
#[allow(missing_doc)];
4848

49-
use result::Result;
50-
49+
use cast;
5150
use clone::Clone;
5251
use container::Container;
5352
use int;
54-
use libc;
55-
use libc::{c_int, c_long, c_void, size_t, ssize_t};
53+
use iterator::IteratorUtil;
5654
use libc::consts::os::posix88::*;
55+
use libc::{c_int, c_long, c_void, size_t, ssize_t};
56+
use libc;
5757
use num;
58+
use ops::Drop;
5859
use os;
59-
use cast;
6060
use path::Path;
61-
use ops::Drop;
62-
use iterator::IteratorUtil;
6361
use ptr;
64-
use result;
65-
use str;
62+
use result::{Result, Ok, Err};
6663
use str::{StrSlice, OwnedStr};
64+
use str;
6765
use to_str::ToStr;
6866
use uint;
69-
use vec;
7067
use vec::{MutableVector, ImmutableVector, OwnedVector, OwnedCopyableVector, CopyableVector};
68+
use vec;
7169

7270
#[allow(non_camel_case_types)] // not sure what to do about this
7371
pub type fd_t = c_int;
@@ -1038,9 +1036,9 @@ pub fn file_reader(path: &Path) -> Result<@Reader, ~str> {
10381036
};
10391037
10401038
if f as uint == 0u {
1041-
result::Err(~"error opening " + path.to_str())
1039+
Err(~"error opening " + path.to_str())
10421040
} else {
1043-
result::Ok(FILE_reader(f, true))
1041+
Ok(FILE_reader(f, true))
10441042
}
10451043
}
10461044
@@ -1287,10 +1285,9 @@ pub fn mk_file_writer(path: &Path, flags: &[FileFlag])
12871285
}
12881286
};
12891287
if fd < (0 as c_int) {
1290-
result::Err(fmt!("error opening %s: %s", path.to_str(),
1291-
os::last_os_error()))
1288+
Err(fmt!("error opening %s: %s", path.to_str(), os::last_os_error()))
12921289
} else {
1293-
result::Ok(fd_writer(fd, true))
1290+
Ok(fd_writer(fd, true))
12941291
}
12951292
}
12961293

@@ -1559,7 +1556,7 @@ impl<T:Writer> WriterUtil for T {
15591556
}
15601557

15611558
pub fn file_writer(path: &Path, flags: &[FileFlag]) -> Result<@Writer, ~str> {
1562-
mk_file_writer(path, flags).chain(|w| result::Ok(w))
1559+
mk_file_writer(path, flags).chain(|w| Ok(w))
15631560
}
15641561

15651562

@@ -1572,9 +1569,9 @@ pub fn buffered_file_writer(path: &Path) -> Result<@Writer, ~str> {
15721569
}
15731570
};
15741571
return if f as uint == 0u {
1575-
result::Err(~"error opening " + path.to_str())
1572+
Err(~"error opening " + path.to_str())
15761573
} else {
1577-
result::Ok(FILE_writer(f, true))
1574+
Ok(FILE_writer(f, true))
15781575
}
15791576
}
15801577
}
@@ -1726,21 +1723,21 @@ pub fn seek_in_buf(offset: int, pos: uint, len: uint, whence: SeekStyle) ->
17261723
}
17271724

17281725
pub fn read_whole_file_str(file: &Path) -> Result<~str, ~str> {
1729-
result::chain(read_whole_file(file), |bytes| {
1726+
do read_whole_file(file).chain |bytes| {
17301727
if str::is_utf8(bytes) {
1731-
result::Ok(str::from_bytes(bytes))
1728+
Ok(str::from_bytes(bytes))
17321729
} else {
1733-
result::Err(file.to_str() + " is not UTF-8")
1730+
Err(file.to_str() + " is not UTF-8")
17341731
}
1735-
})
1732+
}
17361733
}
17371734

17381735
// FIXME (#2004): implement this in a low-level way. Going through the
17391736
// abstractions is pointless.
17401737
pub fn read_whole_file(file: &Path) -> Result<~[u8], ~str> {
1741-
result::chain(file_reader(file), |rdr| {
1742-
result::Ok(rdr.read_whole_stream())
1743-
})
1738+
do file_reader(file).chain |rdr| {
1739+
Ok(rdr.read_whole_stream())
1740+
}
17441741
}
17451742

17461743
// fsync related
@@ -1839,6 +1836,7 @@ mod tests {
18391836
use io::{BytesWriter, SeekCur, SeekEnd, SeekSet};
18401837
use io;
18411838
use path::Path;
1839+
use result::{Ok, Err};
18421840
use result;
18431841
use u64;
18441842
use vec;
@@ -1851,12 +1849,10 @@ mod tests {
18511849
~"A hoopy frood who really knows where his towel is.";
18521850
debug!(frood.clone());
18531851
{
1854-
let out: @io::Writer =
1855-
result::unwrap(
1856-
io::file_writer(tmpfile, [io::Create, io::Truncate]));
1852+
let out = io::file_writer(tmpfile, [io::Create, io::Truncate]).unwrap();
18571853
out.write_str(frood);
18581854
}
1859-
let inp: @io::Reader = result::unwrap(io::file_reader(tmpfile));
1855+
let inp = io::file_reader(tmpfile).unwrap();
18601856
let frood2: ~str = inp.read_c_str();
18611857
debug!(frood2.clone());
18621858
assert_eq!(frood, frood2);
@@ -1941,10 +1937,10 @@ mod tests {
19411937
#[test]
19421938
fn file_reader_not_exist() {
19431939
match io::file_reader(&Path("not a file")) {
1944-
result::Err(e) => {
1940+
Err(e) => {
19451941
assert_eq!(e, ~"error opening not a file");
19461942
}
1947-
result::Ok(_) => fail!()
1943+
Ok(_) => fail!()
19481944
}
19491945
}
19501946
@@ -1982,20 +1978,20 @@ mod tests {
19821978
#[test]
19831979
fn file_writer_bad_name() {
19841980
match io::file_writer(&Path("?/?"), []) {
1985-
result::Err(e) => {
1981+
Err(e) => {
19861982
assert!(e.starts_with("error opening"));
19871983
}
1988-
result::Ok(_) => fail!()
1984+
Ok(_) => fail!()
19891985
}
19901986
}
19911987
19921988
#[test]
19931989
fn buffered_file_writer_bad_name() {
19941990
match io::buffered_file_writer(&Path("?/?")) {
1995-
result::Err(e) => {
1991+
Err(e) => {
19961992
assert!(e.starts_with("error opening"));
19971993
}
1998-
result::Ok(_) => fail!()
1994+
Ok(_) => fail!()
19991995
}
20001996
}
20011997

0 commit comments

Comments
 (0)