Skip to content

Commit fe588d8

Browse files
committedJul 23, 2018
Replace a few expect+format combos with unwrap_or_else+panic
1 parent 210d61f commit fe588d8

File tree

5 files changed

+8
-8
lines changed

5 files changed

+8
-8
lines changed
 

‎src/bootstrap/bin/rustc.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ fn main() {
326326
let start = Instant::now();
327327
let status = cmd
328328
.status()
329-
.expect(&format!("\n\n failed to run {:?}", cmd));
329+
.unwrap_or_else(|_| panic!("\n\n failed to run {:?}", cmd));
330330
let dur = start.elapsed();
331331

332332
let is_test = args.iter().any(|a| a == "--test");
@@ -346,7 +346,7 @@ fn main() {
346346
}
347347
}
348348

349-
let code = exec_cmd(&mut cmd).expect(&format!("\n\n failed to run {:?}", cmd));
349+
let code = exec_cmd(&mut cmd).unwrap_or_else(|_| panic!("\n\n failed to run {:?}", cmd));
350350
std::process::exit(code);
351351
}
352352

‎src/bootstrap/install.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ fn install_sh(
7575
let libdir_default = PathBuf::from("lib");
7676
let mandir_default = datadir_default.join("man");
7777
let prefix = builder.config.prefix.as_ref().map_or(prefix_default, |p| {
78-
fs::canonicalize(p).expect(&format!("could not canonicalize {}", p.display()))
78+
fs::canonicalize(p).unwrap_or_else(|_| panic!("could not canonicalize {}", p.display()))
7979
});
8080
let sysconfdir = builder.config.sysconfdir.as_ref().unwrap_or(&sysconfdir_default);
8181
let datadir = builder.config.datadir.as_ref().unwrap_or(&datadir_default);

‎src/librustc_codegen_llvm/back/rpath.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ fn get_rpath_relative_to_output(config: &mut RPathConfig, lib: &Path) -> String
114114
let mut output = cwd.join(&config.out_filename);
115115
output.pop();
116116
let output = fs::canonicalize(&output).unwrap_or(output);
117-
let relative = path_relative_from(&lib, &output)
118-
.expect(&format!("couldn't create relative path from {:?} to {:?}", output, lib));
117+
let relative = path_relative_from(&lib, &output).unwrap_or_else(||
118+
panic!("couldn't create relative path from {:?} to {:?}", output, lib));
119119
// FIXME (#9639): This needs to handle non-utf8 paths
120120
format!("{}/{}", prefix,
121121
relative.to_str().expect("non-utf8 component in path"))

‎src/librustc_codegen_llvm/base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1277,7 +1277,7 @@ pub fn provide(providers: &mut Providers) {
12771277
all.iter()
12781278
.find(|cgu| *cgu.name() == name)
12791279
.cloned()
1280-
.expect(&format!("failed to find cgu with name {:?}", name))
1280+
.unwrap_or_else(|| panic!("failed to find cgu with name {:?}", name))
12811281
};
12821282
providers.compile_codegen_unit = compile_codegen_unit;
12831283

‎src/libsyntax_ext/format_foreign.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,11 @@ pub mod printf {
232232
impl Num {
233233
fn from_str(s: &str, arg: Option<&str>) -> Self {
234234
if let Some(arg) = arg {
235-
Num::Arg(arg.parse().expect(&format!("invalid format arg `{:?}`", arg)))
235+
Num::Arg(arg.parse().unwrap_or_else(|_| panic!("invalid format arg `{:?}`", arg)))
236236
} else if s == "*" {
237237
Num::Next
238238
} else {
239-
Num::Num(s.parse().expect(&format!("invalid format num `{:?}`", s)))
239+
Num::Num(s.parse().unwrap_or_else(|_| panic!("invalid format num `{:?}`", s)))
240240
}
241241
}
242242

0 commit comments

Comments
 (0)