Skip to content

Commit

Permalink
Use to_option_with in several places
Browse files Browse the repository at this point in the history
  • Loading branch information
varkor committed Dec 6, 2019
1 parent e3a8ea4 commit 50985b0
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/back/rpath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ fn path_relative_from(path: &Path, base: &Path) -> Option<PathBuf> {
use std::path::Component;

if path.is_absolute() != base.is_absolute() {
path.is_absolute().to_option(PathBuf::from(path))
path.is_absolute().to_option_with(|| PathBuf::from(path))
} else {
let mut ita = path.components();
let mut itb = base.components();
Expand Down
11 changes: 7 additions & 4 deletions src/librustc_codegen_ssa/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,14 @@ impl<M> ModuleCodegen<M> {
emit_bc: bool,
emit_bc_compressed: bool,
outputs: &OutputFilenames) -> CompiledModule {
let object = emit_obj.to_option(outputs.temp_path(OutputType::Object, Some(&self.name)));
let bytecode = emit_bc.to_option(outputs.temp_path(OutputType::Bitcode, Some(&self.name)));
let bytecode_compressed = emit_bc_compressed.to_option(
let object = emit_obj
.to_option_with(|| outputs.temp_path(OutputType::Object, Some(&self.name)));
let bytecode = emit_bc
.to_option_with(|| outputs.temp_path(OutputType::Bitcode, Some(&self.name)));
let bytecode_compressed = emit_bc_compressed.to_option_with(|| {
outputs.temp_path(OutputType::Bitcode, Some(&self.name))
.with_extension(RLIB_BYTECODE_EXTENSION));
.with_extension(RLIB_BYTECODE_EXTENSION)
});

CompiledModule {
name: self.name.clone(),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_interface/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ fn output_contains_path(output_paths: &[PathBuf], input_path: &PathBuf) -> bool
}

fn output_conflicts_with_dir(output_paths: &[PathBuf]) -> Option<PathBuf> {
let check = |output_path: &PathBuf| output_path.is_dir().to_option(output_path.clone());
let check = |output_path: &PathBuf| output_path.is_dir().to_option_with(|| output_path.clone());
check_output(output_paths, check)
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_session/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ impl Session {
}

pub fn incr_comp_session_dir_opt(&self) -> Option<cell::Ref<'_, PathBuf>> {
self.opts.incremental.is_some().to_option(self.incr_comp_session_dir())
self.opts.incremental.is_some().to_option_with(|| self.incr_comp_session_dir())
}

pub fn print_perf_stats(&self) {
Expand Down

0 comments on commit 50985b0

Please sign in to comment.