From e3a8ea4e18a50da60036d2731768a9cb78c90f5a Mon Sep 17 00:00:00 2001 From: varkor Date: Tue, 8 Oct 2019 01:14:42 +0100 Subject: Use `to_option` in various places --- src/librustc_codegen_ssa/back/rpath.rs | 6 +----- src/librustc_codegen_ssa/back/symbol_export.rs | 6 +----- src/librustc_codegen_ssa/lib.rs | 22 ++++++---------------- 3 files changed, 8 insertions(+), 26 deletions(-) (limited to 'src/librustc_codegen_ssa') diff --git a/src/librustc_codegen_ssa/back/rpath.rs b/src/librustc_codegen_ssa/back/rpath.rs index e27cb6d8dda..b932a202093 100644 --- a/src/librustc_codegen_ssa/back/rpath.rs +++ b/src/librustc_codegen_ssa/back/rpath.rs @@ -119,11 +119,7 @@ fn path_relative_from(path: &Path, base: &Path) -> Option { use std::path::Component; if path.is_absolute() != base.is_absolute() { - if path.is_absolute() { - Some(PathBuf::from(path)) - } else { - None - } + path.is_absolute().to_option(PathBuf::from(path)) } else { let mut ita = path.components(); let mut itb = base.components(); diff --git a/src/librustc_codegen_ssa/back/symbol_export.rs b/src/librustc_codegen_ssa/back/symbol_export.rs index f8b3e0ffe5c..00519814071 100644 --- a/src/librustc_codegen_ssa/back/symbol_export.rs +++ b/src/librustc_codegen_ssa/back/symbol_export.rs @@ -85,11 +85,7 @@ fn reachable_non_generics_provider( match tcx.hir().get(hir_id) { Node::ForeignItem(..) => { let def_id = tcx.hir().local_def_id(hir_id); - if tcx.is_statically_included_foreign_item(def_id) { - Some(def_id) - } else { - None - } + tcx.is_statically_included_foreign_item(def_id).to_option(def_id) } // Only consider nodes that actually have exported symbols. diff --git a/src/librustc_codegen_ssa/lib.rs b/src/librustc_codegen_ssa/lib.rs index 9784d870b31..ebddff2af6e 100644 --- a/src/librustc_codegen_ssa/lib.rs +++ b/src/librustc_codegen_ssa/lib.rs @@ -1,5 +1,6 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/")] +#![feature(bool_to_option)] #![feature(box_patterns)] #![feature(box_syntax)] #![feature(core_intrinsics)] @@ -68,22 +69,11 @@ impl ModuleCodegen { emit_bc: bool, emit_bc_compressed: bool, outputs: &OutputFilenames) -> CompiledModule { - let object = if emit_obj { - Some(outputs.temp_path(OutputType::Object, Some(&self.name))) - } else { - None - }; - let bytecode = if emit_bc { - Some(outputs.temp_path(OutputType::Bitcode, Some(&self.name))) - } else { - None - }; - let bytecode_compressed = if emit_bc_compressed { - Some(outputs.temp_path(OutputType::Bitcode, Some(&self.name)) - .with_extension(RLIB_BYTECODE_EXTENSION)) - } else { - None - }; + 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( + outputs.temp_path(OutputType::Bitcode, Some(&self.name)) + .with_extension(RLIB_BYTECODE_EXTENSION)); CompiledModule { name: self.name.clone(), -- cgit 1.4.1-3-g733a5