Avoid Lrc<Box<dyn CodegenBackend>>.

Because `Lrc<Box<T>>` is silly. (Clippy warns about `Rc<Box<T>>` and
`Arc<Box<T>>`, and it would warn here if (a) we used Clippy with rustc,
and (b) Clippy knew about `Lrc`.)
This commit is contained in:
Nicholas Nethercote 2023-06-22 09:18:09 +10:00
parent 006a26c0b5
commit 5dd7550a08
3 changed files with 8 additions and 8 deletions

View File

@ -329,7 +329,7 @@ fn run_compiler(
return; return;
} }
let should_stop = let should_stop =
print_crate_info(&***compiler.codegen_backend(), compiler.session(), false); print_crate_info(&**compiler.codegen_backend(), compiler.session(), false);
if should_stop == Compilation::Stop { if should_stop == Compilation::Stop {
return; return;
@ -351,7 +351,7 @@ fn run_compiler(
interface::run_compiler(config, |compiler| { interface::run_compiler(config, |compiler| {
let sess = compiler.session(); let sess = compiler.session();
let should_stop = print_crate_info(&***compiler.codegen_backend(), sess, true) let should_stop = print_crate_info(&**compiler.codegen_backend(), sess, true)
.and_then(|| list_metadata(sess, &*compiler.codegen_backend().metadata_loader())) .and_then(|| list_metadata(sess, &*compiler.codegen_backend().metadata_loader()))
.and_then(|| try_process_rlink(sess, compiler)); .and_then(|| try_process_rlink(sess, compiler));

View File

@ -36,7 +36,7 @@
/// Created by passing [`Config`] to [`run_compiler`]. /// Created by passing [`Config`] to [`run_compiler`].
pub struct Compiler { pub struct Compiler {
pub(crate) sess: Lrc<Session>, pub(crate) sess: Lrc<Session>,
codegen_backend: Lrc<Box<dyn CodegenBackend>>, codegen_backend: Lrc<dyn CodegenBackend>,
pub(crate) register_lints: Option<Box<dyn Fn(&Session, &mut LintStore) + Send + Sync>>, pub(crate) register_lints: Option<Box<dyn Fn(&Session, &mut LintStore) + Send + Sync>>,
pub(crate) override_queries: Option<fn(&Session, &mut Providers, &mut ExternProviders)>, pub(crate) override_queries: Option<fn(&Session, &mut Providers, &mut ExternProviders)>,
} }
@ -45,7 +45,7 @@ impl Compiler {
pub fn session(&self) -> &Lrc<Session> { pub fn session(&self) -> &Lrc<Session> {
&self.sess &self.sess
} }
pub fn codegen_backend(&self) -> &Lrc<Box<dyn CodegenBackend>> { pub fn codegen_backend(&self) -> &Lrc<dyn CodegenBackend> {
&self.codegen_backend &self.codegen_backend
} }
pub fn register_lints(&self) -> &Option<Box<dyn Fn(&Session, &mut LintStore) + Send + Sync>> { pub fn register_lints(&self) -> &Option<Box<dyn Fn(&Session, &mut LintStore) + Send + Sync>> {
@ -318,7 +318,7 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
let compiler = Compiler { let compiler = Compiler {
sess: Lrc::new(sess), sess: Lrc::new(sess),
codegen_backend: Lrc::new(codegen_backend), codegen_backend: Lrc::from(codegen_backend),
register_lints: config.register_lints, register_lints: config.register_lints,
override_queries: config.override_queries, override_queries: config.override_queries,
}; };

View File

@ -115,7 +115,7 @@ pub fn new(compiler: &'tcx Compiler) -> Queries<'tcx> {
fn session(&self) -> &Lrc<Session> { fn session(&self) -> &Lrc<Session> {
&self.compiler.sess &self.compiler.sess
} }
fn codegen_backend(&self) -> &Lrc<Box<dyn CodegenBackend>> { fn codegen_backend(&self) -> &Lrc<dyn CodegenBackend> {
self.compiler.codegen_backend() self.compiler.codegen_backend()
} }
@ -259,7 +259,7 @@ pub fn ongoing_codegen(&'tcx self) -> Result<Box<dyn Any>> {
// Hook for UI tests. // Hook for UI tests.
Self::check_for_rustc_errors_attr(tcx); Self::check_for_rustc_errors_attr(tcx);
Ok(passes::start_codegen(&***self.codegen_backend(), tcx)) Ok(passes::start_codegen(&**self.codegen_backend(), tcx))
}) })
} }
@ -324,7 +324,7 @@ pub fn linker(&'tcx self, ongoing_codegen: Box<dyn Any>) -> Result<Linker> {
pub struct Linker { pub struct Linker {
// compilation inputs // compilation inputs
sess: Lrc<Session>, sess: Lrc<Session>,
codegen_backend: Lrc<Box<dyn CodegenBackend>>, codegen_backend: Lrc<dyn CodegenBackend>,
// compilation outputs // compilation outputs
dep_graph: DepGraph, dep_graph: DepGraph,