Skip to content

Commit

Permalink
rustc/driver: unwrap_or_else with function calls
Browse files Browse the repository at this point in the history
  • Loading branch information
ljedrz committed Oct 13, 2018
1 parent c46c4d7 commit d838a7f
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/librustc_driver/driver.rs
Expand Up @@ -44,7 +44,7 @@ use serialize::json;

use std::any::Any;
use std::env;
use std::ffi::{OsStr, OsString};
use std::ffi::OsString;
use std::fs;
use std::io::{self, Write};
use std::iter;
Expand Down Expand Up @@ -1648,14 +1648,14 @@ pub fn build_output_filenames(
// "-" as input file will cause the parser to read from stdin so we
// have to make up a name
// We want to toss everything after the final '.'
let dirpath = (*odir).as_ref().cloned().unwrap_or_else(|| PathBuf::new());
let dirpath = (*odir).as_ref().cloned().unwrap_or_default();

// If a crate name is present, we use it as the link name
let stem = sess.opts
.crate_name
.clone()
.or_else(|| attr::find_crate_name(attrs).map(|n| n.to_string()))
.unwrap_or(input.filestem());
.unwrap_or_else(|| input.filestem());

OutputFilenames {
out_directory: dirpath,
Expand Down Expand Up @@ -1688,13 +1688,11 @@ pub fn build_output_filenames(
sess.warn("ignoring -C extra-filename flag due to -o flag");
}

let cur_dir = Path::new("");

OutputFilenames {
out_directory: out_file.parent().unwrap_or(cur_dir).to_path_buf(),
out_directory: out_file.parent().unwrap_or_else(|| Path::new("")).to_path_buf(),
out_filestem: out_file
.file_stem()
.unwrap_or(OsStr::new(""))
.unwrap_or_default()
.to_str()
.unwrap()
.to_string(),
Expand Down

0 comments on commit d838a7f

Please sign in to comment.