Skip to content

Commit de4a4bf

Browse files
committed
auto merge of rust-lang#78 : huonw/cargo/minor-de-.unwrapping, r=alexcrichton
I don't think any of the `.unwrap`s I touched can actually be hit since they all seem to have checks earlier, but reducing the number of calls is always nice and makes the code easier to verify. I'm not sure if the `,` -> `:` commit is actually correct, I was just working from the surrounding context.
2 parents c993a54 + 3543133 commit de4a4bf

File tree

4 files changed

+23
-23
lines changed

4 files changed

+23
-23
lines changed

src/bin/cargo-verify-project.rs

100644100755
+8-7
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@ fn main() {
2626
}
2727
};
2828

29-
if !matches.opt_present("m") {
30-
fail("missing-argument", "manifest");
31-
return;
32-
}
33-
34-
let manifest = matches.opt_str("m").unwrap();
29+
let manifest = match matches.opt_str("m") {
30+
Some(m) => m,
31+
None => {
32+
fail("missing-argument", "manifest");
33+
return;
34+
}
35+
};
3536
let file = Path::new(manifest);
3637
let contents = match File::open(&file).read_to_str() {
3738
Ok(s) => s,
@@ -50,6 +51,6 @@ fn main() {
5051
}
5152

5253
fn fail(reason: &str, value: &str) {
53-
println!(r#"{{ "{:s}", "{:s}" }}"#, reason, value);
54+
println!(r#"{{ "{:s}": "{:s}" }}"#, reason, value);
5455
set_exit_status(1);
5556
}

src/cargo/core/package.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,13 @@ impl PackageSet {
155155
}
156156

157157
pub fn pop(&mut self) -> Package {
158-
self.packages.pop().unwrap()
158+
self.packages.pop().expect("PackageSet.pop: empty set")
159159
}
160160

161161
/// Get a package by name out of the set
162162
pub fn get<'a>(&'a self, name: &str) -> &'a Package {
163-
self.packages.iter().find(|pkg| name == pkg.get_name()).unwrap()
163+
self.packages.iter().find(|pkg| name == pkg.get_name())
164+
.expect("PackageSet.get: empty set")
164165
}
165166

166167
pub fn get_all<'a>(&'a self, names: &[&str]) -> Vec<&'a Package> {

src/cargo/ops/cargo_rustc.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,9 @@ fn compile_custom(pkg: &Package, cmd: &str, cx: &Context) -> CargoResult<()> {
168168
let mut cmd = cmd.split(' ');
169169
let mut p = util::process(cmd.next().unwrap())
170170
.cwd(pkg.get_root())
171-
.env("OUT_DIR", Some(cx.dest.as_str().unwrap()))
171+
.env("OUT_DIR", Some(cx.dest.as_str().expect("non-UTF8 dest path")))
172172
.env("DEPS_DIR", Some(cx.dest.join(cx.deps_dir)
173-
.as_str().unwrap()));
173+
.as_str().expect("non-UTF8 deps path")));
174174
for arg in cmd {
175175
p = p.arg(arg);
176176
}

src/cargo/util/config.rs

+10-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{io,fmt,os};
1+
use std::{io,fmt,os, result};
22
use std::collections::HashMap;
33
use serialize::{Encodable,Encoder};
44
use toml;
@@ -231,17 +231,15 @@ fn merge_array(existing: &mut ConfigValue, val: &[toml::Value],
231231
match existing.value {
232232
String(_) => Err(internal("should be an Array, but it was a String")),
233233
List(ref mut list) => {
234-
let new_list: Vec<CargoResult<String>> =
235-
val.iter().map(toml_string).collect();
236-
if new_list.iter().any(|v| v.is_err()) {
237-
return Err(internal("should be an Array of Strings, but \
238-
was an Array of other values"));
239-
} else {
240-
let new_list: Vec<String> =
241-
new_list.move_iter().map(|v| v.unwrap()).collect();
242-
list.push_all(new_list.as_slice());
243-
existing.path.push(path.clone());
244-
Ok(())
234+
let r: CargoResult<Vec<String>> = result::collect(val.iter().map(toml_string));
235+
match r {
236+
Err(_) => Err(internal("should be an Array of Strings, but \
237+
was an Array of other values")),
238+
Ok(new_list) => {
239+
list.push_all(new_list.as_slice());
240+
existing.path.push(path.clone());
241+
Ok(())
242+
}
245243
}
246244
}
247245
}

0 commit comments

Comments
 (0)