mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 08:44:35 +00:00
Replace a few expect+format combos with unwrap_or_else+panic
This commit is contained in:
parent
210d61f05c
commit
fe588d894f
@ -326,7 +326,7 @@ fn main() {
|
|||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
let status = cmd
|
let status = cmd
|
||||||
.status()
|
.status()
|
||||||
.expect(&format!("\n\n failed to run {:?}", cmd));
|
.unwrap_or_else(|_| panic!("\n\n failed to run {:?}", cmd));
|
||||||
let dur = start.elapsed();
|
let dur = start.elapsed();
|
||||||
|
|
||||||
let is_test = args.iter().any(|a| a == "--test");
|
let is_test = args.iter().any(|a| a == "--test");
|
||||||
@ -346,7 +346,7 @@ fn main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let code = exec_cmd(&mut cmd).expect(&format!("\n\n failed to run {:?}", cmd));
|
let code = exec_cmd(&mut cmd).unwrap_or_else(|_| panic!("\n\n failed to run {:?}", cmd));
|
||||||
std::process::exit(code);
|
std::process::exit(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ fn install_sh(
|
|||||||
let libdir_default = PathBuf::from("lib");
|
let libdir_default = PathBuf::from("lib");
|
||||||
let mandir_default = datadir_default.join("man");
|
let mandir_default = datadir_default.join("man");
|
||||||
let prefix = builder.config.prefix.as_ref().map_or(prefix_default, |p| {
|
let prefix = builder.config.prefix.as_ref().map_or(prefix_default, |p| {
|
||||||
fs::canonicalize(p).expect(&format!("could not canonicalize {}", p.display()))
|
fs::canonicalize(p).unwrap_or_else(|_| panic!("could not canonicalize {}", p.display()))
|
||||||
});
|
});
|
||||||
let sysconfdir = builder.config.sysconfdir.as_ref().unwrap_or(&sysconfdir_default);
|
let sysconfdir = builder.config.sysconfdir.as_ref().unwrap_or(&sysconfdir_default);
|
||||||
let datadir = builder.config.datadir.as_ref().unwrap_or(&datadir_default);
|
let datadir = builder.config.datadir.as_ref().unwrap_or(&datadir_default);
|
||||||
|
@ -114,8 +114,8 @@ fn get_rpath_relative_to_output(config: &mut RPathConfig, lib: &Path) -> String
|
|||||||
let mut output = cwd.join(&config.out_filename);
|
let mut output = cwd.join(&config.out_filename);
|
||||||
output.pop();
|
output.pop();
|
||||||
let output = fs::canonicalize(&output).unwrap_or(output);
|
let output = fs::canonicalize(&output).unwrap_or(output);
|
||||||
let relative = path_relative_from(&lib, &output)
|
let relative = path_relative_from(&lib, &output).unwrap_or_else(||
|
||||||
.expect(&format!("couldn't create relative path from {:?} to {:?}", output, lib));
|
panic!("couldn't create relative path from {:?} to {:?}", output, lib));
|
||||||
// FIXME (#9639): This needs to handle non-utf8 paths
|
// FIXME (#9639): This needs to handle non-utf8 paths
|
||||||
format!("{}/{}", prefix,
|
format!("{}/{}", prefix,
|
||||||
relative.to_str().expect("non-utf8 component in path"))
|
relative.to_str().expect("non-utf8 component in path"))
|
||||||
|
@ -1277,7 +1277,7 @@ pub fn provide(providers: &mut Providers) {
|
|||||||
all.iter()
|
all.iter()
|
||||||
.find(|cgu| *cgu.name() == name)
|
.find(|cgu| *cgu.name() == name)
|
||||||
.cloned()
|
.cloned()
|
||||||
.expect(&format!("failed to find cgu with name {:?}", name))
|
.unwrap_or_else(|| panic!("failed to find cgu with name {:?}", name))
|
||||||
};
|
};
|
||||||
providers.compile_codegen_unit = compile_codegen_unit;
|
providers.compile_codegen_unit = compile_codegen_unit;
|
||||||
|
|
||||||
|
@ -232,11 +232,11 @@ pub mod printf {
|
|||||||
impl Num {
|
impl Num {
|
||||||
fn from_str(s: &str, arg: Option<&str>) -> Self {
|
fn from_str(s: &str, arg: Option<&str>) -> Self {
|
||||||
if let Some(arg) = arg {
|
if let Some(arg) = arg {
|
||||||
Num::Arg(arg.parse().expect(&format!("invalid format arg `{:?}`", arg)))
|
Num::Arg(arg.parse().unwrap_or_else(|_| panic!("invalid format arg `{:?}`", arg)))
|
||||||
} else if s == "*" {
|
} else if s == "*" {
|
||||||
Num::Next
|
Num::Next
|
||||||
} else {
|
} else {
|
||||||
Num::Num(s.parse().expect(&format!("invalid format num `{:?}`", s)))
|
Num::Num(s.parse().unwrap_or_else(|_| panic!("invalid format num `{:?}`", s)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user