Skip to content

Commit

Permalink
Remove try! in favor of ?
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiram van Paassen authored and hmvp committed Jun 15, 2019
1 parent 5cf3f1e commit 91d6e95
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl<'a> Builder<'a> {
.and_then(OsStr::to_str)
.map(ToString::to_string)
}
Ok(try!(fs::read_dir(&dir_path))
Ok(fs::read_dir(&dir_path)?
.filter_map(Result::ok)
.filter(is_mod)
.filter(|e| !ignored_paths.contains(&e.path()))
Expand Down
18 changes: 8 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fn choose_target<'a>(args: &Arguments, manifest: &'a Manifest) -> Result<&'a Tar
fn run(args: &Arguments) -> Result<(), Error> {
let manifest: Manifest = {
let output = process::Command::new("cargo").arg("read-manifest").output();
let stdout = try!(output.map_err(Error::CargoExecutionFailed)).stdout;
let stdout = output.map_err(Error::CargoExecutionFailed)?.stdout;
let json_string = String::from_utf8(stdout).expect("Failed reading cargo output");
Manifest::from_str(&json_string)?
};
Expand All @@ -92,15 +92,13 @@ fn run(args: &Arguments) -> Result<(), Error> {
let parse_session = ParseSess::new(source_map::FilePathMapping::empty());

syntax::with_globals(|| {
let krate = try!(match parse::parse_crate_from_file(
target.src_path().as_ref(),
&parse_session
) {
Ok(_) if parse_session.span_diagnostic.has_errors() => Err(None),
Ok(krate) => Ok(krate),
Err(e) => Err(Some(e)),
}
.map_err(|e| Error::Syntax(format!("{:?}", e))));
let krate =
match parse::parse_crate_from_file(target.src_path().as_ref(), &parse_session) {
Ok(_) if parse_session.span_diagnostic.has_errors() => Err(None),
Ok(krate) => Ok(krate),
Err(e) => Err(Some(e)),
}
.map_err(|e| Error::Syntax(format!("{:?}", e)))?;

let builder_config = BuilderConfig {
include_orphans: args.orphans,
Expand Down

0 comments on commit 91d6e95

Please sign in to comment.