Skip to content

Commit d838a7f

Browse files
committedOct 13, 2018
rustc/driver: unwrap_or_else with function calls
1 parent c46c4d7 commit d838a7f

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed
 

‎src/librustc_driver/driver.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use serialize::json;
4444

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

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

16601660
OutputFilenames {
16611661
out_directory: dirpath,
@@ -1688,13 +1688,11 @@ pub fn build_output_filenames(
16881688
sess.warn("ignoring -C extra-filename flag due to -o flag");
16891689
}
16901690

1691-
let cur_dir = Path::new("");
1692-
16931691
OutputFilenames {
1694-
out_directory: out_file.parent().unwrap_or(cur_dir).to_path_buf(),
1692+
out_directory: out_file.parent().unwrap_or_else(|| Path::new("")).to_path_buf(),
16951693
out_filestem: out_file
16961694
.file_stem()
1697-
.unwrap_or(OsStr::new(""))
1695+
.unwrap_or_default()
16981696
.to_str()
16991697
.unwrap()
17001698
.to_string(),

0 commit comments

Comments
 (0)