Skip to content

Commit

Permalink
auto merge of rust-lang#78 : huonw/cargo/minor-de-.unwrapping, r=alex…
Browse files Browse the repository at this point in the history
…crichton

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.
  • Loading branch information
bors committed Jun 27, 2014
2 parents c993a54 + 3543133 commit de4a4bf
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
15 changes: 8 additions & 7 deletions src/bin/cargo-verify-project.rs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ fn main() {
}
};

if !matches.opt_present("m") {
fail("missing-argument", "manifest");
return;
}

let manifest = matches.opt_str("m").unwrap();
let manifest = match matches.opt_str("m") {
Some(m) => m,
None => {
fail("missing-argument", "manifest");
return;
}
};
let file = Path::new(manifest);
let contents = match File::open(&file).read_to_str() {
Ok(s) => s,
Expand All @@ -50,6 +51,6 @@ fn main() {
}

fn fail(reason: &str, value: &str) {
println!(r#"{{ "{:s}", "{:s}" }}"#, reason, value);
println!(r#"{{ "{:s}": "{:s}" }}"#, reason, value);
set_exit_status(1);
}
5 changes: 3 additions & 2 deletions src/cargo/core/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,13 @@ impl PackageSet {
}

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

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

pub fn get_all<'a>(&'a self, names: &[&str]) -> Vec<&'a Package> {
Expand Down
4 changes: 2 additions & 2 deletions src/cargo/ops/cargo_rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ fn compile_custom(pkg: &Package, cmd: &str, cx: &Context) -> CargoResult<()> {
let mut cmd = cmd.split(' ');
let mut p = util::process(cmd.next().unwrap())
.cwd(pkg.get_root())
.env("OUT_DIR", Some(cx.dest.as_str().unwrap()))
.env("OUT_DIR", Some(cx.dest.as_str().expect("non-UTF8 dest path")))
.env("DEPS_DIR", Some(cx.dest.join(cx.deps_dir)
.as_str().unwrap()));
.as_str().expect("non-UTF8 deps path")));
for arg in cmd {
p = p.arg(arg);
}
Expand Down
22 changes: 10 additions & 12 deletions src/cargo/util/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{io,fmt,os};
use std::{io,fmt,os, result};
use std::collections::HashMap;
use serialize::{Encodable,Encoder};
use toml;
Expand Down Expand Up @@ -231,17 +231,15 @@ fn merge_array(existing: &mut ConfigValue, val: &[toml::Value],
match existing.value {
String(_) => Err(internal("should be an Array, but it was a String")),
List(ref mut list) => {
let new_list: Vec<CargoResult<String>> =
val.iter().map(toml_string).collect();
if new_list.iter().any(|v| v.is_err()) {
return Err(internal("should be an Array of Strings, but \
was an Array of other values"));
} else {
let new_list: Vec<String> =
new_list.move_iter().map(|v| v.unwrap()).collect();
list.push_all(new_list.as_slice());
existing.path.push(path.clone());
Ok(())
let r: CargoResult<Vec<String>> = result::collect(val.iter().map(toml_string));
match r {
Err(_) => Err(internal("should be an Array of Strings, but \
was an Array of other values")),
Ok(new_list) => {
list.push_all(new_list.as_slice());
existing.path.push(path.clone());
Ok(())
}
}
}
}
Expand Down

0 comments on commit de4a4bf

Please sign in to comment.