From c60fc4bd581b955287c2f9e97e1d092fbdab58f1 Mon Sep 17 00:00:00 2001 From: Tobias Schaffner Date: Tue, 22 Aug 2017 11:11:30 +0200 Subject: Return L4Re TargetOptions as a Result type instead of panic If the environment variable L4RE_LIBDIR ist not set an Error will be returned wrapped in a result type instead of a panic. --- src/librustc_back/target/l4re_base.rs | 10 +++++----- src/librustc_back/target/x86_64_unknown_l4re_uclibc.rs | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/librustc_back/target/l4re_base.rs b/src/librustc_back/target/l4re_base.rs index b776c4bb568..31d428d2668 100644 --- a/src/librustc_back/target/l4re_base.rs +++ b/src/librustc_back/target/l4re_base.rs @@ -26,9 +26,9 @@ fn get_path_or(filename: &str) -> String { .expect("Couldn't read path from GCC").trim().into() } -pub fn opts() -> TargetOptions { - let l4re_lib_path = env::var_os("L4RE_LIBDIR").expect("Unable to find L4Re \ - library directory: L4RE_LIBDIR not set.").into_string().unwrap(); +pub fn opts() -> Result { + let l4re_lib_path = env::var_os("L4RE_LIBDIR").ok_or("Unable to find L4Re \ + library directory: L4RE_LIBDIR not set.")?.into_string().unwrap(); let mut pre_link_args = LinkArgs::new(); pre_link_args.insert(LinkerFlavor::Ld, vec![ format!("-T{}/main_stat.ld", l4re_lib_path), @@ -68,7 +68,7 @@ pub fn opts() -> TargetOptions { format!("{}/crtn.o", l4re_lib_path), ]); - TargetOptions { + Ok(TargetOptions { executables: true, has_elf_tls: false, exe_allocation_crate: None, @@ -78,5 +78,5 @@ pub fn opts() -> TargetOptions { post_link_args, target_family: Some("unix".to_string()), .. Default::default() - } + }) } diff --git a/src/librustc_back/target/x86_64_unknown_l4re_uclibc.rs b/src/librustc_back/target/x86_64_unknown_l4re_uclibc.rs index b447f8a989d..99d3171e1c0 100644 --- a/src/librustc_back/target/x86_64_unknown_l4re_uclibc.rs +++ b/src/librustc_back/target/x86_64_unknown_l4re_uclibc.rs @@ -12,7 +12,7 @@ use LinkerFlavor; use target::{Target, TargetResult}; pub fn target() -> TargetResult { - let mut base = super::l4re_base::opts(); + let mut base = super::l4re_base::opts()?; base.cpu = "x86-64".to_string(); base.max_atomic_width = Some(64); -- cgit 1.4.1-3-g733a5