Skip to content

Commit bbda3fa

Browse files
committed
auto merge of #8288 : Kimundi/rust/opteitres4, r=brson
This is an alternative version to #8268, where instead of transitioning to `get()` completely, I transitioned to `unwrap()` completely. My reasoning for also opening this PR is that having two different functions with identical behavior on a common datatype is bad for consistency and confusing for users, and should be solved as soon as possible. The fact that apparently half the code uses `get()`, and the other half `unwrap()` only makes it worse. If the final naming decision ends up different, there needs to be a big renaming anyway, but until then it should at least be consistent. --- - Made naming schemes consistent between Option, Result and Either - Lifted the quality of the either and result module to that of option - Changed Options Add implementation to work like the maybe Monad (return None if any of the inputs is None) See #6002, especially my last comment. - Removed duplicate Option::get and renamed all related functions to use the term `unwrap` instead See also #7887. Todo: Adding testcases for all function in the three modules. Even without the few functions I added, the coverage wasn't complete to begin with. But I'd rather do that as a follow up PR, I've touched to much code here already, need to go through them again later.
2 parents 29099e4 + 0ac7a21 commit bbda3fa

File tree

115 files changed

+792
-817
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+792
-817
lines changed

src/compiletest/compiletest.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ pub fn parse_config(args: ~[~str]) -> config {
131131
ratchet_noise_percent:
132132
getopts::opt_maybe_str(matches,
133133
"ratchet-noise-percent").map(|s|
134-
f64::from_str(*s).get()),
134+
f64::from_str(*s).unwrap()),
135135
runtool: getopts::opt_maybe_str(matches, "runtool"),
136136
rustcflags: getopts::opt_maybe_str(matches, "rustcflags"),
137137
jit: getopts::opt_present(matches, "jit"),
@@ -267,7 +267,7 @@ pub fn is_test(config: &config, testfile: &Path) -> bool {
267267
_ => ~[~".rc", ~".rs"]
268268
};
269269
let invalid_prefixes = ~[~".", ~"#", ~"~"];
270-
let name = testfile.filename().get();
270+
let name = testfile.filename().unwrap();
271271

272272
let mut valid = false;
273273

@@ -300,7 +300,7 @@ pub fn make_test_name(config: &config, testfile: &Path) -> test::TestName {
300300
fn shorten(path: &Path) -> ~str {
301301
let filename = path.filename();
302302
let dir = path.pop().filename();
303-
fmt!("%s/%s", dir.get_or_default(~""), filename.get_or_default(~""))
303+
fmt!("%s/%s", dir.unwrap_or_default(~""), filename.unwrap_or_default(~""))
304304
}
305305

306306
test::DynTestName(fmt!("[%s] %s",

src/compiletest/runtest.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ fn run_pretty_test(config: &config, props: &TestProps, testfile: &Path) {
145145
let rounds =
146146
match props.pp_exact { Some(_) => 1, None => 2 };
147147

148-
let mut srcs = ~[io::read_whole_file_str(testfile).get()];
148+
let mut srcs = ~[io::read_whole_file_str(testfile).unwrap()];
149149

150150
let mut round = 0;
151151
while round < rounds {
@@ -166,7 +166,7 @@ fn run_pretty_test(config: &config, props: &TestProps, testfile: &Path) {
166166
match props.pp_exact {
167167
Some(ref file) => {
168168
let filepath = testfile.dir_path().push_rel(file);
169-
io::read_whole_file_str(&filepath).get()
169+
io::read_whole_file_str(&filepath).unwrap()
170170
}
171171
None => { srcs[srcs.len() - 2u].clone() }
172172
};
@@ -448,7 +448,7 @@ fn scan_until_char(haystack: &str, needle: char, idx: &mut uint) -> bool {
448448
if opt.is_none() {
449449
return false;
450450
}
451-
*idx = opt.get();
451+
*idx = opt.unwrap();
452452
return true;
453453
}
454454

@@ -709,7 +709,7 @@ fn aux_output_dir_name(config: &config, testfile: &Path) -> Path {
709709
}
710710

711711
fn output_testname(testfile: &Path) -> Path {
712-
Path(testfile.filestem().get())
712+
Path(testfile.filestem().unwrap())
713713
}
714714

715715
fn output_base_name(config: &config, testfile: &Path) -> Path {
@@ -878,7 +878,7 @@ fn append_suffix_to_stem(p: &Path, suffix: &str) -> Path {
878878
if suffix.len() == 0 {
879879
(*p).clone()
880880
} else {
881-
let stem = p.filestem().get();
881+
let stem = p.filestem().unwrap();
882882
p.with_filestem(stem + "-" + suffix)
883883
}
884884
}
@@ -938,7 +938,7 @@ fn disassemble_extract(config: &config, _props: &TestProps,
938938

939939

940940
fn count_extracted_lines(p: &Path) -> uint {
941-
let x = io::read_whole_file_str(&p.with_filetype("ll")).get();
941+
let x = io::read_whole_file_str(&p.with_filetype("ll")).unwrap();
942942
x.line_iter().len_()
943943
}
944944

src/libextra/base64.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -322,24 +322,24 @@ mod test {
322322
323323
#[test]
324324
fn test_from_base64_basic() {
325-
assert_eq!("".from_base64().get(), "".as_bytes().to_owned());
326-
assert_eq!("Zg==".from_base64().get(), "f".as_bytes().to_owned());
327-
assert_eq!("Zm8=".from_base64().get(), "fo".as_bytes().to_owned());
328-
assert_eq!("Zm9v".from_base64().get(), "foo".as_bytes().to_owned());
329-
assert_eq!("Zm9vYg==".from_base64().get(), "foob".as_bytes().to_owned());
330-
assert_eq!("Zm9vYmE=".from_base64().get(), "fooba".as_bytes().to_owned());
331-
assert_eq!("Zm9vYmFy".from_base64().get(), "foobar".as_bytes().to_owned());
325+
assert_eq!("".from_base64().unwrap(), "".as_bytes().to_owned());
326+
assert_eq!("Zg==".from_base64().unwrap(), "f".as_bytes().to_owned());
327+
assert_eq!("Zm8=".from_base64().unwrap(), "fo".as_bytes().to_owned());
328+
assert_eq!("Zm9v".from_base64().unwrap(), "foo".as_bytes().to_owned());
329+
assert_eq!("Zm9vYg==".from_base64().unwrap(), "foob".as_bytes().to_owned());
330+
assert_eq!("Zm9vYmE=".from_base64().unwrap(), "fooba".as_bytes().to_owned());
331+
assert_eq!("Zm9vYmFy".from_base64().unwrap(), "foobar".as_bytes().to_owned());
332332
}
333333
334334
#[test]
335335
fn test_from_base64_newlines() {
336-
assert_eq!("Zm9v\r\nYmFy".from_base64().get(),
336+
assert_eq!("Zm9v\r\nYmFy".from_base64().unwrap(),
337337
"foobar".as_bytes().to_owned());
338338
}
339339
340340
#[test]
341341
fn test_from_base64_urlsafe() {
342-
assert_eq!("-_8".from_base64().get(), "+/8=".from_base64().get());
342+
assert_eq!("-_8".from_base64().unwrap(), "+/8=".from_base64().unwrap());
343343
}
344344
345345
#[test]
@@ -364,7 +364,7 @@ mod test {
364364
push(random());
365365
}
366366
};
367-
assert_eq!(v.to_base64(STANDARD).from_base64().get(), v);
367+
assert_eq!(v.to_base64(STANDARD).from_base64().unwrap(), v);
368368
}
369369
}
370370

src/libextra/fileinput.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -526,8 +526,8 @@ mod test {
526526

527527
do input_vec_state(filenames) |line, state| {
528528
let nums: ~[&str] = line.split_iter(' ').collect();
529-
let file_num = uint::from_str(nums[0]).get();
530-
let line_num = uint::from_str(nums[1]).get();
529+
let file_num = uint::from_str(nums[0]).unwrap();
530+
let line_num = uint::from_str(nums[1]).unwrap();
531531
assert_eq!(line_num, state.line_num_file);
532532
assert_eq!(file_num * 3 + line_num, state.line_num);
533533
true

src/libextra/getopts.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ fn find_opt(opts: &[Opt], nm: Name) -> Option<uint> {
196196
* The type returned when the command line does not conform to the
197197
* expected format. Pass this value to <fail_str> to get an error message.
198198
*/
199-
#[deriving(Clone, Eq)]
199+
#[deriving(Clone, Eq, ToStr)]
200200
pub enum Fail_ {
201201
ArgumentMissing(~str),
202202
UnrecognizedOption(~str),
@@ -288,7 +288,7 @@ pub fn getopts(args: &[~str], opts: &[Opt]) -> Result {
288288
None => {
289289
let arg_follows =
290290
last_valid_opt_id.is_some() &&
291-
match opts[last_valid_opt_id.get()]
291+
match opts[last_valid_opt_id.unwrap()]
292292
.hasarg {
293293
294294
Yes | Maybe => true,
@@ -322,15 +322,15 @@ pub fn getopts(args: &[~str], opts: &[Opt]) -> Result {
322322
}
323323
Maybe => {
324324
if !i_arg.is_none() {
325-
vals[optid].push(Val((i_arg.clone()).get()));
325+
vals[optid].push(Val((i_arg.clone()).unwrap()));
326326
} else if name_pos < names.len() ||
327327
i + 1 == l || is_arg(args[i + 1]) {
328328
vals[optid].push(Given);
329329
} else { i += 1; vals[optid].push(Val(args[i].clone())); }
330330
}
331331
Yes => {
332332
if !i_arg.is_none() {
333-
vals[optid].push(Val(i_arg.clone().get()));
333+
vals[optid].push(Val(i_arg.clone().unwrap()));
334334
} else if i + 1 == l {
335335
return Err(ArgumentMissing(name_str(nm)));
336336
} else { i += 1; vals[optid].push(Val(args[i].clone())); }

src/libextra/num/bigint.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1510,11 +1510,11 @@ mod biguint_tests {
15101510

15111511
#[test]
15121512
fn test_is_even() {
1513-
assert!(FromStr::from_str::<BigUint>("1").get().is_odd());
1514-
assert!(FromStr::from_str::<BigUint>("2").get().is_even());
1515-
assert!(FromStr::from_str::<BigUint>("1000").get().is_even());
1516-
assert!(FromStr::from_str::<BigUint>("1000000000000000000000").get().is_even());
1517-
assert!(FromStr::from_str::<BigUint>("1000000000000000000001").get().is_odd());
1513+
assert!(FromStr::from_str::<BigUint>("1").unwrap().is_odd());
1514+
assert!(FromStr::from_str::<BigUint>("2").unwrap().is_even());
1515+
assert!(FromStr::from_str::<BigUint>("1000").unwrap().is_even());
1516+
assert!(FromStr::from_str::<BigUint>("1000000000000000000000").unwrap().is_even());
1517+
assert!(FromStr::from_str::<BigUint>("1000000000000000000001").unwrap().is_odd());
15181518
assert!((BigUint::from_uint(1) << 64).is_even());
15191519
assert!(((BigUint::from_uint(1) << 64) + BigUint::from_uint(1)).is_odd());
15201520
}
@@ -1595,7 +1595,7 @@ mod biguint_tests {
15951595
let &(ref n, ref rs) = num_pair;
15961596
for str_pair in rs.iter() {
15971597
let &(ref radix, ref str) = str_pair;
1598-
assert_eq!(n, &FromStrRadix::from_str_radix(*str, *radix).get());
1598+
assert_eq!(n, &FromStrRadix::from_str_radix(*str, *radix).unwrap());
15991599
}
16001600
}
16011601

src/libextra/ringbuf.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -437,12 +437,12 @@ mod tests {
437437
assert_eq!(deq.len(), 3);
438438
deq.push_back(d.clone());
439439
assert_eq!(deq.len(), 4);
440-
assert_eq!((*deq.front().get()).clone(), b.clone());
441-
assert_eq!((*deq.back().get()).clone(), d.clone());
442-
assert_eq!(deq.pop_front().get(), b.clone());
443-
assert_eq!(deq.pop_back().get(), d.clone());
444-
assert_eq!(deq.pop_back().get(), c.clone());
445-
assert_eq!(deq.pop_back().get(), a.clone());
440+
assert_eq!((*deq.front().unwrap()).clone(), b.clone());
441+
assert_eq!((*deq.back().unwrap()).clone(), d.clone());
442+
assert_eq!(deq.pop_front().unwrap(), b.clone());
443+
assert_eq!(deq.pop_back().unwrap(), d.clone());
444+
assert_eq!(deq.pop_back().unwrap(), c.clone());
445+
assert_eq!(deq.pop_back().unwrap(), a.clone());
446446
assert_eq!(deq.len(), 0);
447447
deq.push_back(c.clone());
448448
assert_eq!(deq.len(), 1);

src/libextra/semver.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,8 @@ fn test_spec_order() {
386386
"1.0.0"];
387387
let mut i = 1;
388388
while i < vs.len() {
389-
let a = parse(vs[i-1]).get();
390-
let b = parse(vs[i]).get();
389+
let a = parse(vs[i-1]).unwrap();
390+
let b = parse(vs[i]).unwrap();
391391
assert!(a < b);
392392
i += 1;
393393
}

src/libextra/smallintmap.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -366,9 +366,9 @@ mod test_map {
366366
map.update_with_key(3, 2, addMoreToCount);
367367

368368
// check the total counts
369-
assert_eq!(map.find(&3).get(), &10);
370-
assert_eq!(map.find(&5).get(), &3);
371-
assert_eq!(map.find(&9).get(), &1);
369+
assert_eq!(map.find(&3).unwrap(), &10);
370+
assert_eq!(map.find(&5).unwrap(), &3);
371+
assert_eq!(map.find(&9).unwrap(), &1);
372372

373373
// sadly, no sevens were counted
374374
assert!(map.find(&7).is_none());

src/libextra/test.rs

+28-29
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,8 @@ pub fn parse_opts(args: &[~str]) -> OptRes {
247247
let ratchet_metrics = getopts::opt_maybe_str(&matches, "ratchet-metrics");
248248
let ratchet_metrics = ratchet_metrics.map(|s| Path(*s));
249249

250-
let ratchet_noise_percent =
251-
getopts::opt_maybe_str(&matches, "ratchet-noise-percent");
252-
let ratchet_noise_percent = ratchet_noise_percent.map(|s| f64::from_str(*s).get());
250+
let ratchet_noise_percent = getopts::opt_maybe_str(&matches, "ratchet-noise-percent");
251+
let ratchet_noise_percent = ratchet_noise_percent.map(|s| f64::from_str(*s).unwrap());
253252

254253
let save_metrics = getopts::opt_maybe_str(&matches, "save-metrics");
255254
let save_metrics = save_metrics.map(|s| Path(*s));
@@ -631,8 +630,8 @@ fn should_sort_failures_before_printing_them() {
631630
st.write_failures();
632631
};
633632

634-
let apos = s.find_str("a").get();
635-
let bpos = s.find_str("b").get();
633+
let apos = s.find_str("a").unwrap();
634+
let bpos = s.find_str("b").unwrap();
636635
assert!(apos < bpos);
637636
}
638637

@@ -868,7 +867,7 @@ impl MetricMap {
868867
pub fn load(p: &Path) -> MetricMap {
869868
assert!(os::path_exists(p));
870869
let f = io::file_reader(p).unwrap();
871-
let mut decoder = json::Decoder(json::from_reader(f).get());
870+
let mut decoder = json::Decoder(json::from_reader(f).unwrap());
872871
MetricMap(Decodable::decode(&mut decoder))
873872
}
874873

@@ -1207,7 +1206,7 @@ mod tests {
12071206
either::Left(o) => o,
12081207
_ => fail!("Malformed arg in first_free_arg_should_be_a_filter")
12091208
};
1210-
assert!("filter" == opts.filter.clone().get());
1209+
assert!("filter" == opts.filter.clone().unwrap());
12111210
}
12121211

12131212
#[test]
@@ -1346,28 +1345,28 @@ mod tests {
13461345
13471346
let diff1 = m2.compare_to_old(&m1, None);
13481347
1349-
assert_eq!(*(diff1.find(&~"in-both-noise").get()), LikelyNoise);
1350-
assert_eq!(*(diff1.find(&~"in-first-noise").get()), MetricRemoved);
1351-
assert_eq!(*(diff1.find(&~"in-second-noise").get()), MetricAdded);
1352-
assert_eq!(*(diff1.find(&~"in-both-want-downwards-but-regressed").get()),
1348+
assert_eq!(*(diff1.find(&~"in-both-noise").unwrap()), LikelyNoise);
1349+
assert_eq!(*(diff1.find(&~"in-first-noise").unwrap()), MetricRemoved);
1350+
assert_eq!(*(diff1.find(&~"in-second-noise").unwrap()), MetricAdded);
1351+
assert_eq!(*(diff1.find(&~"in-both-want-downwards-but-regressed").unwrap()),
13531352
Regression(100.0));
1354-
assert_eq!(*(diff1.find(&~"in-both-want-downwards-and-improved").get()),
1353+
assert_eq!(*(diff1.find(&~"in-both-want-downwards-and-improved").unwrap()),
13551354
Improvement(50.0));
1356-
assert_eq!(*(diff1.find(&~"in-both-want-upwards-but-regressed").get()),
1355+
assert_eq!(*(diff1.find(&~"in-both-want-upwards-but-regressed").unwrap()),
13571356
Regression(50.0));
1358-
assert_eq!(*(diff1.find(&~"in-both-want-upwards-and-improved").get()),
1357+
assert_eq!(*(diff1.find(&~"in-both-want-upwards-and-improved").unwrap()),
13591358
Improvement(100.0));
13601359
assert_eq!(diff1.len(), 7);
13611360
13621361
let diff2 = m2.compare_to_old(&m1, Some(200.0));
13631362
1364-
assert_eq!(*(diff2.find(&~"in-both-noise").get()), LikelyNoise);
1365-
assert_eq!(*(diff2.find(&~"in-first-noise").get()), MetricRemoved);
1366-
assert_eq!(*(diff2.find(&~"in-second-noise").get()), MetricAdded);
1367-
assert_eq!(*(diff2.find(&~"in-both-want-downwards-but-regressed").get()), LikelyNoise);
1368-
assert_eq!(*(diff2.find(&~"in-both-want-downwards-and-improved").get()), LikelyNoise);
1369-
assert_eq!(*(diff2.find(&~"in-both-want-upwards-but-regressed").get()), LikelyNoise);
1370-
assert_eq!(*(diff2.find(&~"in-both-want-upwards-and-improved").get()), LikelyNoise);
1363+
assert_eq!(*(diff2.find(&~"in-both-noise").unwrap()), LikelyNoise);
1364+
assert_eq!(*(diff2.find(&~"in-first-noise").unwrap()), MetricRemoved);
1365+
assert_eq!(*(diff2.find(&~"in-second-noise").unwrap()), MetricAdded);
1366+
assert_eq!(*(diff2.find(&~"in-both-want-downwards-but-regressed").unwrap()), LikelyNoise);
1367+
assert_eq!(*(diff2.find(&~"in-both-want-downwards-and-improved").unwrap()), LikelyNoise);
1368+
assert_eq!(*(diff2.find(&~"in-both-want-upwards-but-regressed").unwrap()), LikelyNoise);
1369+
assert_eq!(*(diff2.find(&~"in-both-want-upwards-and-improved").unwrap()), LikelyNoise);
13711370
assert_eq!(diff2.len(), 7);
13721371
}
13731372
@@ -1391,28 +1390,28 @@ mod tests {
13911390
let (diff1, ok1) = m2.ratchet(&pth, None);
13921391
assert_eq!(ok1, false);
13931392
assert_eq!(diff1.len(), 2);
1394-
assert_eq!(*(diff1.find(&~"runtime").get()), Regression(10.0));
1395-
assert_eq!(*(diff1.find(&~"throughput").get()), LikelyNoise);
1393+
assert_eq!(*(diff1.find(&~"runtime").unwrap()), Regression(10.0));
1394+
assert_eq!(*(diff1.find(&~"throughput").unwrap()), LikelyNoise);
13961395
13971396
// Check that it was not rewritten.
13981397
let m3 = MetricMap::load(&pth);
13991398
assert_eq!(m3.len(), 2);
1400-
assert_eq!(*(m3.find(&~"runtime").get()), Metric { value: 1000.0, noise: 2.0 });
1401-
assert_eq!(*(m3.find(&~"throughput").get()), Metric { value: 50.0, noise: 2.0 });
1399+
assert_eq!(*(m3.find(&~"runtime").unwrap()), Metric { value: 1000.0, noise: 2.0 });
1400+
assert_eq!(*(m3.find(&~"throughput").unwrap()), Metric { value: 50.0, noise: 2.0 });
14021401
14031402
// Ask for a ratchet with an explicit noise-percentage override,
14041403
// that should advance.
14051404
let (diff2, ok2) = m2.ratchet(&pth, Some(10.0));
14061405
assert_eq!(ok2, true);
14071406
assert_eq!(diff2.len(), 2);
1408-
assert_eq!(*(diff2.find(&~"runtime").get()), LikelyNoise);
1409-
assert_eq!(*(diff2.find(&~"throughput").get()), LikelyNoise);
1407+
assert_eq!(*(diff2.find(&~"runtime").unwrap()), LikelyNoise);
1408+
assert_eq!(*(diff2.find(&~"throughput").unwrap()), LikelyNoise);
14101409
14111410
// Check that it was rewritten.
14121411
let m4 = MetricMap::load(&pth);
14131412
assert_eq!(m4.len(), 2);
1414-
assert_eq!(*(m4.find(&~"runtime").get()), Metric { value: 1100.0, noise: 2.0 });
1415-
assert_eq!(*(m4.find(&~"throughput").get()), Metric { value: 50.0, noise: 2.0 });
1413+
assert_eq!(*(m4.find(&~"runtime").unwrap()), Metric { value: 1100.0, noise: 2.0 });
1414+
assert_eq!(*(m4.find(&~"throughput").unwrap()), Metric { value: 50.0, noise: 2.0 });
14161415

14171416
os::remove_dir_recursive(&dpth);
14181417
}

src/libextra/url.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ fn decode_inner(s: &str, full_url: bool) -> ~str {
134134
match rdr.read_char() {
135135
'%' => {
136136
let bytes = rdr.read_bytes(2u);
137-
let ch = uint::parse_bytes(bytes, 16u).get() as char;
137+
let ch = uint::parse_bytes(bytes, 16u).unwrap() as char;
138138

139139
if full_url {
140140
// Only decode some characters:
@@ -257,7 +257,7 @@ pub fn decode_form_urlencoded(s: &[u8]) -> HashMap<~str, ~[~str]> {
257257
let ch = match ch {
258258
'%' => {
259259
let bytes = rdr.read_bytes(2u);
260-
uint::parse_bytes(bytes, 16u).get() as char
260+
uint::parse_bytes(bytes, 16u).unwrap() as char
261261
}
262262
'+' => ' ',
263263
ch => ch

src/librustc/back/link.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@ pub fn link_args(sess: Session,
912912
}
913913
let dir = cratepath.dirname();
914914
if dir != ~"" { args.push(~"-L" + dir); }
915-
let libarg = unlib(sess.targ_cfg, cratepath.filestem().get());
915+
let libarg = unlib(sess.targ_cfg, cratepath.filestem().unwrap());
916916
args.push(~"-l" + libarg);
917917
}
918918

@@ -950,7 +950,7 @@ pub fn link_args(sess: Session,
950950
// be rpathed
951951
if sess.targ_cfg.os == session::os_macos {
952952
args.push(~"-Wl,-install_name,@rpath/"
953-
+ output.filename().get());
953+
+ output.filename().unwrap());
954954
}
955955
}
956956

0 commit comments

Comments
 (0)