Skip to content

Commit c60fc4b

Browse files
author
Tobias Schaffner
committed
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.
1 parent beedf4e commit c60fc4b

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

Diff for: src/librustc_back/target/l4re_base.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ fn get_path_or(filename: &str) -> String {
2626
.expect("Couldn't read path from GCC").trim().into()
2727
}
2828

29-
pub fn opts() -> TargetOptions {
30-
let l4re_lib_path = env::var_os("L4RE_LIBDIR").expect("Unable to find L4Re \
31-
library directory: L4RE_LIBDIR not set.").into_string().unwrap();
29+
pub fn opts() -> Result<TargetOptions, String> {
30+
let l4re_lib_path = env::var_os("L4RE_LIBDIR").ok_or("Unable to find L4Re \
31+
library directory: L4RE_LIBDIR not set.")?.into_string().unwrap();
3232
let mut pre_link_args = LinkArgs::new();
3333
pre_link_args.insert(LinkerFlavor::Ld, vec![
3434
format!("-T{}/main_stat.ld", l4re_lib_path),
@@ -68,7 +68,7 @@ pub fn opts() -> TargetOptions {
6868
format!("{}/crtn.o", l4re_lib_path),
6969
]);
7070

71-
TargetOptions {
71+
Ok(TargetOptions {
7272
executables: true,
7373
has_elf_tls: false,
7474
exe_allocation_crate: None,
@@ -78,5 +78,5 @@ pub fn opts() -> TargetOptions {
7878
post_link_args,
7979
target_family: Some("unix".to_string()),
8080
.. Default::default()
81-
}
81+
})
8282
}

Diff for: src/librustc_back/target/x86_64_unknown_l4re_uclibc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use LinkerFlavor;
1212
use target::{Target, TargetResult};
1313

1414
pub fn target() -> TargetResult {
15-
let mut base = super::l4re_base::opts();
15+
let mut base = super::l4re_base::opts()?;
1616
base.cpu = "x86-64".to_string();
1717
base.max_atomic_width = Some(64);
1818

0 commit comments

Comments
 (0)