Use as_deref
in compiler (but only where it makes sense)
This commit is contained in:
parent
e702534763
commit
94470f4efd
27 changed files with 45 additions and 63 deletions
|
@ -304,7 +304,7 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
|
|||
parse_sess_created(&mut sess.parse_sess);
|
||||
}
|
||||
|
||||
let temps_dir = sess.opts.unstable_opts.temps_dir.as_ref().map(|o| PathBuf::from(&o));
|
||||
let temps_dir = sess.opts.unstable_opts.temps_dir.as_deref().map(PathBuf::from);
|
||||
|
||||
let compiler = Compiler {
|
||||
sess: Lrc::new(sess),
|
||||
|
|
|
@ -33,11 +33,7 @@ pub struct Query<T> {
|
|||
|
||||
impl<T> Query<T> {
|
||||
fn compute<F: FnOnce() -> Result<T>>(&self, f: F) -> Result<&Query<T>> {
|
||||
let mut result = self.result.borrow_mut();
|
||||
if result.is_none() {
|
||||
*result = Some(f());
|
||||
}
|
||||
result.as_ref().unwrap().as_ref().map(|_| self).map_err(|err| *err)
|
||||
self.result.borrow_mut().get_or_insert_with(f).as_ref().map(|_| self).map_err(|&err| err)
|
||||
}
|
||||
|
||||
/// Takes ownership of the query result. Further attempts to take or peek the query
|
||||
|
|
|
@ -68,10 +68,7 @@ pub fn create_session(
|
|||
let codegen_backend = if let Some(make_codegen_backend) = make_codegen_backend {
|
||||
make_codegen_backend(&sopts)
|
||||
} else {
|
||||
get_codegen_backend(
|
||||
&sopts.maybe_sysroot,
|
||||
sopts.unstable_opts.codegen_backend.as_ref().map(|name| &name[..]),
|
||||
)
|
||||
get_codegen_backend(&sopts.maybe_sysroot, sopts.unstable_opts.codegen_backend.as_deref())
|
||||
};
|
||||
|
||||
// target_override is documented to be called before init(), so this is okay
|
||||
|
@ -260,7 +257,7 @@ pub fn rustc_path<'a>() -> Option<&'a Path> {
|
|||
|
||||
const BIN_PATH: &str = env!("RUSTC_INSTALL_BINDIR");
|
||||
|
||||
RUSTC_PATH.get_or_init(|| get_rustc_path_inner(BIN_PATH)).as_ref().map(|v| &**v)
|
||||
RUSTC_PATH.get_or_init(|| get_rustc_path_inner(BIN_PATH)).as_deref()
|
||||
}
|
||||
|
||||
fn get_rustc_path_inner(bin_path: &str) -> Option<PathBuf> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue