Rollup merge of #125953 - nnethercote:streamline-nested-calls, r=lqd

Streamline `nested` calls.

`TyCtxt` impls `PpAnn` in `compiler/rustc_middle/src/hir/map/mod.rs`. We can call that impl, which then calls the one on `intravisit::Map`, instead of calling the one on `intravisit::Map` directly, avoiding a cast and extra references.

r? `@lqd`
This commit is contained in:
Michael Goulet 2024-06-04 08:52:14 -04:00 committed by GitHub
commit 23f39a21db
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -3,7 +3,6 @@
use rustc_ast as ast; use rustc_ast as ast;
use rustc_ast_pretty::pprust as pprust_ast; use rustc_ast_pretty::pprust as pprust_ast;
use rustc_errors::FatalError; use rustc_errors::FatalError;
use rustc_hir as hir;
use rustc_hir_pretty as pprust_hir; use rustc_hir_pretty as pprust_hir;
use rustc_middle::bug; use rustc_middle::bug;
use rustc_middle::mir::{write_mir_graphviz, write_mir_pretty}; use rustc_middle::mir::{write_mir_graphviz, write_mir_pretty};
@ -70,11 +69,7 @@ struct HirIdentifiedAnn<'tcx> {
impl<'tcx> pprust_hir::PpAnn for HirIdentifiedAnn<'tcx> { impl<'tcx> pprust_hir::PpAnn for HirIdentifiedAnn<'tcx> {
fn nested(&self, state: &mut pprust_hir::State<'_>, nested: pprust_hir::Nested) { fn nested(&self, state: &mut pprust_hir::State<'_>, nested: pprust_hir::Nested) {
pprust_hir::PpAnn::nested( self.tcx.nested(state, nested)
&(&self.tcx.hir() as &dyn hir::intravisit::Map<'_>),
state,
nested,
)
} }
fn pre(&self, s: &mut pprust_hir::State<'_>, node: pprust_hir::AnnNode<'_>) { fn pre(&self, s: &mut pprust_hir::State<'_>, node: pprust_hir::AnnNode<'_>) {
@ -152,8 +147,7 @@ fn nested(&self, state: &mut pprust_hir::State<'_>, nested: pprust_hir::Nested)
if let pprust_hir::Nested::Body(id) = nested { if let pprust_hir::Nested::Body(id) = nested {
self.maybe_typeck_results.set(Some(self.tcx.typeck_body(id))); self.maybe_typeck_results.set(Some(self.tcx.typeck_body(id)));
} }
let pp_ann = &(&self.tcx.hir() as &dyn hir::intravisit::Map<'_>); self.tcx.nested(state, nested);
pprust_hir::PpAnn::nested(pp_ann, state, nested);
self.maybe_typeck_results.set(old_maybe_typeck_results); self.maybe_typeck_results.set(old_maybe_typeck_results);
} }