1
Fork 0

Rollup merge of #136466 - nnethercote:start-removing-Map, r=cjgillot

Start removing `rustc_middle::hir::map::Map`

`rustc_middle::hir::map::Map` is now just a low-value wrapper around `TyCtxt`. This PR starts removing it.

r? `@cjgillot`
This commit is contained in:
Matthias Krüger 2025-02-17 06:37:35 +01:00 committed by GitHub
commit f3a4f1a02a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
224 changed files with 673 additions and 700 deletions

View file

@ -407,7 +407,7 @@ fn compute_hir_hash(
.iter_enumerated() .iter_enumerated()
.filter_map(|(def_id, info)| { .filter_map(|(def_id, info)| {
let info = info.as_owner()?; let info = info.as_owner()?;
let def_path_hash = tcx.hir().def_path_hash(def_id); let def_path_hash = tcx.hir_def_path_hash(def_id);
Some((def_path_hash, info)) Some((def_path_hash, info))
}) })
.collect(); .collect();
@ -497,7 +497,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
"adding a def'n for node-id {:?} and def kind {:?} but a previous def'n exists: {:?}", "adding a def'n for node-id {:?} and def kind {:?} but a previous def'n exists: {:?}",
node_id, node_id,
def_kind, def_kind,
self.tcx.hir().def_key(self.local_def_id(node_id)), self.tcx.hir_def_key(self.local_def_id(node_id)),
); );
let def_id = self.tcx.at(span).create_def(parent, name, def_kind).def_id(); let def_id = self.tcx.at(span).create_def(parent, name, def_kind).def_id();

View file

@ -14,7 +14,7 @@ use rustc_errors::codes::*;
use rustc_errors::{Applicability, Diag, MultiSpan, struct_span_code_err}; use rustc_errors::{Applicability, Diag, MultiSpan, struct_span_code_err};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res}; use rustc_hir::def::{DefKind, Res};
use rustc_hir::intravisit::{Map, Visitor, walk_block, walk_expr}; use rustc_hir::intravisit::{Visitor, walk_block, walk_expr};
use rustc_hir::{CoroutineDesugaring, CoroutineKind, CoroutineSource, LangItem, PatField}; use rustc_hir::{CoroutineDesugaring, CoroutineKind, CoroutineSource, LangItem, PatField};
use rustc_middle::bug; use rustc_middle::bug;
use rustc_middle::hir::nested_filter::OnlyBodies; use rustc_middle::hir::nested_filter::OnlyBodies;
@ -348,13 +348,13 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
expr: Option<&'hir hir::Expr<'hir>>, expr: Option<&'hir hir::Expr<'hir>>,
pat: Option<&'hir hir::Pat<'hir>>, pat: Option<&'hir hir::Pat<'hir>>,
parent_pat: Option<&'hir hir::Pat<'hir>>, parent_pat: Option<&'hir hir::Pat<'hir>>,
hir: rustc_middle::hir::map::Map<'hir>, tcx: TyCtxt<'hir>,
} }
impl<'hir> Visitor<'hir> for ExpressionFinder<'hir> { impl<'hir> Visitor<'hir> for ExpressionFinder<'hir> {
type NestedFilter = OnlyBodies; type NestedFilter = OnlyBodies;
fn nested_visit_map(&mut self) -> Self::Map { fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
self.hir self.tcx
} }
fn visit_expr(&mut self, e: &'hir hir::Expr<'hir>) { fn visit_expr(&mut self, e: &'hir hir::Expr<'hir>) {
@ -396,7 +396,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
expr: None, expr: None,
pat: None, pat: None,
parent_pat: None, parent_pat: None,
hir, tcx: self.infcx.tcx,
}; };
finder.visit_expr(expr); finder.visit_expr(expr);
if let Some(span) = span if let Some(span) = span
@ -1082,7 +1082,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
] { ] {
for (destination, sp) in elements { for (destination, sp) in elements {
if let Ok(hir_id) = destination.target_id if let Ok(hir_id) = destination.target_id
&& let hir::Node::Expr(expr) = tcx.hir().hir_node(hir_id) && let hir::Node::Expr(expr) = tcx.hir_node(hir_id)
&& !matches!( && !matches!(
sp.desugaring_kind(), sp.desugaring_kind(),
Some(DesugaringKind::ForLoop | DesugaringKind::WhileLoop) Some(DesugaringKind::ForLoop | DesugaringKind::WhileLoop)
@ -1437,7 +1437,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
let Some(hir_generics) = tcx let Some(hir_generics) = tcx
.typeck_root_def_id(self.mir_def_id().to_def_id()) .typeck_root_def_id(self.mir_def_id().to_def_id())
.as_local() .as_local()
.and_then(|def_id| tcx.hir().get_generics(def_id)) .and_then(|def_id| tcx.hir_get_generics(def_id))
else { else {
return; return;
}; };
@ -1889,7 +1889,6 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
fn suggest_copy_for_type_in_cloned_ref(&self, err: &mut Diag<'infcx>, place: Place<'tcx>) { fn suggest_copy_for_type_in_cloned_ref(&self, err: &mut Diag<'infcx>, place: Place<'tcx>) {
let tcx = self.infcx.tcx; let tcx = self.infcx.tcx;
let hir = tcx.hir();
let Some(body_id) = tcx.hir_node(self.mir_hir_id()).body_id() else { return }; let Some(body_id) = tcx.hir_node(self.mir_hir_id()).body_id() else { return };
struct FindUselessClone<'tcx> { struct FindUselessClone<'tcx> {
@ -1917,7 +1916,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
let mut expr_finder = FindUselessClone::new(tcx, self.mir_def_id()); let mut expr_finder = FindUselessClone::new(tcx, self.mir_def_id());
let body = hir.body(body_id).value; let body = tcx.hir_body(body_id).value;
expr_finder.visit_expr(body); expr_finder.visit_expr(body);
struct Holds<'tcx> { struct Holds<'tcx> {
@ -2106,7 +2105,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
let tcx = self.infcx.tcx; let tcx = self.infcx.tcx;
let body_id = tcx.hir_node(self.mir_hir_id()).body_id()?; let body_id = tcx.hir_node(self.mir_hir_id()).body_id()?;
let mut expr_finder = FindExprBySpan::new(span, tcx); let mut expr_finder = FindExprBySpan::new(span, tcx);
expr_finder.visit_expr(tcx.hir().body(body_id).value); expr_finder.visit_expr(tcx.hir_body(body_id).value);
expr_finder.result expr_finder.result
} }
@ -2258,7 +2257,6 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
) { ) {
let issue_span = issued_spans.args_or_use(); let issue_span = issued_spans.args_or_use();
let tcx = self.infcx.tcx; let tcx = self.infcx.tcx;
let hir = tcx.hir();
let Some(body_id) = tcx.hir_node(self.mir_hir_id()).body_id() else { return }; let Some(body_id) = tcx.hir_node(self.mir_hir_id()).body_id() else { return };
let typeck_results = tcx.typeck(self.mir_def_id()); let typeck_results = tcx.typeck(self.mir_def_id());
@ -2346,7 +2344,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
pat_span: None, pat_span: None,
head: None, head: None,
}; };
finder.visit_expr(hir.body(body_id).value); finder.visit_expr(tcx.hir_body(body_id).value);
if let Some(body_expr) = finder.body_expr if let Some(body_expr) = finder.body_expr
&& let Some(loop_span) = finder.loop_span && let Some(loop_span) = finder.loop_span
@ -2454,10 +2452,10 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
// Get the body the error happens in // Get the body the error happens in
let Some(body_id) = tcx.hir_node(self.mir_hir_id()).body_id() else { return }; let Some(body_id) = tcx.hir_node(self.mir_hir_id()).body_id() else { return };
let body_expr = hir.body(body_id).value; let body_expr = tcx.hir_body(body_id).value;
struct ClosureFinder<'hir> { struct ClosureFinder<'hir> {
hir: rustc_middle::hir::map::Map<'hir>, tcx: TyCtxt<'hir>,
borrow_span: Span, borrow_span: Span,
res: Option<(&'hir hir::Expr<'hir>, &'hir hir::Closure<'hir>)>, res: Option<(&'hir hir::Expr<'hir>, &'hir hir::Closure<'hir>)>,
/// The path expression with the `borrow_span` span /// The path expression with the `borrow_span` span
@ -2466,8 +2464,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
impl<'hir> Visitor<'hir> for ClosureFinder<'hir> { impl<'hir> Visitor<'hir> for ClosureFinder<'hir> {
type NestedFilter = OnlyBodies; type NestedFilter = OnlyBodies;
fn nested_visit_map(&mut self) -> Self::Map { fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
self.hir self.tcx
} }
fn visit_expr(&mut self, ex: &'hir hir::Expr<'hir>) { fn visit_expr(&mut self, ex: &'hir hir::Expr<'hir>) {
@ -2493,7 +2491,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
// Find the closure that most tightly wraps `capture_kind_span` // Find the closure that most tightly wraps `capture_kind_span`
let mut finder = let mut finder =
ClosureFinder { hir, borrow_span: capture_kind_span, res: None, error_path: None }; ClosureFinder { tcx, borrow_span: capture_kind_span, res: None, error_path: None };
finder.visit_expr(body_expr); finder.visit_expr(body_expr);
let Some((closure_expr, closure)) = finder.res else { return }; let Some((closure_expr, closure)) = finder.res else { return };
@ -2558,7 +2556,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
} }
let mut finder = VariableUseFinder { local_id, spans: Vec::new() }; let mut finder = VariableUseFinder { local_id, spans: Vec::new() };
finder.visit_expr(hir.body(closure.body).value); finder.visit_expr(tcx.hir_body(closure.body).value);
spans = finder.spans; spans = finder.spans;
} else { } else {
@ -3211,7 +3209,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
if let Some(scope) = self.body.source_scopes.get(source_info.scope) if let Some(scope) = self.body.source_scopes.get(source_info.scope)
&& let ClearCrossCrate::Set(scope_data) = &scope.local_data && let ClearCrossCrate::Set(scope_data) = &scope.local_data
&& let Some(id) = self.infcx.tcx.hir_node(scope_data.lint_root).body_id() && let Some(id) = self.infcx.tcx.hir_node(scope_data.lint_root).body_id()
&& let hir::ExprKind::Block(block, _) = self.infcx.tcx.hir().body(id).value.kind && let hir::ExprKind::Block(block, _) = self.infcx.tcx.hir_body(id).value.kind
{ {
for stmt in block.stmts { for stmt in block.stmts {
let mut visitor = NestedStatementVisitor { let mut visitor = NestedStatementVisitor {

View file

@ -75,10 +75,10 @@ impl<'tcx> BorrowExplanation<'tcx> {
if let Some(span) = borrow_span { if let Some(span) = borrow_span {
let def_id = body.source.def_id(); let def_id = body.source.def_id();
if let Some(node) = tcx.hir().get_if_local(def_id) if let Some(node) = tcx.hir_get_if_local(def_id)
&& let Some(body_id) = node.body_id() && let Some(body_id) = node.body_id()
{ {
let body = tcx.hir().body(body_id); let body = tcx.hir_body(body_id);
let mut expr_finder = FindExprBySpan::new(span, tcx); let mut expr_finder = FindExprBySpan::new(span, tcx);
expr_finder.visit_expr(body.value); expr_finder.visit_expr(body.value);
if let Some(mut expr) = expr_finder.result { if let Some(mut expr) = expr_finder.result {
@ -256,8 +256,8 @@ impl<'tcx> BorrowExplanation<'tcx> {
impl<'hir> rustc_hir::intravisit::Visitor<'hir> for FindLetExpr<'hir> { impl<'hir> rustc_hir::intravisit::Visitor<'hir> for FindLetExpr<'hir> {
type NestedFilter = rustc_middle::hir::nested_filter::OnlyBodies; type NestedFilter = rustc_middle::hir::nested_filter::OnlyBodies;
fn nested_visit_map(&mut self) -> Self::Map { fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
self.tcx.hir() self.tcx
} }
fn visit_expr(&mut self, expr: &'hir hir::Expr<'hir>) { fn visit_expr(&mut self, expr: &'hir hir::Expr<'hir>) {
if let hir::ExprKind::If(cond, _conseq, _alt) if let hir::ExprKind::If(cond, _conseq, _alt)
@ -308,9 +308,9 @@ impl<'tcx> BorrowExplanation<'tcx> {
suggest_rewrite_if_let(tcx, expr, &pat, init, conseq, alt, err); suggest_rewrite_if_let(tcx, expr, &pat, init, conseq, alt, err);
} else if let Some((old, new)) = multiple_borrow_span } else if let Some((old, new)) = multiple_borrow_span
&& let def_id = body.source.def_id() && let def_id = body.source.def_id()
&& let Some(node) = tcx.hir().get_if_local(def_id) && let Some(node) = tcx.hir_get_if_local(def_id)
&& let Some(body_id) = node.body_id() && let Some(body_id) = node.body_id()
&& let hir_body = tcx.hir().body(body_id) && let hir_body = tcx.hir_body(body_id)
&& let mut expr_finder = (FindLetExpr { span: old, result: None, tcx }) && let mut expr_finder = (FindLetExpr { span: old, result: None, tcx })
&& let Some((let_expr_span, let_expr_pat, let_expr_init)) = { && let Some((let_expr_span, let_expr_pat, let_expr_init)) = {
expr_finder.visit_expr(hir_body.value); expr_finder.visit_expr(hir_body.value);

View file

@ -1220,7 +1220,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
.tcx .tcx
.typeck_root_def_id(self.mir_def_id().to_def_id()) .typeck_root_def_id(self.mir_def_id().to_def_id())
.as_local() .as_local()
.and_then(|def_id| self.infcx.tcx.hir().get_generics(def_id)) .and_then(|def_id| self.infcx.tcx.hir_get_generics(def_id))
&& let spans = hir_generics && let spans = hir_generics
.predicates .predicates
.iter() .iter()

View file

@ -7,7 +7,7 @@ use rustc_hir::intravisit::Visitor;
use rustc_hir::{self as hir, CaptureBy, ExprKind, HirId, Node}; use rustc_hir::{self as hir, CaptureBy, ExprKind, HirId, Node};
use rustc_middle::bug; use rustc_middle::bug;
use rustc_middle::mir::*; use rustc_middle::mir::*;
use rustc_middle::ty::{self, Ty}; use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_mir_dataflow::move_paths::{LookupResult, MovePathIndex}; use rustc_mir_dataflow::move_paths::{LookupResult, MovePathIndex};
use rustc_span::{BytePos, ExpnKind, MacroKind, Span}; use rustc_span::{BytePos, ExpnKind, MacroKind, Span};
use rustc_trait_selection::error_reporting::traits::FindExprBySpan; use rustc_trait_selection::error_reporting::traits::FindExprBySpan;
@ -347,7 +347,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
// Find the closure that captured the binding. // Find the closure that captured the binding.
let mut expr_finder = FindExprBySpan::new(args_span, tcx); let mut expr_finder = FindExprBySpan::new(args_span, tcx);
expr_finder.include_closures = true; expr_finder.include_closures = true;
expr_finder.visit_expr(tcx.hir().body(body_id).value); expr_finder.visit_expr(tcx.hir_body(body_id).value);
let Some(closure_expr) = expr_finder.result else { return }; let Some(closure_expr) = expr_finder.result else { return };
let ExprKind::Closure(closure) = closure_expr.kind else { return }; let ExprKind::Closure(closure) = closure_expr.kind else { return };
// We'll only suggest cloning the binding if it's a `move` closure. // We'll only suggest cloning the binding if it's a `move` closure.
@ -357,7 +357,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
let use_span = use_spans.var_or_use(); let use_span = use_spans.var_or_use();
let mut expr_finder = FindExprBySpan::new(use_span, tcx); let mut expr_finder = FindExprBySpan::new(use_span, tcx);
expr_finder.include_closures = true; expr_finder.include_closures = true;
expr_finder.visit_expr(tcx.hir().body(body_id).value); expr_finder.visit_expr(tcx.hir_body(body_id).value);
let Some(use_expr) = expr_finder.result else { return }; let Some(use_expr) = expr_finder.result else { return };
let parent = tcx.parent_hir_node(use_expr.hir_id); let parent = tcx.parent_hir_node(use_expr.hir_id);
if let Node::Expr(expr) = parent if let Node::Expr(expr) = parent
@ -690,7 +690,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
/// make it bind by reference instead (if possible) /// make it bind by reference instead (if possible)
struct BindingFinder<'tcx> { struct BindingFinder<'tcx> {
typeck_results: &'tcx ty::TypeckResults<'tcx>, typeck_results: &'tcx ty::TypeckResults<'tcx>,
hir: rustc_middle::hir::map::Map<'tcx>, tcx: TyCtxt<'tcx>,
/// Input: the span of the pattern we're finding bindings in /// Input: the span of the pattern we're finding bindings in
pat_span: Span, pat_span: Span,
/// Input: the spans of the bindings we're providing suggestions for /// Input: the spans of the bindings we're providing suggestions for
@ -709,8 +709,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
impl<'tcx> Visitor<'tcx> for BindingFinder<'tcx> { impl<'tcx> Visitor<'tcx> for BindingFinder<'tcx> {
type NestedFilter = rustc_middle::hir::nested_filter::OnlyBodies; type NestedFilter = rustc_middle::hir::nested_filter::OnlyBodies;
fn nested_visit_map(&mut self) -> Self::Map { fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
self.hir self.tcx
} }
fn visit_expr(&mut self, ex: &'tcx hir::Expr<'tcx>) -> Self::Result { fn visit_expr(&mut self, ex: &'tcx hir::Expr<'tcx>) -> Self::Result {
@ -782,7 +782,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
let typeck_results = self.infcx.tcx.typeck(self.mir_def_id()); let typeck_results = self.infcx.tcx.typeck(self.mir_def_id());
let mut finder = BindingFinder { let mut finder = BindingFinder {
typeck_results, typeck_results,
hir, tcx: self.infcx.tcx,
pat_span, pat_span,
binding_spans, binding_spans,
found_pat: false, found_pat: false,

View file

@ -936,11 +936,12 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
fn expected_fn_found_fn_mut_call(&self, err: &mut Diag<'_>, sp: Span, act: &str) { fn expected_fn_found_fn_mut_call(&self, err: &mut Diag<'_>, sp: Span, act: &str) {
err.span_label(sp, format!("cannot {act}")); err.span_label(sp, format!("cannot {act}"));
let hir = self.infcx.tcx.hir(); let tcx = self.infcx.tcx;
let hir = tcx.hir();
let closure_id = self.mir_hir_id(); let closure_id = self.mir_hir_id();
let closure_span = self.infcx.tcx.def_span(self.mir_def_id()); let closure_span = tcx.def_span(self.mir_def_id());
let fn_call_id = self.infcx.tcx.parent_hir_id(closure_id); let fn_call_id = tcx.parent_hir_id(closure_id);
let node = self.infcx.tcx.hir_node(fn_call_id); let node = tcx.hir_node(fn_call_id);
let def_id = hir.enclosing_body_owner(fn_call_id); let def_id = hir.enclosing_body_owner(fn_call_id);
let mut look_at_return = true; let mut look_at_return = true;
@ -951,7 +952,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
return None; return None;
}; };
let typeck_results = self.infcx.tcx.typeck(def_id); let typeck_results = tcx.typeck(def_id);
match kind { match kind {
hir::ExprKind::Call(expr, args) => { hir::ExprKind::Call(expr, args) => {
@ -980,7 +981,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
.map(|(pos, _)| pos) .map(|(pos, _)| pos)
.next(); .next();
let arg = match hir.get_if_local(callee_def_id) { let arg = match tcx.hir_get_if_local(callee_def_id) {
Some( Some(
hir::Node::Item(hir::Item { hir::Node::Item(hir::Item {
ident, kind: hir::ItemKind::Fn { sig, .. }, .. ident, kind: hir::ItemKind::Fn { sig, .. }, ..
@ -1022,7 +1023,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
if look_at_return && hir.get_fn_id_for_return_block(closure_id).is_some() { if look_at_return && hir.get_fn_id_for_return_block(closure_id).is_some() {
// ...otherwise we are probably in the tail expression of the function, point at the // ...otherwise we are probably in the tail expression of the function, point at the
// return type. // return type.
match self.infcx.tcx.hir_node_by_def_id(hir.get_parent_item(fn_call_id).def_id) { match tcx.hir_node_by_def_id(hir.get_parent_item(fn_call_id).def_id) {
hir::Node::Item(hir::Item { hir::Node::Item(hir::Item {
ident, kind: hir::ItemKind::Fn { sig, .. }, .. ident, kind: hir::ItemKind::Fn { sig, .. }, ..
}) })
@ -1050,9 +1051,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
fn suggest_using_iter_mut(&self, err: &mut Diag<'_>) { fn suggest_using_iter_mut(&self, err: &mut Diag<'_>) {
let source = self.body.source; let source = self.body.source;
let hir = self.infcx.tcx.hir();
if let InstanceKind::Item(def_id) = source.instance if let InstanceKind::Item(def_id) = source.instance
&& let Some(Node::Expr(hir::Expr { hir_id, kind, .. })) = hir.get_if_local(def_id) && let Some(Node::Expr(hir::Expr { hir_id, kind, .. })) =
self.infcx.tcx.hir_get_if_local(def_id)
&& let ExprKind::Closure(hir::Closure { kind: hir::ClosureKind::Closure, .. }) = kind && let ExprKind::Closure(hir::Closure { kind: hir::ClosureKind::Closure, .. }) = kind
&& let Node::Expr(expr) = self.infcx.tcx.parent_hir_node(*hir_id) && let Node::Expr(expr) = self.infcx.tcx.parent_hir_node(*hir_id)
{ {

View file

@ -219,7 +219,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
lower_bound: RegionVid, lower_bound: RegionVid,
) { ) {
let mut suggestions = vec![]; let mut suggestions = vec![];
let hir = self.infcx.tcx.hir(); let tcx = self.infcx.tcx;
// find generic associated types in the given region 'lower_bound' // find generic associated types in the given region 'lower_bound'
let gat_id_and_generics = self let gat_id_and_generics = self
@ -228,12 +228,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
.map(|placeholder| { .map(|placeholder| {
if let Some(id) = placeholder.bound.kind.get_id() if let Some(id) = placeholder.bound.kind.get_id()
&& let Some(placeholder_id) = id.as_local() && let Some(placeholder_id) = id.as_local()
&& let gat_hir_id = self.infcx.tcx.local_def_id_to_hir_id(placeholder_id) && let gat_hir_id = tcx.local_def_id_to_hir_id(placeholder_id)
&& let Some(generics_impl) = self && let Some(generics_impl) =
.infcx tcx.parent_hir_node(tcx.parent_hir_id(gat_hir_id)).generics()
.tcx
.parent_hir_node(self.infcx.tcx.parent_hir_id(gat_hir_id))
.generics()
{ {
Some((gat_hir_id, generics_impl)) Some((gat_hir_id, generics_impl))
} else { } else {
@ -254,7 +251,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
}; };
if bound_generic_params if bound_generic_params
.iter() .iter()
.rfind(|bgp| self.infcx.tcx.local_def_id_to_hir_id(bgp.def_id) == *gat_hir_id) .rfind(|bgp| tcx.local_def_id_to_hir_id(bgp.def_id) == *gat_hir_id)
.is_some() .is_some()
{ {
for bound in *bounds { for bound in *bounds {
@ -270,7 +267,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
return; return;
}; };
diag.span_note(*trait_span, fluent::borrowck_limitations_implies_static); diag.span_note(*trait_span, fluent::borrowck_limitations_implies_static);
let Some(generics_fn) = hir.get_generics(self.body.source.def_id().expect_local()) let Some(generics_fn) = tcx.hir_get_generics(self.body.source.def_id().expect_local())
else { else {
return; return;
}; };
@ -1162,7 +1159,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
if ocx.select_all_or_error().is_empty() && count > 0 { if ocx.select_all_or_error().is_empty() && count > 0 {
diag.span_suggestion_verbose( diag.span_suggestion_verbose(
tcx.hir().body(*body).value.peel_blocks().span.shrink_to_lo(), tcx.hir_body(*body).value.peel_blocks().span.shrink_to_lo(),
fluent::borrowck_dereference_suggestion, fluent::borrowck_dereference_suggestion,
"*".repeat(count), "*".repeat(count),
Applicability::MachineApplicable, Applicability::MachineApplicable,

View file

@ -124,7 +124,7 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, codegen_mode: CodegenMode, jit_args: Vec<
crate::constant::codegen_static(tcx, &mut jit_module, def_id); crate::constant::codegen_static(tcx, &mut jit_module, def_id);
} }
MonoItem::GlobalAsm(item_id) => { MonoItem::GlobalAsm(item_id) => {
let item = tcx.hir().item(item_id); let item = tcx.hir_item(item_id);
tcx.dcx().span_fatal(item.span, "Global asm is not supported in JIT mode"); tcx.dcx().span_fatal(item.span, "Global asm is not supported in JIT mode");
} }
} }

View file

@ -15,7 +15,7 @@ use rustc_target::asm::InlineAsmArch;
use crate::prelude::*; use crate::prelude::*;
pub(crate) fn codegen_global_asm_item(tcx: TyCtxt<'_>, global_asm: &mut String, item_id: ItemId) { pub(crate) fn codegen_global_asm_item(tcx: TyCtxt<'_>, global_asm: &mut String, item_id: ItemId) {
let item = tcx.hir().item(item_id); let item = tcx.hir_item(item_id);
if let rustc_hir::ItemKind::GlobalAsm(asm) = item.kind { if let rustc_hir::ItemKind::GlobalAsm(asm) = item.kind {
let is_x86 = let is_x86 =
matches!(tcx.sess.asm_arch.unwrap(), InlineAsmArch::X86 | InlineAsmArch::X86_64); matches!(tcx.sess.asm_arch.unwrap(), InlineAsmArch::X86 | InlineAsmArch::X86_64);

View file

@ -35,7 +35,7 @@ impl<'a, 'tcx: 'a> MonoItemExt<'a, 'tcx> for MonoItem<'tcx> {
cx.codegen_static(def_id); cx.codegen_static(def_id);
} }
MonoItem::GlobalAsm(item_id) => { MonoItem::GlobalAsm(item_id) => {
let item = cx.tcx().hir().item(item_id); let item = cx.tcx().hir_item(item_id);
if let hir::ItemKind::GlobalAsm(asm) = item.kind { if let hir::ItemKind::GlobalAsm(asm) = item.kind {
let operands: Vec<_> = asm let operands: Vec<_> = asm
.operands .operands

View file

@ -273,7 +273,7 @@ pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) {
let attrs = |id| hir_map.attrs(id); let attrs = |id| hir_map.attrs(id);
pprust_hir::print_crate( pprust_hir::print_crate(
sm, sm,
hir_map.root_module(), tcx.hir_root_module(),
src_name, src_name,
src, src,
&attrs, &attrs,
@ -294,7 +294,7 @@ pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) {
} }
HirTree => { HirTree => {
debug!("pretty printing HIR tree"); debug!("pretty printing HIR tree");
format!("{:#?}", ex.tcx().hir().krate()) format!("{:#?}", ex.tcx().hir_crate(()))
} }
Mir => { Mir => {
let mut out = Vec::new(); let mut out = Vec::new();

View file

@ -18,7 +18,7 @@
//! within one another. //! within one another.
//! - Example: Examine each expression to look for its type and do some check or other. //! - Example: Examine each expression to look for its type and do some check or other.
//! - How: Implement `intravisit::Visitor` and override the `NestedFilter` type to //! - How: Implement `intravisit::Visitor` and override the `NestedFilter` type to
//! `nested_filter::OnlyBodies` (and implement `nested_visit_map`), and use //! `nested_filter::OnlyBodies` (and implement `maybe_tcx`), and use
//! `tcx.hir().visit_all_item_likes_in_crate(&mut visitor)`. Within your //! `tcx.hir().visit_all_item_likes_in_crate(&mut visitor)`. Within your
//! `intravisit::Visitor` impl, implement methods like `visit_expr()` (don't forget to invoke //! `intravisit::Visitor` impl, implement methods like `visit_expr()` (don't forget to invoke
//! `intravisit::walk_expr()` to keep walking the subparts). //! `intravisit::walk_expr()` to keep walking the subparts).
@ -30,7 +30,7 @@
//! - Example: Lifetime resolution, which wants to bring lifetimes declared on the //! - Example: Lifetime resolution, which wants to bring lifetimes declared on the
//! impl into scope while visiting the impl-items, and then back out again. //! impl into scope while visiting the impl-items, and then back out again.
//! - How: Implement `intravisit::Visitor` and override the `NestedFilter` type to //! - How: Implement `intravisit::Visitor` and override the `NestedFilter` type to
//! `nested_filter::All` (and implement `nested_visit_map`). Walk your crate with //! `nested_filter::All` (and implement `maybe_tcx`). Walk your crate with
//! `tcx.hir().walk_toplevel_module(visitor)` invoked on `tcx.hir().krate()`. //! `tcx.hir().walk_toplevel_module(visitor)` invoked on `tcx.hir().krate()`.
//! - Pro: Visitor methods for any kind of HIR node, not just item-like things. //! - Pro: Visitor methods for any kind of HIR node, not just item-like things.
//! - Pro: Preserves nesting information //! - Pro: Preserves nesting information
@ -106,45 +106,43 @@ impl<'a> FnKind<'a> {
} }
} }
/// An abstract representation of the HIR `rustc_middle::hir::map::Map`. /// HIR things retrievable from `TyCtxt`, avoiding an explicit dependence on
pub trait Map<'hir> { /// `TyCtxt`. The only impls are for `!` (where these functions are never
/// called) and `TyCtxt` (in `rustc_middle`).
pub trait HirTyCtxt<'hir> {
/// Retrieves the `Node` corresponding to `id`. /// Retrieves the `Node` corresponding to `id`.
fn hir_node(&self, hir_id: HirId) -> Node<'hir>; fn hir_node(&self, hir_id: HirId) -> Node<'hir>;
fn hir_node_by_def_id(&self, def_id: LocalDefId) -> Node<'hir>; fn hir_body(&self, id: BodyId) -> &'hir Body<'hir>;
fn body(&self, id: BodyId) -> &'hir Body<'hir>; fn hir_item(&self, id: ItemId) -> &'hir Item<'hir>;
fn item(&self, id: ItemId) -> &'hir Item<'hir>; fn hir_trait_item(&self, id: TraitItemId) -> &'hir TraitItem<'hir>;
fn trait_item(&self, id: TraitItemId) -> &'hir TraitItem<'hir>; fn hir_impl_item(&self, id: ImplItemId) -> &'hir ImplItem<'hir>;
fn impl_item(&self, id: ImplItemId) -> &'hir ImplItem<'hir>; fn hir_foreign_item(&self, id: ForeignItemId) -> &'hir ForeignItem<'hir>;
fn foreign_item(&self, id: ForeignItemId) -> &'hir ForeignItem<'hir>;
} }
// Used when no map is actually available, forcing manual implementation of nested visitors. // Used when no tcx is actually available, forcing manual implementation of nested visitors.
impl<'hir> Map<'hir> for ! { impl<'hir> HirTyCtxt<'hir> for ! {
fn hir_node(&self, _: HirId) -> Node<'hir> { fn hir_node(&self, _: HirId) -> Node<'hir> {
*self; unreachable!();
} }
fn hir_node_by_def_id(&self, _: LocalDefId) -> Node<'hir> { fn hir_body(&self, _: BodyId) -> &'hir Body<'hir> {
*self; unreachable!();
} }
fn body(&self, _: BodyId) -> &'hir Body<'hir> { fn hir_item(&self, _: ItemId) -> &'hir Item<'hir> {
*self; unreachable!();
} }
fn item(&self, _: ItemId) -> &'hir Item<'hir> { fn hir_trait_item(&self, _: TraitItemId) -> &'hir TraitItem<'hir> {
*self; unreachable!();
} }
fn trait_item(&self, _: TraitItemId) -> &'hir TraitItem<'hir> { fn hir_impl_item(&self, _: ImplItemId) -> &'hir ImplItem<'hir> {
*self; unreachable!();
} }
fn impl_item(&self, _: ImplItemId) -> &'hir ImplItem<'hir> { fn hir_foreign_item(&self, _: ForeignItemId) -> &'hir ForeignItem<'hir> {
*self; unreachable!();
}
fn foreign_item(&self, _: ForeignItemId) -> &'hir ForeignItem<'hir> {
*self;
} }
} }
pub mod nested_filter { pub mod nested_filter {
use super::Map; use super::HirTyCtxt;
/// Specifies what nested things a visitor wants to visit. By "nested /// Specifies what nested things a visitor wants to visit. By "nested
/// things", we are referring to bits of HIR that are not directly embedded /// things", we are referring to bits of HIR that are not directly embedded
@ -159,7 +157,7 @@ pub mod nested_filter {
/// See the comments at [`rustc_hir::intravisit`] for more details on the overall /// See the comments at [`rustc_hir::intravisit`] for more details on the overall
/// visit strategy. /// visit strategy.
pub trait NestedFilter<'hir> { pub trait NestedFilter<'hir> {
type Map: Map<'hir>; type MaybeTyCtxt: HirTyCtxt<'hir>;
/// Whether the visitor visits nested "item-like" things. /// Whether the visitor visits nested "item-like" things.
/// E.g., item, impl-item. /// E.g., item, impl-item.
@ -175,10 +173,10 @@ pub mod nested_filter {
/// ///
/// Use this if you are only walking some particular kind of tree /// Use this if you are only walking some particular kind of tree
/// (i.e., a type, or fn signature) and you don't want to thread a /// (i.e., a type, or fn signature) and you don't want to thread a
/// HIR map around. /// `tcx` around.
pub struct None(()); pub struct None(());
impl NestedFilter<'_> for None { impl NestedFilter<'_> for None {
type Map = !; type MaybeTyCtxt = !;
const INTER: bool = false; const INTER: bool = false;
const INTRA: bool = false; const INTRA: bool = false;
} }
@ -203,18 +201,18 @@ use nested_filter::NestedFilter;
/// to monitor future changes to `Visitor` in case a new method with a /// to monitor future changes to `Visitor` in case a new method with a
/// new default implementation gets introduced.) /// new default implementation gets introduced.)
pub trait Visitor<'v>: Sized { pub trait Visitor<'v>: Sized {
// this type should not be overridden, it exists for convenient usage as `Self::Map` // This type should not be overridden, it exists for convenient usage as `Self::MaybeTyCtxt`.
type Map: Map<'v> = <Self::NestedFilter as NestedFilter<'v>>::Map; type MaybeTyCtxt: HirTyCtxt<'v> = <Self::NestedFilter as NestedFilter<'v>>::MaybeTyCtxt;
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// Nested items. // Nested items.
/// Override this type to control which nested HIR are visited; see /// Override this type to control which nested HIR are visited; see
/// [`NestedFilter`] for details. If you override this type, you /// [`NestedFilter`] for details. If you override this type, you
/// must also override [`nested_visit_map`](Self::nested_visit_map). /// must also override [`maybe_tcx`](Self::maybe_tcx).
/// ///
/// **If for some reason you want the nested behavior, but don't /// **If for some reason you want the nested behavior, but don't
/// have a `Map` at your disposal:** then override the /// have a `tcx` at your disposal:** then override the
/// `visit_nested_XXX` methods. If a new `visit_nested_XXX` variant is /// `visit_nested_XXX` methods. If a new `visit_nested_XXX` variant is
/// added in the future, it will cause a panic which can be detected /// added in the future, it will cause a panic which can be detected
/// and fixed appropriately. /// and fixed appropriately.
@ -226,9 +224,9 @@ pub trait Visitor<'v>: Sized {
/// If `type NestedFilter` is set to visit nested items, this method /// If `type NestedFilter` is set to visit nested items, this method
/// must also be overridden to provide a map to retrieve nested items. /// must also be overridden to provide a map to retrieve nested items.
fn nested_visit_map(&mut self) -> Self::Map { fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
panic!( panic!(
"nested_visit_map must be implemented or consider using \ "maybe_tcx must be implemented or consider using \
`type NestedFilter = nested_filter::None` (the default)" `type NestedFilter = nested_filter::None` (the default)"
); );
} }
@ -240,10 +238,10 @@ pub trait Visitor<'v>: Sized {
/// "deep" visit patterns described at /// "deep" visit patterns described at
/// [`rustc_hir::intravisit`]. The only reason to override /// [`rustc_hir::intravisit`]. The only reason to override
/// this method is if you want a nested pattern but cannot supply a /// this method is if you want a nested pattern but cannot supply a
/// [`Map`]; see `nested_visit_map` for advice. /// `TyCtxt`; see `maybe_tcx` for advice.
fn visit_nested_item(&mut self, id: ItemId) -> Self::Result { fn visit_nested_item(&mut self, id: ItemId) -> Self::Result {
if Self::NestedFilter::INTER { if Self::NestedFilter::INTER {
let item = self.nested_visit_map().item(id); let item = self.maybe_tcx().hir_item(id);
try_visit!(self.visit_item(item)); try_visit!(self.visit_item(item));
} }
Self::Result::output() Self::Result::output()
@ -254,7 +252,7 @@ pub trait Visitor<'v>: Sized {
/// method. /// method.
fn visit_nested_trait_item(&mut self, id: TraitItemId) -> Self::Result { fn visit_nested_trait_item(&mut self, id: TraitItemId) -> Self::Result {
if Self::NestedFilter::INTER { if Self::NestedFilter::INTER {
let item = self.nested_visit_map().trait_item(id); let item = self.maybe_tcx().hir_trait_item(id);
try_visit!(self.visit_trait_item(item)); try_visit!(self.visit_trait_item(item));
} }
Self::Result::output() Self::Result::output()
@ -265,7 +263,7 @@ pub trait Visitor<'v>: Sized {
/// method. /// method.
fn visit_nested_impl_item(&mut self, id: ImplItemId) -> Self::Result { fn visit_nested_impl_item(&mut self, id: ImplItemId) -> Self::Result {
if Self::NestedFilter::INTER { if Self::NestedFilter::INTER {
let item = self.nested_visit_map().impl_item(id); let item = self.maybe_tcx().hir_impl_item(id);
try_visit!(self.visit_impl_item(item)); try_visit!(self.visit_impl_item(item));
} }
Self::Result::output() Self::Result::output()
@ -276,7 +274,7 @@ pub trait Visitor<'v>: Sized {
/// method. /// method.
fn visit_nested_foreign_item(&mut self, id: ForeignItemId) -> Self::Result { fn visit_nested_foreign_item(&mut self, id: ForeignItemId) -> Self::Result {
if Self::NestedFilter::INTER { if Self::NestedFilter::INTER {
let item = self.nested_visit_map().foreign_item(id); let item = self.maybe_tcx().hir_foreign_item(id);
try_visit!(self.visit_foreign_item(item)); try_visit!(self.visit_foreign_item(item));
} }
Self::Result::output() Self::Result::output()
@ -287,7 +285,7 @@ pub trait Visitor<'v>: Sized {
/// `Self::NestedFilter`. /// `Self::NestedFilter`.
fn visit_nested_body(&mut self, id: BodyId) -> Self::Result { fn visit_nested_body(&mut self, id: BodyId) -> Self::Result {
if Self::NestedFilter::INTRA { if Self::NestedFilter::INTRA {
let body = self.nested_visit_map().body(id); let body = self.maybe_tcx().hir_body(id);
try_visit!(self.visit_body(body)); try_visit!(self.visit_body(body));
} }
Self::Result::output() Self::Result::output()

View file

@ -124,7 +124,7 @@ fn check_union_fields(tcx: TyCtxt<'_>, span: Span, item_def_id: LocalDefId) -> b
for field in &def.non_enum_variant().fields { for field in &def.non_enum_variant().fields {
if !allowed_union_or_unsafe_field(tcx, field.ty(tcx, args), typing_env, span) { if !allowed_union_or_unsafe_field(tcx, field.ty(tcx, args), typing_env, span) {
let (field_span, ty_span) = match tcx.hir().get_if_local(field.did) { let (field_span, ty_span) = match tcx.hir_get_if_local(field.did) {
// We are currently checking the type this field came from, so it must be local. // We are currently checking the type this field came from, so it must be local.
Some(Node::Field(field)) => (field.span, field.ty.span), Some(Node::Field(field)) => (field.span, field.ty.span),
_ => unreachable!("mir field has to correspond to hir field"), _ => unreachable!("mir field has to correspond to hir field"),
@ -435,8 +435,8 @@ fn best_definition_site_of_opaque<'tcx>(
impl<'tcx> intravisit::Visitor<'tcx> for TaitConstraintLocator<'tcx> { impl<'tcx> intravisit::Visitor<'tcx> for TaitConstraintLocator<'tcx> {
type NestedFilter = nested_filter::All; type NestedFilter = nested_filter::All;
type Result = ControlFlow<(Span, LocalDefId)>; type Result = ControlFlow<(Span, LocalDefId)>;
fn nested_visit_map(&mut self) -> Self::Map { fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
self.tcx.hir() self.tcx
} }
fn visit_expr(&mut self, ex: &'tcx hir::Expr<'tcx>) -> Self::Result { fn visit_expr(&mut self, ex: &'tcx hir::Expr<'tcx>) -> Self::Result {
if let hir::ExprKind::Closure(closure) = ex.kind { if let hir::ExprKind::Closure(closure) = ex.kind {
@ -880,7 +880,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
.emit(); .emit();
} }
let item = tcx.hir().foreign_item(item.id); let item = tcx.hir_foreign_item(item.id);
match &item.kind { match &item.kind {
hir::ForeignItemKind::Fn(sig, _, _) => { hir::ForeignItemKind::Fn(sig, _, _) => {
require_c_abi_if_c_variadic(tcx, sig.decl, abi, item.span); require_c_abi_if_c_variadic(tcx, sig.decl, abi, item.span);
@ -1494,7 +1494,7 @@ fn detect_discriminant_duplicate<'tcx>(tcx: TyCtxt<'tcx>, adt: ty::AdtDef<'tcx>)
// In the case the discriminant is both a duplicate and overflowed, let the user know // In the case the discriminant is both a duplicate and overflowed, let the user know
if let hir::Node::AnonConst(expr) = if let hir::Node::AnonConst(expr) =
tcx.hir_node_by_def_id(discr_def_id.expect_local()) tcx.hir_node_by_def_id(discr_def_id.expect_local())
&& let hir::ExprKind::Lit(lit) = &tcx.hir().body(expr.body).value.kind && let hir::ExprKind::Lit(lit) = &tcx.hir_body(expr.body).value.kind
&& let rustc_ast::LitKind::Int(lit_value, _int_kind) = &lit.node && let rustc_ast::LitKind::Int(lit_value, _int_kind) = &lit.node
&& *lit_value != dis.val && *lit_value != dis.val
{ {

View file

@ -658,11 +658,10 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
"method `{}` has an incompatible return type for trait", "method `{}` has an incompatible return type for trait",
trait_m.name trait_m.name
); );
let hir = tcx.hir();
infcx.err_ctxt().note_type_err( infcx.err_ctxt().note_type_err(
&mut diag, &mut diag,
&cause, &cause,
hir.get_if_local(impl_m.def_id) tcx.hir_get_if_local(impl_m.def_id)
.and_then(|node| node.fn_decl()) .and_then(|node| node.fn_decl())
.map(|decl| (decl.output.span(), Cow::from("return type in trait"), false)), .map(|decl| (decl.output.span(), Cow::from("return type in trait"), false)),
Some(param_env.and(infer::ValuePairs::Terms(ExpectedFound { Some(param_env.and(infer::ValuePairs::Terms(ExpectedFound {
@ -1123,15 +1122,14 @@ fn check_region_bounds_on_impl_item<'tcx>(
// the moment, give a kind of vague error message. // the moment, give a kind of vague error message.
if trait_params != impl_params { if trait_params != impl_params {
let span = tcx let span = tcx
.hir() .hir_get_generics(impl_m.def_id.expect_local())
.get_generics(impl_m.def_id.expect_local())
.expect("expected impl item to have generics or else we can't compare them") .expect("expected impl item to have generics or else we can't compare them")
.span; .span;
let mut generics_span = None; let mut generics_span = None;
let mut bounds_span = vec![]; let mut bounds_span = vec![];
let mut where_span = None; let mut where_span = None;
if let Some(trait_node) = tcx.hir().get_if_local(trait_m.def_id) if let Some(trait_node) = tcx.hir_get_if_local(trait_m.def_id)
&& let Some(trait_generics) = trait_node.generics() && let Some(trait_generics) = trait_node.generics()
{ {
generics_span = Some(trait_generics.span); generics_span = Some(trait_generics.span);
@ -1146,7 +1144,7 @@ fn check_region_bounds_on_impl_item<'tcx>(
} }
} }
} }
if let Some(impl_node) = tcx.hir().get_if_local(impl_m.def_id) if let Some(impl_node) = tcx.hir_get_if_local(impl_m.def_id)
&& let Some(impl_generics) = impl_node.generics() && let Some(impl_generics) = impl_node.generics()
{ {
let mut impl_bounds = 0; let mut impl_bounds = 0;

View file

@ -96,7 +96,7 @@ pub(crate) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
// This opaque also needs to be from the impl method -- otherwise, // This opaque also needs to be from the impl method -- otherwise,
// it's a refinement to a TAIT. // it's a refinement to a TAIT.
if !tcx.hir().get_if_local(impl_opaque.def_id).is_some_and(|node| { if !tcx.hir_get_if_local(impl_opaque.def_id).is_some_and(|node| {
matches!( matches!(
node.expect_opaque_ty().origin, node.expect_opaque_ty().origin,
hir::OpaqueTyOrigin::AsyncFn { parent, .. } | hir::OpaqueTyOrigin::FnReturn { parent, .. } hir::OpaqueTyOrigin::AsyncFn { parent, .. } | hir::OpaqueTyOrigin::FnReturn { parent, .. }
@ -327,7 +327,7 @@ fn report_mismatched_rpitit_signature<'tcx>(
hir::FnRetTy::Return(ty) => (ty.span, ty.span, "", ""), hir::FnRetTy::Return(ty) => (ty.span, ty.span, "", ""),
}; };
let trait_return_span = let trait_return_span =
tcx.hir().get_if_local(trait_m_def_id).map(|node| match node.fn_decl().unwrap().output { tcx.hir_get_if_local(trait_m_def_id).map(|node| match node.fn_decl().unwrap().output {
hir::FnRetTy::DefaultReturn(_) => tcx.def_span(trait_m_def_id), hir::FnRetTy::DefaultReturn(_) => tcx.def_span(trait_m_def_id),
hir::FnRetTy::Return(ty) => ty.span, hir::FnRetTy::Return(ty) => ty.span,
}); });

View file

@ -129,7 +129,7 @@ fn get_owner_return_paths(
let hir_id = tcx.local_def_id_to_hir_id(def_id); let hir_id = tcx.local_def_id_to_hir_id(def_id);
let parent_id = tcx.hir().get_parent_item(hir_id).def_id; let parent_id = tcx.hir().get_parent_item(hir_id).def_id;
tcx.hir_node_by_def_id(parent_id).body_id().map(|body_id| { tcx.hir_node_by_def_id(parent_id).body_id().map(|body_id| {
let body = tcx.hir().body(body_id); let body = tcx.hir_body(body_id);
let mut visitor = ReturnsVisitor::default(); let mut visitor = ReturnsVisitor::default();
visitor.visit_body(body); visitor.visit_body(body);
(parent_id, visitor) (parent_id, visitor)

View file

@ -424,7 +424,7 @@ fn resolve_expr<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, expr: &'tcx hi
// that share the parent environment. We handle const blocks in // that share the parent environment. We handle const blocks in
// `visit_inline_const`. // `visit_inline_const`.
hir::ExprKind::Closure(&hir::Closure { body, .. }) => { hir::ExprKind::Closure(&hir::Closure { body, .. }) => {
let body = visitor.tcx.hir().body(body); let body = visitor.tcx.hir_body(body);
visitor.visit_body(body); visitor.visit_body(body);
} }
hir::ExprKind::AssignOp(_, left_expr, right_expr) => { hir::ExprKind::AssignOp(_, left_expr, right_expr) => {
@ -906,7 +906,7 @@ impl<'tcx> Visitor<'tcx> for ScopeResolutionVisitor<'tcx> {
resolve_local(self, Some(l.pat), l.init) resolve_local(self, Some(l.pat), l.init)
} }
fn visit_inline_const(&mut self, c: &'tcx hir::ConstBlock) { fn visit_inline_const(&mut self, c: &'tcx hir::ConstBlock) {
let body = self.tcx.hir().body(c.body); let body = self.tcx.hir_body(c.body);
self.visit_body(body); self.visit_body(body);
} }
} }

View file

@ -1163,7 +1163,7 @@ fn check_type_defn<'tcx>(
// be refactored to check the instantiate-ability of the code better. // be refactored to check the instantiate-ability of the code better.
if let Some(def_id) = def_id.as_local() if let Some(def_id) = def_id.as_local()
&& let hir::Node::AnonConst(anon) = tcx.hir_node_by_def_id(def_id) && let hir::Node::AnonConst(anon) = tcx.hir_node_by_def_id(def_id)
&& let expr = &tcx.hir().body(anon.body).value && let expr = &tcx.hir_body(anon.body).value
&& let hir::ExprKind::Path(hir::QPath::Resolved(None, path)) = expr.kind && let hir::ExprKind::Path(hir::QPath::Resolved(None, path)) = expr.kind
&& let Res::Def(DefKind::ConstParam, _def_id) = path.res && let Res::Def(DefKind::ConstParam, _def_id) = path.res
{ {

View file

@ -679,7 +679,7 @@ fn infringing_fields_error<'tcx>(
suggest_constraining_type_params( suggest_constraining_type_params(
tcx, tcx,
tcx.hir().get_generics(impl_did).expect("impls always have generics"), tcx.hir_get_generics(impl_did).expect("impls always have generics"),
&mut err, &mut err,
bounds bounds
.iter() .iter()

View file

@ -25,7 +25,7 @@ pub(crate) fn crate_inherent_impls(
let mut collect = InherentCollect { tcx, impls_map: Default::default() }; let mut collect = InherentCollect { tcx, impls_map: Default::default() };
let mut res = Ok(()); let mut res = Ok(());
for id in tcx.hir().items() { for id in tcx.hir_free_items() {
res = res.and(collect.check_item(id)); res = res.and(collect.check_item(id));
} }

View file

@ -18,7 +18,7 @@ pub(crate) fn crate_inherent_impls_overlap_check(
) -> Result<(), ErrorGuaranteed> { ) -> Result<(), ErrorGuaranteed> {
let mut inherent_overlap_checker = InherentOverlapChecker { tcx }; let mut inherent_overlap_checker = InherentOverlapChecker { tcx };
let mut res = Ok(()); let mut res = Ok(());
for id in tcx.hir().items() { for id in tcx.hir_free_items() {
res = res.and(inherent_overlap_checker.check_item(id)); res = res.and(inherent_overlap_checker.check_item(id));
} }
res res

View file

@ -277,8 +277,8 @@ fn reject_placeholder_type_signatures_in_item<'tcx>(
impl<'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'tcx> { impl<'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
type NestedFilter = nested_filter::OnlyBodies; type NestedFilter = nested_filter::OnlyBodies;
fn nested_visit_map(&mut self) -> Self::Map { fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
self.tcx.hir() self.tcx
} }
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) { fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
@ -669,7 +669,7 @@ fn get_new_lifetime_name<'tcx>(
#[instrument(level = "debug", skip_all)] #[instrument(level = "debug", skip_all)]
fn lower_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) { fn lower_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
let it = tcx.hir().item(item_id); let it = tcx.hir_item(item_id);
debug!(item = %it.ident, id = %it.hir_id()); debug!(item = %it.ident, id = %it.hir_id());
let def_id = item_id.owner_id.def_id; let def_id = item_id.owner_id.def_id;
let icx = ItemCtxt::new(tcx, def_id); let icx = ItemCtxt::new(tcx, def_id);
@ -683,7 +683,7 @@ fn lower_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
| hir::ItemKind::GlobalAsm(_) => {} | hir::ItemKind::GlobalAsm(_) => {}
hir::ItemKind::ForeignMod { items, .. } => { hir::ItemKind::ForeignMod { items, .. } => {
for item in *items { for item in *items {
let item = tcx.hir().foreign_item(item.id); let item = tcx.hir_foreign_item(item.id);
tcx.ensure_ok().generics_of(item.owner_id); tcx.ensure_ok().generics_of(item.owner_id);
tcx.ensure_ok().type_of(item.owner_id); tcx.ensure_ok().type_of(item.owner_id);
tcx.ensure_ok().predicates_of(item.owner_id); tcx.ensure_ok().predicates_of(item.owner_id);
@ -790,7 +790,7 @@ fn lower_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
} }
fn lower_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) { fn lower_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
let trait_item = tcx.hir().trait_item(trait_item_id); let trait_item = tcx.hir_trait_item(trait_item_id);
let def_id = trait_item_id.owner_id; let def_id = trait_item_id.owner_id;
tcx.ensure_ok().generics_of(def_id); tcx.ensure_ok().generics_of(def_id);
let icx = ItemCtxt::new(tcx, def_id.def_id); let icx = ItemCtxt::new(tcx, def_id.def_id);
@ -865,7 +865,7 @@ fn lower_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::ImplItemId) {
tcx.ensure_ok().generics_of(def_id); tcx.ensure_ok().generics_of(def_id);
tcx.ensure_ok().type_of(def_id); tcx.ensure_ok().type_of(def_id);
tcx.ensure_ok().predicates_of(def_id); tcx.ensure_ok().predicates_of(def_id);
let impl_item = tcx.hir().impl_item(impl_item_id); let impl_item = tcx.hir_impl_item(impl_item_id);
let icx = ItemCtxt::new(tcx, def_id.def_id); let icx = ItemCtxt::new(tcx, def_id.def_id);
match impl_item.kind { match impl_item.kind {
hir::ImplItemKind::Fn(..) => { hir::ImplItemKind::Fn(..) => {
@ -1769,7 +1769,7 @@ fn coroutine_for_closure(tcx: TyCtxt<'_>, def_id: LocalDefId) -> DefId {
.. ..
}), }),
.. ..
} = tcx.hir().body(body).value } = tcx.hir_body(body).value
else { else {
bug!() bug!()
}; };

View file

@ -52,7 +52,7 @@ pub(crate) fn predicates_and_item_bounds(tcx: TyCtxt<'_>) {
} }
pub(crate) fn def_parents(tcx: TyCtxt<'_>) { pub(crate) fn def_parents(tcx: TyCtxt<'_>) {
for iid in tcx.hir().items() { for iid in tcx.hir_free_items() {
let did = iid.owner_id.def_id; let did = iid.owner_id.def_id;
if tcx.has_attr(did, sym::rustc_dump_def_parents) { if tcx.has_attr(did, sym::rustc_dump_def_parents) {
struct AnonConstFinder<'tcx> { struct AnonConstFinder<'tcx> {
@ -63,8 +63,8 @@ pub(crate) fn def_parents(tcx: TyCtxt<'_>) {
impl<'tcx> intravisit::Visitor<'tcx> for AnonConstFinder<'tcx> { impl<'tcx> intravisit::Visitor<'tcx> for AnonConstFinder<'tcx> {
type NestedFilter = nested_filter::All; type NestedFilter = nested_filter::All;
fn nested_visit_map(&mut self) -> Self::Map { fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
self.tcx.hir() self.tcx
} }
fn visit_anon_const(&mut self, c: &'tcx rustc_hir::AnonConst) { fn visit_anon_const(&mut self, c: &'tcx rustc_hir::AnonConst) {
@ -77,7 +77,7 @@ pub(crate) fn def_parents(tcx: TyCtxt<'_>) {
// the `rustc_dump_def_parents` attribute to the anon const so it would not be possible // the `rustc_dump_def_parents` attribute to the anon const so it would not be possible
// to see what its def parent is. // to see what its def parent is.
let mut anon_ct_finder = AnonConstFinder { tcx, anon_consts: vec![] }; let mut anon_ct_finder = AnonConstFinder { tcx, anon_consts: vec![] };
intravisit::walk_item(&mut anon_ct_finder, tcx.hir().item(iid)); intravisit::walk_item(&mut anon_ct_finder, tcx.hir_item(iid));
for did in [did].into_iter().chain(anon_ct_finder.anon_consts) { for did in [did].into_iter().chain(anon_ct_finder.anon_consts) {
let span = tcx.def_span(did); let span = tcx.def_span(did);
@ -99,14 +99,14 @@ pub(crate) fn def_parents(tcx: TyCtxt<'_>) {
} }
pub(crate) fn vtables<'tcx>(tcx: TyCtxt<'tcx>) { pub(crate) fn vtables<'tcx>(tcx: TyCtxt<'tcx>) {
for id in tcx.hir().items() { for id in tcx.hir_free_items() {
let def_id = id.owner_id.def_id; let def_id = id.owner_id.def_id;
let Some(attr) = tcx.get_attr(def_id, sym::rustc_dump_vtable) else { let Some(attr) = tcx.get_attr(def_id, sym::rustc_dump_vtable) else {
continue; continue;
}; };
let vtable_entries = match tcx.hir().item(id).kind { let vtable_entries = match tcx.hir_item(id).kind {
hir::ItemKind::Impl(hir::Impl { of_trait: Some(_), .. }) => { hir::ItemKind::Impl(hir::Impl { of_trait: Some(_), .. }) => {
let trait_ref = tcx.impl_trait_ref(def_id).unwrap().instantiate_identity(); let trait_ref = tcx.impl_trait_ref(def_id).unwrap().instantiate_identity();
if trait_ref.has_non_region_param() { if trait_ref.has_non_region_param() {

View file

@ -422,12 +422,12 @@ enum NonLifetimeBinderAllowed {
impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> { impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
type NestedFilter = nested_filter::OnlyBodies; type NestedFilter = nested_filter::OnlyBodies;
fn nested_visit_map(&mut self) -> Self::Map { fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
self.tcx.hir() self.tcx
} }
fn visit_nested_body(&mut self, body: hir::BodyId) { fn visit_nested_body(&mut self, body: hir::BodyId) {
let body = self.tcx.hir().body(body); let body = self.tcx.hir_body(body);
self.with(Scope::Body { id: body.id(), s: self.scope }, |this| { self.with(Scope::Body { id: body.id(), s: self.scope }, |this| {
this.visit_body(body); this.visit_body(body);
}); });
@ -1049,7 +1049,7 @@ fn object_lifetime_default(tcx: TyCtxt<'_>, param_def_id: LocalDefId) -> ObjectL
match param.source { match param.source {
hir::GenericParamSource::Generics => { hir::GenericParamSource::Generics => {
let parent_def_id = tcx.local_parent(param_def_id); let parent_def_id = tcx.local_parent(param_def_id);
let generics = tcx.hir().get_generics(parent_def_id).unwrap(); let generics = tcx.hir_get_generics(parent_def_id).unwrap();
let param_hir_id = tcx.local_def_id_to_hir_id(param_def_id); let param_hir_id = tcx.local_def_id_to_hir_id(param_def_id);
let param = generics.params.iter().find(|p| p.hir_id == param_hir_id).unwrap(); let param = generics.params.iter().find(|p| p.hir_id == param_hir_id).unwrap();
@ -1250,7 +1250,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
if let Some(hir::PredicateOrigin::ImplTrait) = where_bound_origin if let Some(hir::PredicateOrigin::ImplTrait) = where_bound_origin
&& let hir::LifetimeName::Param(param_id) = lifetime_ref.res && let hir::LifetimeName::Param(param_id) = lifetime_ref.res
&& let Some(generics) = && let Some(generics) =
self.tcx.hir().get_generics(self.tcx.local_parent(param_id)) self.tcx.hir_get_generics(self.tcx.local_parent(param_id))
&& let Some(param) = generics.params.iter().find(|p| p.def_id == param_id) && let Some(param) = generics.params.iter().find(|p| p.def_id == param_id)
&& param.is_elided_lifetime() && param.is_elided_lifetime()
&& !self.tcx.asyncness(lifetime_ref.hir_id.owner.def_id).is_async() && !self.tcx.asyncness(lifetime_ref.hir_id.owner.def_id).is_async()
@ -1264,7 +1264,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
); );
if let Some(generics) = if let Some(generics) =
self.tcx.hir().get_generics(lifetime_ref.hir_id.owner.def_id) self.tcx.hir_get_generics(lifetime_ref.hir_id.owner.def_id)
{ {
let new_param_sugg = let new_param_sugg =
if let Some(span) = generics.span_for_lifetime_suggestion() { if let Some(span) = generics.span_for_lifetime_suggestion() {
@ -2266,7 +2266,7 @@ fn is_late_bound_map(
owner_id: hir::OwnerId, owner_id: hir::OwnerId,
) -> Option<&FxIndexSet<hir::ItemLocalId>> { ) -> Option<&FxIndexSet<hir::ItemLocalId>> {
let sig = tcx.hir().fn_sig_by_hir_id(owner_id.into())?; let sig = tcx.hir().fn_sig_by_hir_id(owner_id.into())?;
let generics = tcx.hir().get_generics(owner_id.def_id)?; let generics = tcx.hir_get_generics(owner_id.def_id)?;
let mut late_bound = FxIndexSet::default(); let mut late_bound = FxIndexSet::default();

View file

@ -451,7 +451,7 @@ fn infer_placeholder_type<'tcx>(
); );
} else { } else {
with_forced_trimmed_paths!(err.span_note( with_forced_trimmed_paths!(err.span_note(
tcx.hir().body(body_id).value.span, tcx.hir_body(body_id).value.span,
format!("however, the inferred type `{ty}` cannot be named"), format!("however, the inferred type `{ty}` cannot be named"),
)); ));
} }
@ -494,7 +494,7 @@ fn infer_placeholder_type<'tcx>(
); );
} else { } else {
with_forced_trimmed_paths!(diag.span_note( with_forced_trimmed_paths!(diag.span_note(
tcx.hir().body(body_id).value.span, tcx.hir_body(body_id).value.span,
format!("however, the inferred type `{ty}` cannot be named"), format!("however, the inferred type `{ty}` cannot be named"),
)); ));
} }

View file

@ -298,8 +298,8 @@ impl TaitConstraintLocator<'_> {
impl<'tcx> intravisit::Visitor<'tcx> for TaitConstraintLocator<'tcx> { impl<'tcx> intravisit::Visitor<'tcx> for TaitConstraintLocator<'tcx> {
type NestedFilter = nested_filter::All; type NestedFilter = nested_filter::All;
fn nested_visit_map(&mut self) -> Self::Map { fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
self.tcx.hir() self.tcx
} }
fn visit_expr(&mut self, ex: &'tcx Expr<'tcx>) { fn visit_expr(&mut self, ex: &'tcx Expr<'tcx>) {
if let hir::ExprKind::Closure(closure) = ex.kind { if let hir::ExprKind::Closure(closure) = ex.kind {
@ -441,8 +441,8 @@ impl RpitConstraintChecker<'_> {
impl<'tcx> intravisit::Visitor<'tcx> for RpitConstraintChecker<'tcx> { impl<'tcx> intravisit::Visitor<'tcx> for RpitConstraintChecker<'tcx> {
type NestedFilter = nested_filter::OnlyBodies; type NestedFilter = nested_filter::OnlyBodies;
fn nested_visit_map(&mut self) -> Self::Map { fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
self.tcx.hir() self.tcx
} }
fn visit_expr(&mut self, ex: &'tcx Expr<'tcx>) { fn visit_expr(&mut self, ex: &'tcx Expr<'tcx>) {
if let hir::ExprKind::Closure(closure) = ex.kind { if let hir::ExprKind::Closure(closure) = ex.kind {

View file

@ -451,7 +451,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
) )
}); });
let fn_sig = self.tcx.hir().get_if_local(self.def_id).and_then(hir::Node::fn_sig); let fn_sig = self.tcx.hir_get_if_local(self.def_id).and_then(hir::Node::fn_sig);
let is_used_in_input = |def_id| { let is_used_in_input = |def_id| {
fn_sig.is_some_and(|fn_sig| { fn_sig.is_some_and(|fn_sig| {
fn_sig.decl.inputs.iter().any(|ty| match ty.kind { fn_sig.decl.inputs.iter().any(|ty| match ty.kind {

View file

@ -225,7 +225,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
&& let item_def_id = && let item_def_id =
tcx.hir().get_parent_item(tcx.local_def_id_to_hir_id(ty_param_def_id)) tcx.hir().get_parent_item(tcx.local_def_id_to_hir_id(ty_param_def_id))
// FIXME: ...which obviously won't have any generics. // FIXME: ...which obviously won't have any generics.
&& let Some(generics) = tcx.hir().get_generics(item_def_id.def_id) && let Some(generics) = tcx.hir_get_generics(item_def_id.def_id)
{ {
// FIXME: Suggest adding supertrait bounds if we have a `Self` type param. // FIXME: Suggest adding supertrait bounds if we have a `Self` type param.
// FIXME(trait_alias): Suggest adding `Self: Trait` to // FIXME(trait_alias): Suggest adding `Self: Trait` to

View file

@ -110,7 +110,7 @@ fn generic_arg_mismatch_err(
err.help(format!("`{}` is a function item, not a type", tcx.item_name(id))); err.help(format!("`{}` is a function item, not a type", tcx.item_name(id)));
err.help("function item types cannot be named directly"); err.help("function item types cannot be named directly");
} else if let hir::ConstArgKind::Anon(anon) = cnst.kind } else if let hir::ConstArgKind::Anon(anon) = cnst.kind
&& let body = tcx.hir().body(anon.body) && let body = tcx.hir_body(anon.body)
&& let rustc_hir::ExprKind::Path(rustc_hir::QPath::Resolved(_, path)) = && let rustc_hir::ExprKind::Path(rustc_hir::QPath::Resolved(_, path)) =
body.value.kind body.value.kind
&& let Res::Def(DefKind::Fn { .. }, id) = path.res && let Res::Def(DefKind::Fn { .. }, id) = path.res

View file

@ -1976,7 +1976,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
if let Some(hir::Node::Item(&hir::Item { if let Some(hir::Node::Item(&hir::Item {
kind: hir::ItemKind::Impl(impl_), kind: hir::ItemKind::Impl(impl_),
.. ..
})) = tcx.hir().get_if_local(def_id) })) = tcx.hir_get_if_local(def_id)
{ {
err.span_note(impl_.self_ty.span, "not a concrete type"); err.span_note(impl_.self_ty.span, "not a concrete type");
} }
@ -2213,7 +2213,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
fn lower_anon_const(&self, anon: &AnonConst) -> Const<'tcx> { fn lower_anon_const(&self, anon: &AnonConst) -> Const<'tcx> {
let tcx = self.tcx(); let tcx = self.tcx();
let expr = &tcx.hir().body(anon.body).value; let expr = &tcx.hir_body(anon.body).value;
debug!(?expr); debug!(?expr);
let ty = tcx let ty = tcx

View file

@ -3,7 +3,7 @@ use rustc_middle::ty::{self, TyCtxt};
use rustc_span::sym; use rustc_span::sym;
pub(crate) fn inferred_outlives(tcx: TyCtxt<'_>) { pub(crate) fn inferred_outlives(tcx: TyCtxt<'_>) {
for id in tcx.hir().items() { for id in tcx.hir_free_items() {
if !tcx.has_attr(id.owner_id, sym::rustc_outlives) { if !tcx.has_attr(id.owner_id, sym::rustc_outlives) {
continue; continue;
} }

View file

@ -28,7 +28,7 @@ pub(super) fn infer_predicates(
let mut predicates_added = false; let mut predicates_added = false;
// Visit all the crates and infer predicates // Visit all the crates and infer predicates
for id in tcx.hir().items() { for id in tcx.hir_free_items() {
let item_did = id.owner_id; let item_did = id.owner_id;
debug!("InferVisitor::visit_item(item={:?})", item_did); debug!("InferVisitor::visit_item(item={:?})", item_did);

View file

@ -24,8 +24,8 @@ use rustc_span::source_map::SourceMap;
use rustc_span::{FileName, Ident, Span, Symbol, kw}; use rustc_span::{FileName, Ident, Span, Symbol, kw};
use {rustc_ast as ast, rustc_hir as hir}; use {rustc_ast as ast, rustc_hir as hir};
pub fn id_to_string(map: &dyn rustc_hir::intravisit::Map<'_>, hir_id: HirId) -> String { pub fn id_to_string(cx: &dyn rustc_hir::intravisit::HirTyCtxt<'_>, hir_id: HirId) -> String {
to_string(&map, |s| s.print_node(map.hir_node(hir_id))) to_string(&cx, |s| s.print_node(cx.hir_node(hir_id)))
} }
pub enum AnnNode<'a> { pub enum AnnNode<'a> {
@ -54,15 +54,15 @@ pub trait PpAnn {
fn post(&self, _state: &mut State<'_>, _node: AnnNode<'_>) {} fn post(&self, _state: &mut State<'_>, _node: AnnNode<'_>) {}
} }
impl PpAnn for &dyn rustc_hir::intravisit::Map<'_> { impl PpAnn for &dyn rustc_hir::intravisit::HirTyCtxt<'_> {
fn nested(&self, state: &mut State<'_>, nested: Nested) { fn nested(&self, state: &mut State<'_>, nested: Nested) {
match nested { match nested {
Nested::Item(id) => state.print_item(self.item(id)), Nested::Item(id) => state.print_item(self.hir_item(id)),
Nested::TraitItem(id) => state.print_trait_item(self.trait_item(id)), Nested::TraitItem(id) => state.print_trait_item(self.hir_trait_item(id)),
Nested::ImplItem(id) => state.print_impl_item(self.impl_item(id)), Nested::ImplItem(id) => state.print_impl_item(self.hir_impl_item(id)),
Nested::ForeignItem(id) => state.print_foreign_item(self.foreign_item(id)), Nested::ForeignItem(id) => state.print_foreign_item(self.hir_foreign_item(id)),
Nested::Body(id) => state.print_expr(self.body(id).value), Nested::Body(id) => state.print_expr(self.hir_body(id).value),
Nested::BodyParamPat(id, i) => state.print_pat(self.body(id).params[i].pat), Nested::BodyParamPat(id, i) => state.print_pat(self.hir_body(id).params[i].pat),
} }
} }
} }

View file

@ -708,8 +708,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
&& let Res::Local(_) = path.res && let Res::Local(_) = path.res
&& let [segment] = &path.segments && let [segment] = &path.segments
{ {
for id in self.tcx.hir().items() { for id in self.tcx.hir_free_items() {
if let Some(node) = self.tcx.hir().get_if_local(id.owner_id.into()) if let Some(node) = self.tcx.hir_get_if_local(id.owner_id.into())
&& let hir::Node::Item(item) = node && let hir::Node::Item(item) = node
&& let hir::ItemKind::Fn { .. } = item.kind && let hir::ItemKind::Fn { .. } = item.kind
&& item.ident.name == segment.ident.name && item.ident.name == segment.ident.name

View file

@ -51,7 +51,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
expected: Expectation<'tcx>, expected: Expectation<'tcx>,
) -> Ty<'tcx> { ) -> Ty<'tcx> {
let tcx = self.tcx; let tcx = self.tcx;
let body = tcx.hir().body(closure.body); let body = tcx.hir_body(closure.body);
let expr_def_id = closure.def_id; let expr_def_id = closure.def_id;
// It's always helpful for inference if we know the kind of // It's always helpful for inference if we know the kind of

View file

@ -1891,7 +1891,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
kind: hir::ExprKind::Closure(&hir::Closure { body, .. }), kind: hir::ExprKind::Closure(&hir::Closure { body, .. }),
.. ..
}) = parent }) = parent
&& !matches!(fcx.tcx.hir().body(body).value.kind, hir::ExprKind::Block(..)) && !matches!(fcx.tcx.hir_body(body).value.kind, hir::ExprKind::Block(..))
{ {
fcx.suggest_missing_semicolon(&mut err, expr, expected, true); fcx.suggest_missing_semicolon(&mut err, expr, expected, true);
} }

View file

@ -727,7 +727,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
ident, ident,
kind: hir::ItemKind::Static(ty, ..) | hir::ItemKind::Const(ty, ..), kind: hir::ItemKind::Static(ty, ..) | hir::ItemKind::Const(ty, ..),
.. ..
})) = self.tcx.hir().get_if_local(*def_id) })) = self.tcx.hir_get_if_local(*def_id)
{ {
primary_span = ty.span; primary_span = ty.span;
secondary_span = ident.span; secondary_span = ident.span;
@ -1173,7 +1173,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if let Some(hir::Node::Item(hir::Item { if let Some(hir::Node::Item(hir::Item {
kind: hir::ItemKind::Impl(hir::Impl { self_ty, .. }), kind: hir::ItemKind::Impl(hir::Impl { self_ty, .. }),
.. ..
})) = self.tcx.hir().get_if_local(*alias_to) })) = self.tcx.hir_get_if_local(*alias_to)
{ {
err.span_label(self_ty.span, "this is the type of the `Self` literal"); err.span_label(self_ty.span, "this is the type of the `Self` literal");
} }

View file

@ -1801,7 +1801,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
block: &'tcx hir::ConstBlock, block: &'tcx hir::ConstBlock,
expected: Expectation<'tcx>, expected: Expectation<'tcx>,
) -> Ty<'tcx> { ) -> Ty<'tcx> {
let body = self.tcx.hir().body(block.body); let body = self.tcx.hir_body(block.body);
// Create a new function context. // Create a new function context.
let def_id = block.def_id; let def_id = block.def_id;

View file

@ -687,7 +687,7 @@ impl<'tcx> Visitor<'tcx> for AnnotateUnitFallbackVisitor<'_, 'tcx> {
if let hir::ExprKind::Closure(&hir::Closure { body, .. }) if let hir::ExprKind::Closure(&hir::Closure { body, .. })
| hir::ExprKind::ConstBlock(hir::ConstBlock { body, .. }) = expr.kind | hir::ExprKind::ConstBlock(hir::ConstBlock { body, .. }) = expr.kind
{ {
self.visit_body(self.fcx.tcx.hir().body(body))?; self.visit_body(self.fcx.tcx.hir_body(body))?;
} }
// Try to suggest adding an explicit qself `()` to a trait method path. // Try to suggest adding an explicit qself `()` to a trait method path.

View file

@ -640,7 +640,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let witness = Ty::new_coroutine_witness(self.tcx, expr_def_id.to_def_id(), args); let witness = Ty::new_coroutine_witness(self.tcx, expr_def_id.to_def_id(), args);
// Unify `interior` with `witness` and collect all the resulting obligations. // Unify `interior` with `witness` and collect all the resulting obligations.
let span = self.tcx.hir().body(body_id).value.span; let span = self.tcx.hir_body(body_id).value.span;
let ty::Infer(ty::InferTy::TyVar(_)) = interior.kind() else { let ty::Infer(ty::InferTy::TyVar(_)) = interior.kind() else {
span_bug!(span, "coroutine interior witness not infer: {:?}", interior.kind()) span_bug!(span, "coroutine interior witness not infer: {:?}", interior.kind())
}; };

View file

@ -2056,7 +2056,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
match node { match node {
Node::Item(&hir::Item { kind: hir::ItemKind::Fn { body: body_id, .. }, .. }) Node::Item(&hir::Item { kind: hir::ItemKind::Fn { body: body_id, .. }, .. })
| Node::ImplItem(&hir::ImplItem { kind: hir::ImplItemKind::Fn(_, body_id), .. }) => { | Node::ImplItem(&hir::ImplItem { kind: hir::ImplItemKind::Fn(_, body_id), .. }) => {
let body = self.tcx.hir().body(body_id); let body = self.tcx.hir_body(body_id);
if let ExprKind::Block(block, _) = &body.value.kind { if let ExprKind::Block(block, _) = &body.value.kind {
return Some(block.span); return Some(block.span);
} }
@ -2512,11 +2512,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
} }
err.span_note(spans, format!("{} defined here", self.tcx.def_descr(def_id))); err.span_note(spans, format!("{} defined here", self.tcx.def_descr(def_id)));
} else if let Some(hir::Node::Expr(e)) = self.tcx.hir().get_if_local(def_id) } else if let Some(hir::Node::Expr(e)) = self.tcx.hir_get_if_local(def_id)
&& let hir::ExprKind::Closure(hir::Closure { body, .. }) = &e.kind && let hir::ExprKind::Closure(hir::Closure { body, .. }) = &e.kind
{ {
let param = expected_idx let param = expected_idx
.and_then(|expected_idx| self.tcx.hir().body(*body).params.get(expected_idx)); .and_then(|expected_idx| self.tcx.hir_body(*body).params.get(expected_idx));
let (kind, span) = if let Some(param) = param { let (kind, span) = if let Some(param) = param {
// Try to find earlier invocations of this closure to find if the type mismatch // Try to find earlier invocations of this closure to find if the type mismatch
// is because of inference. If we find one, point at them. // is because of inference. If we find one, point at them.
@ -2650,7 +2650,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
is_method: bool, is_method: bool,
) -> Option<(IndexVec<ExpectedIdx, (Option<GenericIdx>, FnParam<'_>)>, &hir::Generics<'_>)> ) -> Option<(IndexVec<ExpectedIdx, (Option<GenericIdx>, FnParam<'_>)>, &hir::Generics<'_>)>
{ {
let (sig, generics, body_id, param_names) = match self.tcx.hir().get_if_local(def_id)? { let (sig, generics, body_id, param_names) = match self.tcx.hir_get_if_local(def_id)? {
hir::Node::TraitItem(&hir::TraitItem { hir::Node::TraitItem(&hir::TraitItem {
generics, generics,
kind: hir::TraitItemKind::Fn(sig, trait_fn), kind: hir::TraitItemKind::Fn(sig, trait_fn),
@ -2695,7 +2695,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
match (body_id, param_names) { match (body_id, param_names) {
(Some(_), Some(_)) | (None, None) => unreachable!(), (Some(_), Some(_)) | (None, None) => unreachable!(),
(Some(body), None) => { (Some(body), None) => {
let params = self.tcx.hir().body(body).params; let params = self.tcx.hir_body(body).params;
let params = let params =
params.get(is_method as usize..params.len() - sig.decl.c_variadic as usize)?; params.get(is_method as usize..params.len() - sig.decl.c_variadic as usize)?;
debug_assert_eq!(params.len(), fn_inputs.len()); debug_assert_eq!(params.len(), fn_inputs.len());
@ -2725,8 +2725,8 @@ struct FindClosureArg<'tcx> {
impl<'tcx> Visitor<'tcx> for FindClosureArg<'tcx> { impl<'tcx> Visitor<'tcx> for FindClosureArg<'tcx> {
type NestedFilter = rustc_middle::hir::nested_filter::All; type NestedFilter = rustc_middle::hir::nested_filter::All;
fn nested_visit_map(&mut self) -> Self::Map { fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
self.tcx.hir() self.tcx
} }
fn visit_expr(&mut self, ex: &'tcx hir::Expr<'tcx>) { fn visit_expr(&mut self, ex: &'tcx hir::Expr<'tcx>) {

View file

@ -1813,7 +1813,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
); );
let owner = self.tcx.hir().enclosing_body_owner(expr.hir_id); let owner = self.tcx.hir().enclosing_body_owner(expr.hir_id);
if let ty::Param(param) = expected_ty.kind() if let ty::Param(param) = expected_ty.kind()
&& let Some(generics) = self.tcx.hir().get_generics(owner) && let Some(generics) = self.tcx.hir_get_generics(owner)
{ {
suggest_constraining_type_params( suggest_constraining_type_params(
self.tcx, self.tcx,
@ -1933,7 +1933,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.. ..
} = init } = init
{ {
let hir::Body { value: body_expr, .. } = self.tcx.hir().body(*body_id); let hir::Body { value: body_expr, .. } = self.tcx.hir_body(*body_id);
self.note_type_is_not_clone_inner_expr(body_expr) self.note_type_is_not_clone_inner_expr(body_expr)
} else { } else {
expr expr

View file

@ -123,7 +123,7 @@ fn typeck_with_inspect<'tcx>(
let body_id = node.body_id().unwrap_or_else(|| { let body_id = node.body_id().unwrap_or_else(|| {
span_bug!(span, "can't type-check body of {:?}", def_id); span_bug!(span, "can't type-check body of {:?}", def_id);
}); });
let body = tcx.hir().body(body_id); let body = tcx.hir_body(body_id);
let param_env = tcx.param_env(def_id); let param_env = tcx.param_env(def_id);

View file

@ -1091,7 +1091,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
continue; continue;
} }
match self.tcx.hir().get_if_local(item_def_id) { match self.tcx.hir_get_if_local(item_def_id) {
// Unmet obligation comes from a `derive` macro, point at it once to // Unmet obligation comes from a `derive` macro, point at it once to
// avoid multiple span labels pointing at the same place. // avoid multiple span labels pointing at the same place.
Some(Node::Item(hir::Item { Some(Node::Item(hir::Item {
@ -3753,19 +3753,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
hir::TraitFn::Required([ident, ..]) => { hir::TraitFn::Required([ident, ..]) => {
ident.name == kw::SelfLower ident.name == kw::SelfLower
} }
hir::TraitFn::Provided(body_id) => self hir::TraitFn::Provided(body_id) => {
.tcx self.tcx.hir_body(*body_id).params.first().is_some_and(
.hir() |param| {
.body(*body_id)
.params
.first()
.is_some_and(|param| {
matches!( matches!(
param.pat.kind, param.pat.kind,
hir::PatKind::Binding(_, _, ident, _) hir::PatKind::Binding(_, _, ident, _)
if ident.name == kw::SelfLower if ident.name == kw::SelfLower
) )
}), },
)
}
_ => false, _ => false,
}; };
@ -3833,20 +3831,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if let Some(param) = param_type { if let Some(param) = param_type {
let generics = self.tcx.generics_of(self.body_id.to_def_id()); let generics = self.tcx.generics_of(self.body_id.to_def_id());
let type_param = generics.type_param(param, self.tcx); let type_param = generics.type_param(param, self.tcx);
let hir = self.tcx.hir(); let tcx = self.tcx;
if let Some(def_id) = type_param.def_id.as_local() { if let Some(def_id) = type_param.def_id.as_local() {
let id = self.tcx.local_def_id_to_hir_id(def_id); let id = tcx.local_def_id_to_hir_id(def_id);
// Get the `hir::Param` to verify whether it already has any bounds. // Get the `hir::Param` to verify whether it already has any bounds.
// We do this to avoid suggesting code that ends up as `T: FooBar`, // We do this to avoid suggesting code that ends up as `T: FooBar`,
// instead we suggest `T: Foo + Bar` in that case. // instead we suggest `T: Foo + Bar` in that case.
match self.tcx.hir_node(id) { match tcx.hir_node(id) {
Node::GenericParam(param) => { Node::GenericParam(param) => {
enum Introducer { enum Introducer {
Plus, Plus,
Colon, Colon,
Nothing, Nothing,
} }
let hir_generics = hir.get_generics(id.owner.def_id).unwrap(); let hir_generics = tcx.hir_get_generics(id.owner.def_id).unwrap();
let trait_def_ids: DefIdSet = hir_generics let trait_def_ids: DefIdSet = hir_generics
.bounds_for_param(def_id) .bounds_for_param(def_id)
.flat_map(|bp| bp.bounds.iter()) .flat_map(|bp| bp.bounds.iter())
@ -3866,8 +3864,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let candidate_strs: Vec<_> = candidates let candidate_strs: Vec<_> = candidates
.iter() .iter()
.map(|cand| { .map(|cand| {
let cand_path = self.tcx.def_path_str(cand.def_id); let cand_path = tcx.def_path_str(cand.def_id);
let cand_params = &self.tcx.generics_of(cand.def_id).own_params; let cand_params = &tcx.generics_of(cand.def_id).own_params;
let cand_args: String = cand_params let cand_args: String = cand_params
.iter() .iter()
.skip(1) .skip(1)
@ -3960,9 +3958,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
err.span_suggestions( err.span_suggestions(
sp, sp,
message(format!("add {article} supertrait for")), message(format!("add {article} supertrait for")),
candidates.iter().map(|t| { candidates
format!("{} {}", sep, self.tcx.def_path_str(t.def_id),) .iter()
}), .map(|t| format!("{} {}", sep, tcx.def_path_str(t.def_id),)),
Applicability::MaybeIncorrect, Applicability::MaybeIncorrect,
); );
return; return;

View file

@ -1231,7 +1231,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
ident: Ident, ident: Ident,
) -> bool { ) -> bool {
match opt_def_id { match opt_def_id {
Some(def_id) => match self.tcx.hir().get_if_local(def_id) { Some(def_id) => match self.tcx.hir_get_if_local(def_id) {
Some(hir::Node::Item(hir::Item { Some(hir::Node::Item(hir::Item {
kind: hir::ItemKind::Const(_, _, body_id), kind: hir::ItemKind::Const(_, _, body_id),
.. ..

View file

@ -143,7 +143,7 @@ impl<'a, 'tcx> Visitor<'tcx> for InferBorrowKindVisitor<'a, 'tcx> {
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) { fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) {
match expr.kind { match expr.kind {
hir::ExprKind::Closure(&hir::Closure { capture_clause, body: body_id, .. }) => { hir::ExprKind::Closure(&hir::Closure { capture_clause, body: body_id, .. }) => {
let body = self.fcx.tcx.hir().body(body_id); let body = self.fcx.tcx.hir_body(body_id);
self.visit_body(body); self.visit_body(body);
self.fcx.analyze_closure(expr.hir_id, expr.span, body_id, body, capture_clause); self.fcx.analyze_closure(expr.hir_id, expr.span, body_id, body, capture_clause);
} }
@ -154,7 +154,7 @@ impl<'a, 'tcx> Visitor<'tcx> for InferBorrowKindVisitor<'a, 'tcx> {
} }
fn visit_inline_const(&mut self, c: &'tcx hir::ConstBlock) { fn visit_inline_const(&mut self, c: &'tcx hir::ConstBlock) {
let body = self.fcx.tcx.hir().body(c.body); let body = self.fcx.tcx.hir_body(c.body);
self.visit_body(body); self.visit_body(body);
} }
} }

View file

@ -249,7 +249,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
fn visit_const_block(&mut self, span: Span, anon_const: &hir::ConstBlock) { fn visit_const_block(&mut self, span: Span, anon_const: &hir::ConstBlock) {
self.visit_node_id(span, anon_const.hir_id); self.visit_node_id(span, anon_const.hir_id);
let body = self.tcx().hir().body(anon_const.body); let body = self.tcx().hir_body(anon_const.body);
self.visit_body(body); self.visit_body(body);
} }
} }
@ -266,7 +266,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for WritebackCx<'cx, 'tcx> {
fn visit_expr(&mut self, e: &'tcx hir::Expr<'tcx>) { fn visit_expr(&mut self, e: &'tcx hir::Expr<'tcx>) {
match e.kind { match e.kind {
hir::ExprKind::Closure(&hir::Closure { body, .. }) => { hir::ExprKind::Closure(&hir::Closure { body, .. }) => {
let body = self.fcx.tcx.hir().body(body); let body = self.fcx.tcx.hir_body(body);
for param in body.params { for param in body.params {
self.visit_node_id(e.span, param.hir_id); self.visit_node_id(e.span, param.hir_id);
} }

View file

@ -174,8 +174,8 @@ impl<'tcx> IfThisChanged<'tcx> {
impl<'tcx> Visitor<'tcx> for IfThisChanged<'tcx> { impl<'tcx> Visitor<'tcx> for IfThisChanged<'tcx> {
type NestedFilter = nested_filter::OnlyBodies; type NestedFilter = nested_filter::OnlyBodies;
fn nested_visit_map(&mut self) -> Self::Map { fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
self.tcx.hir() self.tcx
} }
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) { fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {

View file

@ -455,8 +455,8 @@ impl<'tcx> FindAllAttrs<'tcx> {
impl<'tcx> intravisit::Visitor<'tcx> for FindAllAttrs<'tcx> { impl<'tcx> intravisit::Visitor<'tcx> for FindAllAttrs<'tcx> {
type NestedFilter = nested_filter::All; type NestedFilter = nested_filter::All;
fn nested_visit_map(&mut self) -> Self::Map { fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
self.tcx.hir() self.tcx
} }
fn visit_attribute(&mut self, attr: &'tcx Attribute) { fn visit_attribute(&mut self, attr: &'tcx Attribute) {

View file

@ -7,7 +7,7 @@ use rustc_span::sym;
fn proc_macro_decls_static(tcx: TyCtxt<'_>, (): ()) -> Option<LocalDefId> { fn proc_macro_decls_static(tcx: TyCtxt<'_>, (): ()) -> Option<LocalDefId> {
let mut decls = None; let mut decls = None;
for id in tcx.hir().items() { for id in tcx.hir_free_items() {
let attrs = tcx.hir().attrs(id.hir_id()); let attrs = tcx.hir().attrs(id.hir_id());
if attr::contains_name(attrs, sym::rustc_proc_macro_decls) { if attr::contains_name(attrs, sym::rustc_proc_macro_decls) {
decls = Some(id.owner_id.def_id); decls = Some(id.owner_id.def_id);

View file

@ -68,7 +68,7 @@ impl<'tcx> LateLintPass<'tcx> for AsyncClosureUsage {
return; return;
}; };
let mut body = cx.tcx.hir().body(body).value; let mut body = cx.tcx.hir_body(body).value;
// Only peel blocks that have no expressions. // Only peel blocks that have no expressions.
while let hir::ExprKind::Block(&hir::Block { stmts: [], expr: Some(tail), .. }, None) = while let hir::ExprKind::Block(&hir::Block { stmts: [], expr: Some(tail), .. }, None) =

View file

@ -1057,7 +1057,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidNoMangleItems {
check_no_mangle_on_generic_fn( check_no_mangle_on_generic_fn(
no_mangle_attr, no_mangle_attr,
Some(generics), Some(generics),
cx.tcx.hir().get_generics(it.id.owner_id.def_id).unwrap(), cx.tcx.hir_get_generics(it.id.owner_id.def_id).unwrap(),
it.span, it.span,
); );
} }

View file

@ -928,7 +928,7 @@ impl<'tcx> LateContext<'tcx> {
while let hir::ExprKind::Path(ref qpath) = expr.kind while let hir::ExprKind::Path(ref qpath) = expr.kind
&& let Some(parent_node) = match self.qpath_res(qpath, expr.hir_id) { && let Some(parent_node) = match self.qpath_res(qpath, expr.hir_id) {
Res::Local(hir_id) => Some(self.tcx.parent_hir_node(hir_id)), Res::Local(hir_id) => Some(self.tcx.parent_hir_node(hir_id)),
Res::Def(_, def_id) => self.tcx.hir().get_if_local(def_id), Res::Def(_, def_id) => self.tcx.hir_get_if_local(def_id),
_ => None, _ => None,
} }
&& let Some(init) = match parent_node { && let Some(init) = match parent_node {
@ -936,7 +936,7 @@ impl<'tcx> LateContext<'tcx> {
hir::Node::LetStmt(hir::LetStmt { init, .. }) => *init, hir::Node::LetStmt(hir::LetStmt { init, .. }) => *init,
hir::Node::Item(item) => match item.kind { hir::Node::Item(item) => match item.kind {
hir::ItemKind::Const(.., body_id) | hir::ItemKind::Static(.., body_id) => { hir::ItemKind::Const(.., body_id) | hir::ItemKind::Static(.., body_id) => {
Some(self.tcx.hir().body(body_id).value) Some(self.tcx.hir_body(body_id).value)
} }
_ => None, _ => None,
}, },

View file

@ -76,10 +76,8 @@ impl<'tcx> LateLintPass<'tcx> for DefaultCouldBeDerived {
// We now know we have a manually written definition of a `<Type as Default>::default()`. // We now know we have a manually written definition of a `<Type as Default>::default()`.
let hir = cx.tcx.hir();
let type_def_id = def.did(); let type_def_id = def.did();
let body = hir.body(body_id); let body = cx.tcx.hir_body(body_id);
// FIXME: evaluate bodies with statements and evaluate bindings to see if they would be // FIXME: evaluate bodies with statements and evaluate bindings to see if they would be
// derivable. // derivable.
@ -92,7 +90,7 @@ impl<'tcx> LateLintPass<'tcx> for DefaultCouldBeDerived {
// Keep a mapping of field name to `hir::FieldDef` for every field in the type. We'll use // Keep a mapping of field name to `hir::FieldDef` for every field in the type. We'll use
// these to check for things like checking whether it has a default or using its span for // these to check for things like checking whether it has a default or using its span for
// suggestions. // suggestions.
let orig_fields = match hir.get_if_local(type_def_id) { let orig_fields = match cx.tcx.hir_get_if_local(type_def_id) {
Some(hir::Node::Item(hir::Item { Some(hir::Node::Item(hir::Item {
kind: kind:
hir::ItemKind::Struct(hir::VariantData::Struct { fields, recovered: _ }, _generics), hir::ItemKind::Struct(hir::VariantData::Struct { fields, recovered: _ }, _generics),
@ -183,7 +181,7 @@ fn mk_lint(
if removed_all_fields { if removed_all_fields {
let msg = "to avoid divergence in behavior between `Struct { .. }` and \ let msg = "to avoid divergence in behavior between `Struct { .. }` and \
`<Struct as Default>::default()`, derive the `Default`"; `<Struct as Default>::default()`, derive the `Default`";
if let Some(hir::Node::Item(impl_)) = tcx.hir().get_if_local(impl_def_id) { if let Some(hir::Node::Item(impl_)) = tcx.hir_get_if_local(impl_def_id) {
diag.multipart_suggestion_verbose( diag.multipart_suggestion_verbose(
msg, msg,
vec![ vec![

View file

@ -155,7 +155,7 @@ fn suggest_question_mark<'tcx>(
// Check that the function/closure/constant we are in has a `Result` type. // Check that the function/closure/constant we are in has a `Result` type.
// Otherwise suggesting using `?` may not be a good idea. // Otherwise suggesting using `?` may not be a good idea.
{ {
let ty = cx.typeck_results().expr_ty(cx.tcx.hir().body(body_id).value); let ty = cx.typeck_results().expr_ty(cx.tcx.hir_body(body_id).value);
let ty::Adt(ret_adt, ..) = ty.kind() else { return false }; let ty::Adt(ret_adt, ..) = ty.kind() else { return false };
if !cx.tcx.is_diagnostic_item(sym::Result, ret_adt.did()) { if !cx.tcx.is_diagnostic_item(sym::Result, ret_adt.did()) {
return false; return false;

View file

@ -84,8 +84,8 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
/// Because lints are scoped lexically, we want to walk nested /// Because lints are scoped lexically, we want to walk nested
/// items in the context of the outer item, so enable /// items in the context of the outer item, so enable
/// deep-walking. /// deep-walking.
fn nested_visit_map(&mut self) -> Self::Map { fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
self.context.tcx.hir() self.context.tcx
} }
fn visit_nested_body(&mut self, body_id: hir::BodyId) { fn visit_nested_body(&mut self, body_id: hir::BodyId) {
@ -99,7 +99,7 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
self.context.cached_typeck_results.set(None); self.context.cached_typeck_results.set(None);
} }
let body = self.context.tcx.hir().body(body_id); let body = self.context.tcx.hir_body(body_id);
self.visit_body(body); self.visit_body(body);
self.context.enclosing_body = old_enclosing_body; self.context.enclosing_body = old_enclosing_body;
@ -191,7 +191,7 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
// in order for `check_fn` to be able to use them. // in order for `check_fn` to be able to use them.
let old_enclosing_body = self.context.enclosing_body.replace(body_id); let old_enclosing_body = self.context.enclosing_body.replace(body_id);
let old_cached_typeck_results = self.context.cached_typeck_results.take(); let old_cached_typeck_results = self.context.cached_typeck_results.take();
let body = self.context.tcx.hir().body(body_id); let body = self.context.tcx.hir_body(body_id);
lint_callback!(self, check_fn, fk, decl, body, span, id); lint_callback!(self, check_fn, fk, decl, body, span, id);
hir_visit::walk_fn(self, fk, decl, body_id, id); hir_visit::walk_fn(self, fk, decl, body_id, id);
self.context.enclosing_body = old_enclosing_body; self.context.enclosing_body = old_enclosing_body;

View file

@ -270,8 +270,8 @@ impl<'tcx> LintLevelsBuilder<'_, LintLevelQueryMap<'tcx>> {
impl<'tcx> Visitor<'tcx> for LintLevelsBuilder<'_, LintLevelQueryMap<'tcx>> { impl<'tcx> Visitor<'tcx> for LintLevelsBuilder<'_, LintLevelQueryMap<'tcx>> {
type NestedFilter = nested_filter::OnlyBodies; type NestedFilter = nested_filter::OnlyBodies;
fn nested_visit_map(&mut self) -> Self::Map { fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
self.provider.tcx.hir() self.provider.tcx
} }
fn visit_param(&mut self, param: &'tcx hir::Param<'tcx>) { fn visit_param(&mut self, param: &'tcx hir::Param<'tcx>) {
@ -365,8 +365,8 @@ impl<'tcx> LintLevelMaximum<'tcx> {
impl<'tcx> Visitor<'tcx> for LintLevelMaximum<'tcx> { impl<'tcx> Visitor<'tcx> for LintLevelMaximum<'tcx> {
type NestedFilter = nested_filter::All; type NestedFilter = nested_filter::All;
fn nested_visit_map(&mut self) -> Self::Map { fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
self.tcx.hir() self.tcx
} }
/// FIXME(blyxyas): In a future revision, we should also graph #![allow]s, /// FIXME(blyxyas): In a future revision, we should also graph #![allow]s,

View file

@ -10,13 +10,13 @@ pub(crate) fn collect(tcx: TyCtxt<'_>, LocalCrate: LocalCrate) -> FxIndexMap<Def
let mut modules = FxIndexMap::default(); let mut modules = FxIndexMap::default();
// We need to collect all the `ForeignMod`, even if they are empty. // We need to collect all the `ForeignMod`, even if they are empty.
for id in tcx.hir().items() { for id in tcx.hir_free_items() {
if !matches!(tcx.def_kind(id.owner_id), DefKind::ForeignMod) { if !matches!(tcx.def_kind(id.owner_id), DefKind::ForeignMod) {
continue; continue;
} }
let def_id = id.owner_id.to_def_id(); let def_id = id.owner_id.to_def_id();
let item = tcx.hir().item(id); let item = tcx.hir_item(id);
if let hir::ItemKind::ForeignMod { abi, items } = item.kind { if let hir::ItemKind::ForeignMod { abi, items } = item.kind {
let foreign_items = items.iter().map(|it| it.id.owner_id.to_def_id()).collect(); let foreign_items = items.iter().map(|it| it.id.owner_id.to_def_id()).collect();

View file

@ -1940,7 +1940,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
bug!("Unknown proc-macro type for item {:?}", id); bug!("Unknown proc-macro type for item {:?}", id);
}; };
let mut def_key = self.tcx.hir().def_key(id); let mut def_key = self.tcx.hir_def_key(id);
def_key.disambiguated_data.data = DefPathData::MacroNs(name); def_key.disambiguated_data.data = DefPathData::MacroNs(name);
let def_id = id.to_def_id(); let def_id = id.to_def_id();
@ -2076,7 +2076,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
let mut trait_impls: FxIndexMap<DefId, Vec<(DefIndex, Option<SimplifiedType>)>> = let mut trait_impls: FxIndexMap<DefId, Vec<(DefIndex, Option<SimplifiedType>)>> =
FxIndexMap::default(); FxIndexMap::default();
for id in tcx.hir().items() { for id in tcx.hir_free_items() {
let DefKind::Impl { of_trait } = tcx.def_kind(id.owner_id) else { let DefKind::Impl { of_trait } = tcx.def_kind(id.owner_id) else {
continue; continue;
}; };
@ -2410,7 +2410,6 @@ pub(crate) fn provide(providers: &mut Providers) {
/// use a different method for pretty-printing. Ideally this function /// use a different method for pretty-printing. Ideally this function
/// should only ever be used as a fallback. /// should only ever be used as a fallback.
pub fn rendered_const<'tcx>(tcx: TyCtxt<'tcx>, body: &hir::Body<'_>, def_id: LocalDefId) -> String { pub fn rendered_const<'tcx>(tcx: TyCtxt<'tcx>, body: &hir::Body<'_>, def_id: LocalDefId) -> String {
let hir = tcx.hir();
let value = body.value; let value = body.value;
#[derive(PartialEq, Eq)] #[derive(PartialEq, Eq)]
@ -2467,7 +2466,7 @@ pub fn rendered_const<'tcx>(tcx: TyCtxt<'tcx>, body: &hir::Body<'_>, def_id: Loc
// Otherwise we prefer pretty-printing to get rid of extraneous whitespace, comments and // Otherwise we prefer pretty-printing to get rid of extraneous whitespace, comments and
// other formatting artifacts. // other formatting artifacts.
Literal | Simple => id_to_string(&hir, body.id().hir_id), Literal | Simple => id_to_string(&tcx, body.id().hir_id),
// FIXME: Omit the curly braces if the enclosing expression is an array literal // FIXME: Omit the curly braces if the enclosing expression is an array literal
// with a repeated element (an `ExprKind::Repeat`) as in such case it // with a repeated element (an `ExprKind::Repeat`) as in such case it

View file

@ -93,7 +93,7 @@ impl<'hir> Iterator for ParentOwnerIterator<'hir> {
return None; return None;
} }
let parent_id = self.map.def_key(self.current_id.owner.def_id).parent; let parent_id = self.map.tcx.hir_def_key(self.current_id.owner.def_id).parent;
let parent_id = parent_id.map_or(CRATE_OWNER_ID, |local_def_index| { let parent_id = parent_id.map_or(CRATE_OWNER_ID, |local_def_index| {
let def_id = LocalDefId { local_def_index }; let def_id = LocalDefId { local_def_index };
self.map.tcx.local_def_id_to_hir_id(def_id).owner self.map.tcx.local_def_id_to_hir_id(def_id).owner
@ -164,76 +164,74 @@ impl<'tcx> TyCtxt<'tcx> {
pub fn parent_hir_node(self, hir_id: HirId) -> Node<'tcx> { pub fn parent_hir_node(self, hir_id: HirId) -> Node<'tcx> {
self.hir_node(self.parent_hir_id(hir_id)) self.hir_node(self.parent_hir_id(hir_id))
} }
}
impl<'hir> Map<'hir> {
#[inline]
pub fn krate(self) -> &'hir Crate<'hir> {
self.tcx.hir_crate(())
}
#[inline] #[inline]
pub fn root_module(self) -> &'hir Mod<'hir> { pub fn hir_root_module(self) -> &'tcx Mod<'tcx> {
match self.tcx.hir_owner_node(CRATE_OWNER_ID) { match self.hir_owner_node(CRATE_OWNER_ID) {
OwnerNode::Crate(item) => item, OwnerNode::Crate(item) => item,
_ => bug!(), _ => bug!(),
} }
} }
#[inline] #[inline]
pub fn items(self) -> impl Iterator<Item = ItemId> + 'hir { pub fn hir_free_items(self) -> impl Iterator<Item = ItemId> + 'tcx {
self.tcx.hir_crate_items(()).free_items.iter().copied() self.hir_crate_items(()).free_items.iter().copied()
} }
#[inline] #[inline]
pub fn module_items(self, module: LocalModDefId) -> impl Iterator<Item = ItemId> + 'hir { pub fn hir_module_free_items(
self.tcx.hir_module_items(module).free_items() self,
module: LocalModDefId,
) -> impl Iterator<Item = ItemId> + 'tcx {
self.hir_module_items(module).free_items()
} }
pub fn def_key(self, def_id: LocalDefId) -> DefKey { pub fn hir_def_key(self, def_id: LocalDefId) -> DefKey {
// Accessing the DefKey is ok, since it is part of DefPathHash. // Accessing the DefKey is ok, since it is part of DefPathHash.
self.tcx.definitions_untracked().def_key(def_id) self.definitions_untracked().def_key(def_id)
} }
pub fn def_path(self, def_id: LocalDefId) -> DefPath { pub fn hir_def_path(self, def_id: LocalDefId) -> DefPath {
// Accessing the DefPath is ok, since it is part of DefPathHash. // Accessing the DefPath is ok, since it is part of DefPathHash.
self.tcx.definitions_untracked().def_path(def_id) self.definitions_untracked().def_path(def_id)
} }
#[inline] #[inline]
pub fn def_path_hash(self, def_id: LocalDefId) -> DefPathHash { pub fn hir_def_path_hash(self, def_id: LocalDefId) -> DefPathHash {
// Accessing the DefPathHash is ok, it is incr. comp. stable. // Accessing the DefPathHash is ok, it is incr. comp. stable.
self.tcx.definitions_untracked().def_path_hash(def_id) self.definitions_untracked().def_path_hash(def_id)
} }
pub fn get_if_local(self, id: DefId) -> Option<Node<'hir>> { pub fn hir_get_if_local(self, id: DefId) -> Option<Node<'tcx>> {
id.as_local().map(|id| self.tcx.hir_node_by_def_id(id)) id.as_local().map(|id| self.hir_node_by_def_id(id))
} }
pub fn get_generics(self, id: LocalDefId) -> Option<&'hir Generics<'hir>> { pub fn hir_get_generics(self, id: LocalDefId) -> Option<&'tcx Generics<'tcx>> {
self.tcx.opt_hir_owner_node(id)?.generics() self.opt_hir_owner_node(id)?.generics()
} }
pub fn item(self, id: ItemId) -> &'hir Item<'hir> { pub fn hir_item(self, id: ItemId) -> &'tcx Item<'tcx> {
self.tcx.hir_owner_node(id.owner_id).expect_item() self.hir_owner_node(id.owner_id).expect_item()
} }
pub fn trait_item(self, id: TraitItemId) -> &'hir TraitItem<'hir> { pub fn hir_trait_item(self, id: TraitItemId) -> &'tcx TraitItem<'tcx> {
self.tcx.hir_owner_node(id.owner_id).expect_trait_item() self.hir_owner_node(id.owner_id).expect_trait_item()
} }
pub fn impl_item(self, id: ImplItemId) -> &'hir ImplItem<'hir> { pub fn hir_impl_item(self, id: ImplItemId) -> &'tcx ImplItem<'tcx> {
self.tcx.hir_owner_node(id.owner_id).expect_impl_item() self.hir_owner_node(id.owner_id).expect_impl_item()
} }
pub fn foreign_item(self, id: ForeignItemId) -> &'hir ForeignItem<'hir> { pub fn hir_foreign_item(self, id: ForeignItemId) -> &'tcx ForeignItem<'tcx> {
self.tcx.hir_owner_node(id.owner_id).expect_foreign_item() self.hir_owner_node(id.owner_id).expect_foreign_item()
} }
pub fn body(self, id: BodyId) -> &'hir Body<'hir> { pub fn hir_body(self, id: BodyId) -> &'tcx Body<'tcx> {
self.tcx.hir_owner_nodes(id.hir_id.owner).bodies[&id.hir_id.local_id] self.hir_owner_nodes(id.hir_id.owner).bodies[&id.hir_id.local_id]
} }
}
impl<'hir> Map<'hir> {
#[track_caller] #[track_caller]
pub fn fn_decl_by_hir_id(self, hir_id: HirId) -> Option<&'hir FnDecl<'hir>> { pub fn fn_decl_by_hir_id(self, hir_id: HirId) -> Option<&'hir FnDecl<'hir>> {
self.tcx.hir_node(hir_id).fn_decl() self.tcx.hir_node(hir_id).fn_decl()
@ -271,7 +269,7 @@ impl<'hir> Map<'hir> {
/// Given a `LocalDefId`, returns the `BodyId` associated with it, /// Given a `LocalDefId`, returns the `BodyId` associated with it,
/// if the node is a body owner, otherwise returns `None`. /// if the node is a body owner, otherwise returns `None`.
pub fn maybe_body_owned_by(self, id: LocalDefId) -> Option<&'hir Body<'hir>> { pub fn maybe_body_owned_by(self, id: LocalDefId) -> Option<&'hir Body<'hir>> {
Some(self.body(self.tcx.hir_node_by_def_id(id).body_id()?)) Some(self.tcx.hir_body(self.tcx.hir_node_by_def_id(id).body_id()?))
} }
/// Given a body owner's id, returns the `BodyId` associated with it. /// Given a body owner's id, returns the `BodyId` associated with it.
@ -288,7 +286,7 @@ impl<'hir> Map<'hir> {
} }
pub fn body_param_names(self, id: BodyId) -> impl Iterator<Item = Ident> + 'hir { pub fn body_param_names(self, id: BodyId) -> impl Iterator<Item = Ident> + 'hir {
self.body(id).params.iter().map(|arg| match arg.pat.kind { self.tcx.hir_body(id).params.iter().map(|arg| match arg.pat.kind {
PatKind::Binding(_, _, ident, _) => ident, PatKind::Binding(_, _, ident, _) => ident,
_ => Ident::empty(), _ => Ident::empty(),
}) })
@ -410,7 +408,7 @@ impl<'hir> Map<'hir> {
where where
V: Visitor<'hir>, V: Visitor<'hir>,
{ {
let krate = self.krate(); let krate = self.tcx.hir_crate(());
for info in krate.owners.iter() { for info in krate.owners.iter() {
if let MaybeOwner::Owner(info) = info { if let MaybeOwner::Owner(info) = info {
for attrs in info.attrs.map.values() { for attrs in info.attrs.map.values() {
@ -436,13 +434,21 @@ impl<'hir> Map<'hir> {
V: Visitor<'hir>, V: Visitor<'hir>,
{ {
let krate = self.tcx.hir_crate_items(()); let krate = self.tcx.hir_crate_items(());
walk_list!(visitor, visit_item, krate.free_items().map(|id| self.item(id))); walk_list!(visitor, visit_item, krate.free_items().map(|id| self.tcx.hir_item(id)));
walk_list!(visitor, visit_trait_item, krate.trait_items().map(|id| self.trait_item(id))); walk_list!(
walk_list!(visitor, visit_impl_item, krate.impl_items().map(|id| self.impl_item(id))); visitor,
visit_trait_item,
krate.trait_items().map(|id| self.tcx.hir_trait_item(id))
);
walk_list!(
visitor,
visit_impl_item,
krate.impl_items().map(|id| self.tcx.hir_impl_item(id))
);
walk_list!( walk_list!(
visitor, visitor,
visit_foreign_item, visit_foreign_item,
krate.foreign_items().map(|id| self.foreign_item(id)) krate.foreign_items().map(|id| self.tcx.hir_foreign_item(id))
); );
V::Result::output() V::Result::output()
} }
@ -454,13 +460,21 @@ impl<'hir> Map<'hir> {
V: Visitor<'hir>, V: Visitor<'hir>,
{ {
let module = self.tcx.hir_module_items(module); let module = self.tcx.hir_module_items(module);
walk_list!(visitor, visit_item, module.free_items().map(|id| self.item(id))); walk_list!(visitor, visit_item, module.free_items().map(|id| self.tcx.hir_item(id)));
walk_list!(visitor, visit_trait_item, module.trait_items().map(|id| self.trait_item(id))); walk_list!(
walk_list!(visitor, visit_impl_item, module.impl_items().map(|id| self.impl_item(id))); visitor,
visit_trait_item,
module.trait_items().map(|id| self.tcx.hir_trait_item(id))
);
walk_list!(
visitor,
visit_impl_item,
module.impl_items().map(|id| self.tcx.hir_impl_item(id))
);
walk_list!( walk_list!(
visitor, visitor,
visit_foreign_item, visit_foreign_item,
module.foreign_items().map(|id| self.foreign_item(id)) module.foreign_items().map(|id| self.tcx.hir_foreign_item(id))
); );
V::Result::output() V::Result::output()
} }
@ -921,7 +935,7 @@ impl<'hir> Map<'hir> {
Node::Variant(variant) => variant.span, Node::Variant(variant) => variant.span,
Node::Field(field) => field.span, Node::Field(field) => field.span,
Node::AnonConst(constant) => constant.span, Node::AnonConst(constant) => constant.span,
Node::ConstBlock(constant) => self.body(constant.body).value.span, Node::ConstBlock(constant) => self.tcx.hir_body(constant.body).value.span,
Node::ConstArg(const_arg) => const_arg.span(), Node::ConstArg(const_arg) => const_arg.span(),
Node::Expr(expr) => expr.span, Node::Expr(expr) => expr.span,
Node::ExprField(field) => field.span, Node::ExprField(field) => field.span,
@ -1014,39 +1028,35 @@ impl<'hir> Map<'hir> {
} }
} }
impl<'hir> intravisit::Map<'hir> for Map<'hir> { impl<'tcx> intravisit::HirTyCtxt<'tcx> for TyCtxt<'tcx> {
fn hir_node(&self, hir_id: HirId) -> Node<'hir> { fn hir_node(&self, hir_id: HirId) -> Node<'tcx> {
self.tcx.hir_node(hir_id) (*self).hir_node(hir_id)
} }
fn hir_node_by_def_id(&self, def_id: LocalDefId) -> Node<'hir> { fn hir_body(&self, id: BodyId) -> &'tcx Body<'tcx> {
self.tcx.hir_node_by_def_id(def_id) (*self).hir_body(id)
} }
fn body(&self, id: BodyId) -> &'hir Body<'hir> { fn hir_item(&self, id: ItemId) -> &'tcx Item<'tcx> {
(*self).body(id) (*self).hir_item(id)
} }
fn item(&self, id: ItemId) -> &'hir Item<'hir> { fn hir_trait_item(&self, id: TraitItemId) -> &'tcx TraitItem<'tcx> {
(*self).item(id) (*self).hir_trait_item(id)
} }
fn trait_item(&self, id: TraitItemId) -> &'hir TraitItem<'hir> { fn hir_impl_item(&self, id: ImplItemId) -> &'tcx ImplItem<'tcx> {
(*self).trait_item(id) (*self).hir_impl_item(id)
} }
fn impl_item(&self, id: ImplItemId) -> &'hir ImplItem<'hir> { fn hir_foreign_item(&self, id: ForeignItemId) -> &'tcx ForeignItem<'tcx> {
(*self).impl_item(id) (*self).hir_foreign_item(id)
}
fn foreign_item(&self, id: ForeignItemId) -> &'hir ForeignItem<'hir> {
(*self).foreign_item(id)
} }
} }
impl<'tcx> pprust_hir::PpAnn for TyCtxt<'tcx> { impl<'tcx> pprust_hir::PpAnn for TyCtxt<'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.hir() as &dyn intravisit::Map<'_>), state, nested) pprust_hir::PpAnn::nested(&(self as &dyn intravisit::HirTyCtxt<'_>), state, nested)
} }
} }
@ -1333,8 +1343,8 @@ impl<'tcx> ItemCollector<'tcx> {
impl<'hir> Visitor<'hir> for ItemCollector<'hir> { impl<'hir> Visitor<'hir> for ItemCollector<'hir> {
type NestedFilter = nested_filter::All; type NestedFilter = nested_filter::All;
fn nested_visit_map(&mut self) -> Self::Map { fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
self.tcx.hir() self.tcx
} }
fn visit_item(&mut self, item: &'hir Item<'hir>) { fn visit_item(&mut self, item: &'hir Item<'hir>) {

View file

@ -1,5 +1,7 @@
use rustc_hir::intravisit::nested_filter::NestedFilter; use rustc_hir::intravisit::nested_filter::NestedFilter;
use crate::ty::TyCtxt;
/// Do not visit nested item-like things, but visit nested things /// Do not visit nested item-like things, but visit nested things
/// that are inside of an item-like. /// that are inside of an item-like.
/// ///
@ -12,8 +14,8 @@ use rustc_hir::intravisit::nested_filter::NestedFilter;
/// and to have the visitor that visits the contents of each item /// and to have the visitor that visits the contents of each item
/// using this setting. /// using this setting.
pub struct OnlyBodies(()); pub struct OnlyBodies(());
impl<'hir> NestedFilter<'hir> for OnlyBodies { impl<'tcx> NestedFilter<'tcx> for OnlyBodies {
type Map = crate::hir::map::Map<'hir>; type MaybeTyCtxt = TyCtxt<'tcx>;
const INTER: bool = false; const INTER: bool = false;
const INTRA: bool = true; const INTRA: bool = true;
} }
@ -24,8 +26,8 @@ impl<'hir> NestedFilter<'hir> for OnlyBodies {
/// process everything within their lexical context. Typically you /// process everything within their lexical context. Typically you
/// kick off the visit by doing `walk_krate()`. /// kick off the visit by doing `walk_krate()`.
pub struct All(()); pub struct All(());
impl<'hir> NestedFilter<'hir> for All { impl<'tcx> NestedFilter<'tcx> for All {
type Map = crate::hir::map::Map<'hir>; type MaybeTyCtxt = TyCtxt<'tcx>;
const INTER: bool = true; const INTER: bool = true;
const INTRA: bool = true; const INTRA: bool = true;
} }

View file

@ -3299,13 +3299,12 @@ define_print_and_forward_display! {
fn for_each_def(tcx: TyCtxt<'_>, mut collect_fn: impl for<'b> FnMut(&'b Ident, Namespace, DefId)) { fn for_each_def(tcx: TyCtxt<'_>, mut collect_fn: impl for<'b> FnMut(&'b Ident, Namespace, DefId)) {
// Iterate all local crate items no matter where they are defined. // Iterate all local crate items no matter where they are defined.
let hir = tcx.hir(); for id in tcx.hir_free_items() {
for id in hir.items() {
if matches!(tcx.def_kind(id.owner_id), DefKind::Use) { if matches!(tcx.def_kind(id.owner_id), DefKind::Use) {
continue; continue;
} }
let item = hir.item(id); let item = tcx.hir_item(id);
if item.ident.name == kw::Empty { if item.ident.name == kw::Empty {
continue; continue;
} }

View file

@ -267,7 +267,7 @@ pub(super) fn incoherent_impls_provider(tcx: TyCtxt<'_>, simp: SimplifiedType) -
pub(super) fn traits_provider(tcx: TyCtxt<'_>, _: LocalCrate) -> &[DefId] { pub(super) fn traits_provider(tcx: TyCtxt<'_>, _: LocalCrate) -> &[DefId] {
let mut traits = Vec::new(); let mut traits = Vec::new();
for id in tcx.hir().items() { for id in tcx.hir_free_items() {
if matches!(tcx.def_kind(id.owner_id), DefKind::Trait | DefKind::TraitAlias) { if matches!(tcx.def_kind(id.owner_id), DefKind::Trait | DefKind::TraitAlias) {
traits.push(id.owner_id.to_def_id()) traits.push(id.owner_id.to_def_id())
} }
@ -278,7 +278,7 @@ pub(super) fn traits_provider(tcx: TyCtxt<'_>, _: LocalCrate) -> &[DefId] {
pub(super) fn trait_impls_in_crate_provider(tcx: TyCtxt<'_>, _: LocalCrate) -> &[DefId] { pub(super) fn trait_impls_in_crate_provider(tcx: TyCtxt<'_>, _: LocalCrate) -> &[DefId] {
let mut trait_impls = Vec::new(); let mut trait_impls = Vec::new();
for id in tcx.hir().items() { for id in tcx.hir_free_items() {
if matches!(tcx.def_kind(id.owner_id), DefKind::Impl { .. }) if matches!(tcx.def_kind(id.owner_id), DefKind::Impl { .. })
&& tcx.impl_trait_ref(id.owner_id).is_some() && tcx.impl_trait_ref(id.owner_id).is_some()
{ {

View file

@ -53,7 +53,7 @@ impl<'tcx> Value<TyCtxt<'tcx>> for ty::Binder<'_, ty::FnSig<'_>> {
let arity = if let Some(frame) = cycle_error.cycle.get(0) let arity = if let Some(frame) = cycle_error.cycle.get(0)
&& frame.query.dep_kind == dep_kinds::fn_sig && frame.query.dep_kind == dep_kinds::fn_sig
&& let Some(def_id) = frame.query.def_id && let Some(def_id) = frame.query.def_id
&& let Some(node) = tcx.hir().get_if_local(def_id) && let Some(node) = tcx.hir_get_if_local(def_id)
&& let Some(sig) = node.fn_sig() && let Some(sig) = node.fn_sig()
{ {
sig.decl.inputs.len() sig.decl.inputs.len()

View file

@ -759,7 +759,7 @@ impl UnsafeOpKind {
}); });
let unsafe_not_inherited_note = if should_suggest { let unsafe_not_inherited_note = if should_suggest {
suggest_unsafe_block.then(|| { suggest_unsafe_block.then(|| {
let body_span = tcx.hir().body(parent_owner.body_id().unwrap()).value.span; let body_span = tcx.hir_body(parent_owner.body_id().unwrap()).value.span;
UnsafeNotInheritedLintNote { UnsafeNotInheritedLintNote {
signature_span: tcx.def_span(parent_id.def_id), signature_span: tcx.def_span(parent_id.def_id),
body_span, body_span,

View file

@ -601,8 +601,7 @@ impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for NonExhaustivePatternsTypeNo
let def_span = self let def_span = self
.cx .cx
.tcx .tcx
.hir() .hir_get_if_local(def.did())
.get_if_local(def.did())
.and_then(|node| node.ident()) .and_then(|node| node.ident())
.map(|ident| ident.span) .map(|ident| ident.span)
.unwrap_or_else(|| self.cx.tcx.def_span(def.did())); .unwrap_or_else(|| self.cx.tcx.def_span(def.did()));

View file

@ -1498,7 +1498,7 @@ fn report_adt_defined_here<'tcx>(
return None; return None;
}; };
let adt_def_span = let adt_def_span =
tcx.hir().get_if_local(def.did()).and_then(|node| node.ident()).map(|ident| ident.span); tcx.hir_get_if_local(def.did()).and_then(|node| node.ident()).map(|ident| ident.span);
let adt_def_span = if point_at_non_local_ty { let adt_def_span = if point_at_non_local_ty {
adt_def_span.unwrap_or_else(|| tcx.def_span(def.did())) adt_def_span.unwrap_or_else(|| tcx.def_span(def.did()))
} else { } else {

View file

@ -10,7 +10,6 @@ mod unexpand;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::intravisit::{Visitor, walk_expr}; use rustc_hir::intravisit::{Visitor, walk_expr};
use rustc_middle::hir::map::Map;
use rustc_middle::hir::nested_filter; use rustc_middle::hir::nested_filter;
use rustc_middle::mir::coverage::{ use rustc_middle::mir::coverage::{
CoverageKind, DecisionInfo, FunctionCoverageInfo, Mapping, MappingKind, CoverageKind, DecisionInfo, FunctionCoverageInfo, Mapping, MappingKind,
@ -291,7 +290,7 @@ fn extract_hir_info<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> ExtractedHir
let hir_node = tcx.hir_node_by_def_id(def_id); let hir_node = tcx.hir_node_by_def_id(def_id);
let fn_body_id = hir_node.body_id().expect("HIR node is a function with body"); let fn_body_id = hir_node.body_id().expect("HIR node is a function with body");
let hir_body = tcx.hir().body(fn_body_id); let hir_body = tcx.hir_body(fn_body_id);
let maybe_fn_sig = hir_node.fn_sig(); let maybe_fn_sig = hir_node.fn_sig();
let is_async_fn = maybe_fn_sig.is_some_and(|fn_sig| fn_sig.header.is_async()); let is_async_fn = maybe_fn_sig.is_some_and(|fn_sig| fn_sig.header.is_async());
@ -348,7 +347,7 @@ fn extract_hole_spans_from_hir<'tcx>(
hir_body: &hir::Body<'tcx>, hir_body: &hir::Body<'tcx>,
) -> Vec<Span> { ) -> Vec<Span> {
struct HolesVisitor<'hir, F> { struct HolesVisitor<'hir, F> {
hir: Map<'hir>, tcx: TyCtxt<'hir>,
visit_hole_span: F, visit_hole_span: F,
} }
@ -360,8 +359,8 @@ fn extract_hole_spans_from_hir<'tcx>(
/// items contained within them. /// items contained within them.
type NestedFilter = nested_filter::All; type NestedFilter = nested_filter::All;
fn nested_visit_map(&mut self) -> Self::Map { fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
self.hir self.tcx
} }
fn visit_item(&mut self, item: &'hir hir::Item<'hir>) { fn visit_item(&mut self, item: &'hir hir::Item<'hir>) {
@ -388,7 +387,7 @@ fn extract_hole_spans_from_hir<'tcx>(
let mut hole_spans = vec![]; let mut hole_spans = vec![];
let mut visitor = HolesVisitor { let mut visitor = HolesVisitor {
hir: tcx.hir(), tcx,
visit_hole_span: |hole_span| { visit_hole_span: |hole_span| {
// Discard any holes that aren't directly visible within the body span. // Discard any holes that aren't directly visible within the body span.
if body_span.contains(hole_span) && body_span.eq_ctxt(hole_span) { if body_span.contains(hole_span) && body_span.eq_ctxt(hole_span) {

View file

@ -478,7 +478,7 @@ fn collect_items_rec<'tcx>(
); );
recursion_depth_reset = None; recursion_depth_reset = None;
let item = tcx.hir().item(item_id); let item = tcx.hir_item(item_id);
if let hir::ItemKind::GlobalAsm(asm) = item.kind { if let hir::ItemKind::GlobalAsm(asm) = item.kind {
for (op, op_sp) in asm.operands { for (op, op_sp) in asm.operands {
match op { match op {

View file

@ -627,7 +627,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
fn check_object_lifetime_default(&self, hir_id: HirId) { fn check_object_lifetime_default(&self, hir_id: HirId) {
let tcx = self.tcx; let tcx = self.tcx;
if let Some(owner_id) = hir_id.as_owner() if let Some(owner_id) = hir_id.as_owner()
&& let Some(generics) = tcx.hir().get_generics(owner_id.def_id) && let Some(generics) = tcx.hir_get_generics(owner_id.def_id)
{ {
for p in generics.params { for p in generics.params {
let hir::GenericParamKind::Type { .. } = p.kind else { continue }; let hir::GenericParamKind::Type { .. } = p.kind else { continue };
@ -2606,8 +2606,8 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
impl<'tcx> Visitor<'tcx> for CheckAttrVisitor<'tcx> { impl<'tcx> Visitor<'tcx> for CheckAttrVisitor<'tcx> {
type NestedFilter = nested_filter::OnlyBodies; type NestedFilter = nested_filter::OnlyBodies;
fn nested_visit_map(&mut self) -> Self::Map { fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
self.tcx.hir() self.tcx
} }
fn visit_item(&mut self, item: &'tcx Item<'tcx>) { fn visit_item(&mut self, item: &'tcx Item<'tcx>) {
@ -2740,9 +2740,8 @@ fn check_invalid_crate_level_attr(tcx: TyCtxt<'_>, attrs: &[Attribute]) {
for attr_to_check in ATTRS_TO_CHECK { for attr_to_check in ATTRS_TO_CHECK {
if attr.has_name(*attr_to_check) { if attr.has_name(*attr_to_check) {
let item = tcx let item = tcx
.hir() .hir_free_items()
.items() .map(|id| tcx.hir_item(id))
.map(|id| tcx.hir().item(id))
.find(|item| !item.span.is_dummy()) // Skip prelude `use`s .find(|item| !item.span.is_dummy()) // Skip prelude `use`s
.map(|item| errors::ItemFollowingInnerAttr { .map(|item| errors::ItemFollowingInnerAttr {
span: item.ident.span, span: item.ident.span,

View file

@ -531,7 +531,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
fn impl_item_with_used_self(&mut self, impl_id: hir::ItemId, impl_item_id: LocalDefId) -> bool { fn impl_item_with_used_self(&mut self, impl_id: hir::ItemId, impl_item_id: LocalDefId) -> bool {
if let TyKind::Path(hir::QPath::Resolved(_, path)) = if let TyKind::Path(hir::QPath::Resolved(_, path)) =
self.tcx.hir().item(impl_id).expect_impl().self_ty.kind self.tcx.hir_item(impl_id).expect_impl().self_ty.kind
&& let Res::Def(def_kind, def_id) = path.res && let Res::Def(def_kind, def_id) = path.res
&& let Some(local_def_id) = def_id.as_local() && let Some(local_def_id) = def_id.as_local()
&& matches!(def_kind, DefKind::Struct | DefKind::Enum | DefKind::Union) && matches!(def_kind, DefKind::Struct | DefKind::Enum | DefKind::Union)
@ -559,7 +559,7 @@ impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> {
fn visit_nested_body(&mut self, body: hir::BodyId) { fn visit_nested_body(&mut self, body: hir::BodyId) {
let old_maybe_typeck_results = let old_maybe_typeck_results =
self.maybe_typeck_results.replace(self.tcx.typeck_body(body)); self.maybe_typeck_results.replace(self.tcx.typeck_body(body));
let body = self.tcx.hir().body(body); let body = self.tcx.hir_body(body);
self.visit_body(body); self.visit_body(body);
self.maybe_typeck_results = old_maybe_typeck_results; self.maybe_typeck_results = old_maybe_typeck_results;
} }
@ -750,7 +750,7 @@ fn check_item<'tcx>(
match tcx.def_kind(id.owner_id) { match tcx.def_kind(id.owner_id) {
DefKind::Enum => { DefKind::Enum => {
let item = tcx.hir().item(id); let item = tcx.hir_item(id);
if let hir::ItemKind::Enum(ref enum_def, _) = item.kind { if let hir::ItemKind::Enum(ref enum_def, _) = item.kind {
if let Some(comes_from_allow) = allow_dead_code { if let Some(comes_from_allow) = allow_dead_code {
worklist.extend( worklist.extend(
@ -772,7 +772,7 @@ fn check_item<'tcx>(
.iter() .iter()
.filter_map(|def_id| def_id.as_local()); .filter_map(|def_id| def_id.as_local());
let ty_is_pub = ty_ref_to_pub_struct(tcx, tcx.hir().item(id).expect_impl().self_ty); let ty_is_pub = ty_ref_to_pub_struct(tcx, tcx.hir_item(id).expect_impl().self_ty);
// And we access the Map here to get HirId from LocalDefId // And we access the Map here to get HirId from LocalDefId
for local_def_id in local_def_ids { for local_def_id in local_def_ids {
@ -805,7 +805,7 @@ fn check_item<'tcx>(
} }
} }
DefKind::Struct => { DefKind::Struct => {
let item = tcx.hir().item(id); let item = tcx.hir_item(id);
if let hir::ItemKind::Struct(ref variant_data, _) = item.kind if let hir::ItemKind::Struct(ref variant_data, _) = item.kind
&& let Some(ctor_def_id) = variant_data.ctor_def_id() && let Some(ctor_def_id) = variant_data.ctor_def_id()
{ {
@ -827,7 +827,7 @@ fn check_trait_item(
) { ) {
use hir::TraitItemKind::{Const, Fn}; use hir::TraitItemKind::{Const, Fn};
if matches!(tcx.def_kind(id.owner_id), DefKind::AssocConst | DefKind::AssocFn) { if matches!(tcx.def_kind(id.owner_id), DefKind::AssocConst | DefKind::AssocFn) {
let trait_item = tcx.hir().trait_item(id); let trait_item = tcx.hir_trait_item(id);
if matches!(trait_item.kind, Const(_, Some(_)) | Fn(..)) if matches!(trait_item.kind, Const(_, Some(_)) | Fn(..))
&& let Some(comes_from_allow) = && let Some(comes_from_allow) =
has_allow_dead_code_or_lang_attr(tcx, trait_item.owner_id.def_id) has_allow_dead_code_or_lang_attr(tcx, trait_item.owner_id.def_id)

View file

@ -37,7 +37,7 @@ fn entry_fn(tcx: TyCtxt<'_>, (): ()) -> Option<(DefId, EntryFnType)> {
let mut ctxt = EntryContext { tcx, rustc_main_fn: None, non_main_fns: Vec::new() }; let mut ctxt = EntryContext { tcx, rustc_main_fn: None, non_main_fns: Vec::new() };
for id in tcx.hir().items() { for id in tcx.hir_free_items() {
check_and_search_item(id, &mut ctxt); check_and_search_item(id, &mut ctxt);
} }

View file

@ -61,7 +61,7 @@ impl<'a, 'hir> HirIdValidator<'a, 'hir> {
if max != self.hir_ids_seen.len() - 1 { if max != self.hir_ids_seen.len() - 1 {
let hir = self.tcx.hir(); let hir = self.tcx.hir();
let pretty_owner = hir.def_path(owner.def_id).to_string_no_crate_verbose(); let pretty_owner = self.tcx.hir_def_path(owner.def_id).to_string_no_crate_verbose();
let missing_items: Vec<_> = (0..=max as u32) let missing_items: Vec<_> = (0..=max as u32)
.map(|i| ItemLocalId::from_u32(i)) .map(|i| ItemLocalId::from_u32(i))
@ -105,8 +105,8 @@ impl<'a, 'hir> HirIdValidator<'a, 'hir> {
impl<'a, 'hir> intravisit::Visitor<'hir> for HirIdValidator<'a, 'hir> { impl<'a, 'hir> intravisit::Visitor<'hir> for HirIdValidator<'a, 'hir> {
type NestedFilter = nested_filter::OnlyBodies; type NestedFilter = nested_filter::OnlyBodies;
fn nested_visit_map(&mut self) -> Self::Map { fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
self.tcx.hir() self.tcx
} }
fn visit_nested_item(&mut self, id: hir::ItemId) { fn visit_nested_item(&mut self, id: hir::ItemId) {
@ -138,8 +138,8 @@ impl<'a, 'hir> intravisit::Visitor<'hir> for HirIdValidator<'a, 'hir> {
format!( format!(
"HirIdValidator: The recorded owner of {} is {} instead of {}", "HirIdValidator: The recorded owner of {} is {} instead of {}",
self.tcx.hir().node_to_string(hir_id), self.tcx.hir().node_to_string(hir_id),
self.tcx.hir().def_path(hir_id.owner.def_id).to_string_no_crate_verbose(), self.tcx.hir_def_path(hir_id.owner.def_id).to_string_no_crate_verbose(),
self.tcx.hir().def_path(owner.def_id).to_string_no_crate_verbose() self.tcx.hir_def_path(owner.def_id).to_string_no_crate_verbose()
) )
}); });
} }

View file

@ -7,7 +7,6 @@ use rustc_ast::{self as ast, NodeId, visit as ast_visit};
use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::thousands::format_with_underscores; use rustc_data_structures::thousands::format_with_underscores;
use rustc_hir::{self as hir, AmbigArg, HirId, intravisit as hir_visit}; use rustc_hir::{self as hir, AmbigArg, HirId, intravisit as hir_visit};
use rustc_middle::hir::map::Map;
use rustc_middle::ty::TyCtxt; use rustc_middle::ty::TyCtxt;
use rustc_span::Span; use rustc_span::Span;
use rustc_span::def_id::LocalDefId; use rustc_span::def_id::LocalDefId;
@ -56,17 +55,14 @@ impl Node {
/// a `visit_*` method for, and so we cannot measure these, which is /// a `visit_*` method for, and so we cannot measure these, which is
/// unfortunate. /// unfortunate.
struct StatCollector<'k> { struct StatCollector<'k> {
krate: Option<Map<'k>>, tcx: Option<TyCtxt<'k>>,
nodes: FxHashMap<&'static str, Node>, nodes: FxHashMap<&'static str, Node>,
seen: FxHashSet<HirId>, seen: FxHashSet<HirId>,
} }
pub fn print_hir_stats(tcx: TyCtxt<'_>) { pub fn print_hir_stats(tcx: TyCtxt<'_>) {
let mut collector = StatCollector { let mut collector =
krate: Some(tcx.hir()), StatCollector { tcx: Some(tcx), nodes: FxHashMap::default(), seen: FxHashSet::default() };
nodes: FxHashMap::default(),
seen: FxHashSet::default(),
};
tcx.hir().walk_toplevel_module(&mut collector); tcx.hir().walk_toplevel_module(&mut collector);
tcx.hir().walk_attributes(&mut collector); tcx.hir().walk_attributes(&mut collector);
collector.print("HIR STATS", "hir-stats"); collector.print("HIR STATS", "hir-stats");
@ -76,7 +72,7 @@ pub fn print_ast_stats(krate: &ast::Crate, title: &str, prefix: &str) {
use rustc_ast::visit::Visitor; use rustc_ast::visit::Visitor;
let mut collector = let mut collector =
StatCollector { krate: None, nodes: FxHashMap::default(), seen: FxHashSet::default() }; StatCollector { tcx: None, nodes: FxHashMap::default(), seen: FxHashSet::default() };
collector.visit_crate(krate); collector.visit_crate(krate);
collector.print(title, prefix); collector.print(title, prefix);
} }
@ -205,27 +201,27 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
} }
fn visit_nested_item(&mut self, id: hir::ItemId) { fn visit_nested_item(&mut self, id: hir::ItemId) {
let nested_item = self.krate.unwrap().item(id); let nested_item = self.tcx.unwrap().hir_item(id);
self.visit_item(nested_item) self.visit_item(nested_item)
} }
fn visit_nested_trait_item(&mut self, trait_item_id: hir::TraitItemId) { fn visit_nested_trait_item(&mut self, trait_item_id: hir::TraitItemId) {
let nested_trait_item = self.krate.unwrap().trait_item(trait_item_id); let nested_trait_item = self.tcx.unwrap().hir_trait_item(trait_item_id);
self.visit_trait_item(nested_trait_item) self.visit_trait_item(nested_trait_item)
} }
fn visit_nested_impl_item(&mut self, impl_item_id: hir::ImplItemId) { fn visit_nested_impl_item(&mut self, impl_item_id: hir::ImplItemId) {
let nested_impl_item = self.krate.unwrap().impl_item(impl_item_id); let nested_impl_item = self.tcx.unwrap().hir_impl_item(impl_item_id);
self.visit_impl_item(nested_impl_item) self.visit_impl_item(nested_impl_item)
} }
fn visit_nested_foreign_item(&mut self, id: hir::ForeignItemId) { fn visit_nested_foreign_item(&mut self, id: hir::ForeignItemId) {
let nested_foreign_item = self.krate.unwrap().foreign_item(id); let nested_foreign_item = self.tcx.unwrap().hir_foreign_item(id);
self.visit_foreign_item(nested_foreign_item); self.visit_foreign_item(nested_foreign_item);
} }
fn visit_nested_body(&mut self, body_id: hir::BodyId) { fn visit_nested_body(&mut self, body_id: hir::BodyId) {
let nested_body = self.krate.unwrap().body(body_id); let nested_body = self.tcx.unwrap().hir_body(body_id);
self.visit_body(nested_body) self.visit_body(nested_body)
} }

View file

@ -129,8 +129,8 @@ impl<'tcx> LibFeatureCollector<'tcx> {
impl<'tcx> Visitor<'tcx> for LibFeatureCollector<'tcx> { impl<'tcx> Visitor<'tcx> for LibFeatureCollector<'tcx> {
type NestedFilter = nested_filter::All; type NestedFilter = nested_filter::All;
fn nested_visit_map(&mut self) -> Self::Map { fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
self.tcx.hir() self.tcx
} }
fn visit_attribute(&mut self, attr: &'tcx Attribute) { fn visit_attribute(&mut self, attr: &'tcx Attribute) {

View file

@ -87,8 +87,8 @@ pub(crate) fn provide(providers: &mut Providers) {
impl<'hir> Visitor<'hir> for CheckLoopVisitor<'hir> { impl<'hir> Visitor<'hir> for CheckLoopVisitor<'hir> {
type NestedFilter = nested_filter::OnlyBodies; type NestedFilter = nested_filter::OnlyBodies;
fn nested_visit_map(&mut self) -> Self::Map { fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
self.tcx.hir() self.tcx
} }
fn visit_anon_const(&mut self, c: &'hir hir::AnonConst) { fn visit_anon_const(&mut self, c: &'hir hir::AnonConst) {

View file

@ -45,7 +45,7 @@ fn check_mod_naked_functions(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) {
_ => continue, _ => continue,
}; };
let body = tcx.hir().body(body_id); let body = tcx.hir_body(body_id);
if tcx.has_attr(def_id, sym::naked) { if tcx.has_attr(def_id, sym::naked) {
check_abi(tcx, def_id, fn_header.abi); check_abi(tcx, def_id, fn_header.abi);
@ -259,8 +259,8 @@ struct CheckNakedAsmInNakedFn<'tcx> {
impl<'tcx> Visitor<'tcx> for CheckNakedAsmInNakedFn<'tcx> { impl<'tcx> Visitor<'tcx> for CheckNakedAsmInNakedFn<'tcx> {
type NestedFilter = OnlyBodies; type NestedFilter = OnlyBodies;
fn nested_visit_map(&mut self) -> Self::Map { fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
self.tcx.hir() self.tcx
} }
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) { fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) {

View file

@ -66,7 +66,7 @@ impl<'tcx> Visitor<'tcx> for ReachableContext<'tcx> {
fn visit_nested_body(&mut self, body: hir::BodyId) { fn visit_nested_body(&mut self, body: hir::BodyId) {
let old_maybe_typeck_results = let old_maybe_typeck_results =
self.maybe_typeck_results.replace(self.tcx.typeck_body(body)); self.maybe_typeck_results.replace(self.tcx.typeck_body(body));
let body = self.tcx.hir().body(body); let body = self.tcx.hir_body(body);
self.visit_body(body); self.visit_body(body);
self.maybe_typeck_results = old_maybe_typeck_results; self.maybe_typeck_results = old_maybe_typeck_results;
} }

View file

@ -394,8 +394,8 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
/// deep-walking. /// deep-walking.
type NestedFilter = nested_filter::All; type NestedFilter = nested_filter::All;
fn nested_visit_map(&mut self) -> Self::Map { fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
self.tcx.hir() self.tcx
} }
fn visit_item(&mut self, i: &'tcx Item<'tcx>) { fn visit_item(&mut self, i: &'tcx Item<'tcx>) {
@ -616,8 +616,8 @@ impl<'tcx> MissingStabilityAnnotations<'tcx> {
impl<'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'tcx> { impl<'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'tcx> {
type NestedFilter = nested_filter::OnlyBodies; type NestedFilter = nested_filter::OnlyBodies;
fn nested_visit_map(&mut self) -> Self::Map { fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
self.tcx.hir() self.tcx
} }
fn visit_item(&mut self, i: &'tcx Item<'tcx>) { fn visit_item(&mut self, i: &'tcx Item<'tcx>) {
@ -756,8 +756,8 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> {
/// Because stability levels are scoped lexically, we want to walk /// Because stability levels are scoped lexically, we want to walk
/// nested items in the context of the outer item, so enable /// nested items in the context of the outer item, so enable
/// deep-walking. /// deep-walking.
fn nested_visit_map(&mut self) -> Self::Map { fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
self.tcx.hir() self.tcx
} }
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) { fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {

View file

@ -1036,7 +1036,7 @@ impl<'tcx> Visitor<'tcx> for NamePrivacyVisitor<'tcx> {
return; return;
} }
let old_maybe_typeck_results = self.maybe_typeck_results.replace(new_typeck_results); let old_maybe_typeck_results = self.maybe_typeck_results.replace(new_typeck_results);
self.visit_body(self.tcx.hir().body(body_id)); self.visit_body(self.tcx.hir_body(body_id));
self.maybe_typeck_results = old_maybe_typeck_results; self.maybe_typeck_results = old_maybe_typeck_results;
} }
@ -1161,7 +1161,7 @@ impl<'tcx> Visitor<'tcx> for TypePrivacyVisitor<'tcx> {
fn visit_nested_body(&mut self, body_id: hir::BodyId) { fn visit_nested_body(&mut self, body_id: hir::BodyId) {
let old_maybe_typeck_results = let old_maybe_typeck_results =
self.maybe_typeck_results.replace(self.tcx.typeck_body(body_id)); self.maybe_typeck_results.replace(self.tcx.typeck_body(body_id));
self.visit_body(self.tcx.hir().body(body_id)); self.visit_body(self.tcx.hir_body(body_id));
self.maybe_typeck_results = old_maybe_typeck_results; self.maybe_typeck_results = old_maybe_typeck_results;
} }
@ -1599,7 +1599,7 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'_, 'tcx> {
self.check(def_id, item_visibility, effective_vis).generics().bounds(); self.check(def_id, item_visibility, effective_vis).generics().bounds();
} }
DefKind::Trait => { DefKind::Trait => {
let item = tcx.hir().item(id); let item = tcx.hir_item(id);
if let hir::ItemKind::Trait(.., trait_item_refs) = item.kind { if let hir::ItemKind::Trait(.., trait_item_refs) = item.kind {
self.check_unnameable(item.owner_id.def_id, effective_vis); self.check_unnameable(item.owner_id.def_id, effective_vis);
@ -1630,7 +1630,7 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'_, 'tcx> {
self.check(def_id, item_visibility, effective_vis).generics().predicates(); self.check(def_id, item_visibility, effective_vis).generics().predicates();
} }
DefKind::Enum => { DefKind::Enum => {
let item = tcx.hir().item(id); let item = tcx.hir_item(id);
if let hir::ItemKind::Enum(ref def, _) = item.kind { if let hir::ItemKind::Enum(ref def, _) = item.kind {
self.check_unnameable(item.owner_id.def_id, effective_vis); self.check_unnameable(item.owner_id.def_id, effective_vis);
@ -1647,10 +1647,10 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'_, 'tcx> {
} }
// Subitems of foreign modules have their own publicity. // Subitems of foreign modules have their own publicity.
DefKind::ForeignMod => { DefKind::ForeignMod => {
let item = tcx.hir().item(id); let item = tcx.hir_item(id);
if let hir::ItemKind::ForeignMod { items, .. } = item.kind { if let hir::ItemKind::ForeignMod { items, .. } = item.kind {
for foreign_item in items { for foreign_item in items {
let foreign_item = tcx.hir().foreign_item(foreign_item.id); let foreign_item = tcx.hir_foreign_item(foreign_item.id);
let ev = self.get(foreign_item.owner_id.def_id); let ev = self.get(foreign_item.owner_id.def_id);
let vis = tcx.local_visibility(foreign_item.owner_id.def_id); let vis = tcx.local_visibility(foreign_item.owner_id.def_id);
@ -1668,7 +1668,7 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'_, 'tcx> {
} }
// Subitems of structs and unions have their own publicity. // Subitems of structs and unions have their own publicity.
DefKind::Struct | DefKind::Union => { DefKind::Struct | DefKind::Union => {
let item = tcx.hir().item(id); let item = tcx.hir_item(id);
if let hir::ItemKind::Struct(ref struct_def, _) if let hir::ItemKind::Struct(ref struct_def, _)
| hir::ItemKind::Union(ref struct_def, _) = item.kind | hir::ItemKind::Union(ref struct_def, _) = item.kind
{ {
@ -1695,7 +1695,7 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'_, 'tcx> {
// A trait impl is public when both its type and its trait are public // A trait impl is public when both its type and its trait are public
// Subitems of trait impls have inherited publicity. // Subitems of trait impls have inherited publicity.
DefKind::Impl { .. } => { DefKind::Impl { .. } => {
let item = tcx.hir().item(id); let item = tcx.hir_item(id);
if let hir::ItemKind::Impl(impl_) = item.kind { if let hir::ItemKind::Impl(impl_) = item.kind {
let impl_vis = ty::Visibility::of_impl::<false>( let impl_vis = ty::Visibility::of_impl::<false>(
item.owner_id.def_id, item.owner_id.def_id,
@ -1788,7 +1788,7 @@ fn check_mod_privacy(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) {
} }
for id in module.free_items() { for id in module.free_items() {
if let ItemKind::Impl(i) = tcx.hir().item(id).kind { if let ItemKind::Impl(i) = tcx.hir_item(id).kind {
if let Some(item) = i.of_trait { if let Some(item) = i.of_trait {
let trait_ref = tcx.impl_trait_ref(id.owner_id.def_id).unwrap(); let trait_ref = tcx.impl_trait_ref(id.owner_id.def_id).unwrap();
let trait_ref = trait_ref.instantiate_identity(); let trait_ref = trait_ref.instantiate_identity();
@ -1885,7 +1885,7 @@ fn check_private_in_public(tcx: TyCtxt<'_>, (): ()) {
// Check for private types in public interfaces. // Check for private types in public interfaces.
let mut checker = PrivateItemsInPublicInterfacesChecker { tcx, effective_visibilities }; let mut checker = PrivateItemsInPublicInterfacesChecker { tcx, effective_visibilities };
for id in tcx.hir().items() { for id in tcx.hir_free_items() {
checker.check_item(id); checker.check_item(id);
} }
} }

View file

@ -1989,7 +1989,6 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
trace: &TypeTrace<'tcx>, trace: &TypeTrace<'tcx>,
span: Span, span: Span,
) -> Option<TypeErrorAdditionalDiags> { ) -> Option<TypeErrorAdditionalDiags> {
let hir = self.tcx.hir();
let TypeError::ArraySize(sz) = terr else { let TypeError::ArraySize(sz) = terr else {
return None; return None;
}; };
@ -1997,7 +1996,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
hir::Node::Item(hir::Item { hir::Node::Item(hir::Item {
kind: hir::ItemKind::Fn { body: body_id, .. }, .. kind: hir::ItemKind::Fn { body: body_id, .. }, ..
}) => { }) => {
let body = hir.body(*body_id); let body = self.tcx.hir_body(*body_id);
struct LetVisitor { struct LetVisitor {
span: Span, span: Span,
} }

View file

@ -1202,8 +1202,8 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
impl<'a, 'tcx> Visitor<'tcx> for FindInferSourceVisitor<'a, 'tcx> { impl<'a, 'tcx> Visitor<'tcx> for FindInferSourceVisitor<'a, 'tcx> {
type NestedFilter = nested_filter::OnlyBodies; type NestedFilter = nested_filter::OnlyBodies;
fn nested_visit_map(&mut self) -> Self::Map { fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
self.tecx.tcx.hir() self.tecx.tcx
} }
fn visit_local(&mut self, local: &'tcx LetStmt<'tcx>) { fn visit_local(&mut self, local: &'tcx LetStmt<'tcx>) {
@ -1320,7 +1320,7 @@ impl<'a, 'tcx> Visitor<'tcx> for FindInferSourceVisitor<'a, 'tcx> {
{ {
let output = args.as_closure().sig().output().skip_binder(); let output = args.as_closure().sig().output().skip_binder();
if self.generic_arg_contains_target(output.into()) { if self.generic_arg_contains_target(output.into()) {
let body = self.tecx.tcx.hir().body(body); let body = self.tecx.tcx.hir_body(body);
let should_wrap_expr = if matches!(body.value.kind, ExprKind::Block(..)) { let should_wrap_expr = if matches!(body.value.kind, ExprKind::Block(..)) {
None None
} else { } else {

View file

@ -3,7 +3,6 @@ use core::ops::ControlFlow;
use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::intravisit::{self, Visitor, VisitorExt}; use rustc_hir::intravisit::{self, Visitor, VisitorExt};
use rustc_hir::{self as hir, AmbigArg}; use rustc_hir::{self as hir, AmbigArg};
use rustc_middle::hir::map::Map;
use rustc_middle::hir::nested_filter; use rustc_middle::hir::nested_filter;
use rustc_middle::middle::resolve_bound_vars as rbv; use rustc_middle::middle::resolve_bound_vars as rbv;
use rustc_middle::ty::{self, Region, TyCtxt}; use rustc_middle::ty::{self, Region, TyCtxt};
@ -70,8 +69,8 @@ impl<'tcx> Visitor<'tcx> for FindNestedTypeVisitor<'tcx> {
type Result = ControlFlow<&'tcx hir::Ty<'tcx>>; type Result = ControlFlow<&'tcx hir::Ty<'tcx>>;
type NestedFilter = nested_filter::OnlyBodies; type NestedFilter = nested_filter::OnlyBodies;
fn nested_visit_map(&mut self) -> Self::Map { fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
self.tcx.hir() self.tcx
} }
fn visit_ty(&mut self, arg: &'tcx hir::Ty<'tcx, AmbigArg>) -> Self::Result { fn visit_ty(&mut self, arg: &'tcx hir::Ty<'tcx, AmbigArg>) -> Self::Result {
@ -176,8 +175,8 @@ impl<'tcx> Visitor<'tcx> for TyPathVisitor<'tcx> {
type Result = ControlFlow<()>; type Result = ControlFlow<()>;
type NestedFilter = nested_filter::OnlyBodies; type NestedFilter = nested_filter::OnlyBodies;
fn nested_visit_map(&mut self) -> Map<'tcx> { fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
self.tcx.hir() self.tcx
} }
fn visit_lifetime(&mut self, lifetime: &hir::Lifetime) -> Self::Result { fn visit_lifetime(&mut self, lifetime: &hir::Lifetime) -> Self::Result {

View file

@ -66,7 +66,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
); );
let mut impl_span = None; let mut impl_span = None;
let mut implicit_static_lifetimes = Vec::new(); let mut implicit_static_lifetimes = Vec::new();
if let Some(impl_node) = self.tcx().hir().get_if_local(*impl_def_id) { if let Some(impl_node) = self.tcx().hir_get_if_local(*impl_def_id) {
// If an impl is local, then maybe this isn't what they want. Try to // If an impl is local, then maybe this isn't what they want. Try to
// be as helpful as possible with implicit lifetimes. // be as helpful as possible with implicit lifetimes.

View file

@ -318,7 +318,7 @@ pub fn suggest_new_region_bound(
} else { } else {
// get a lifetime name of existing named lifetimes if any // get a lifetime name of existing named lifetimes if any
let existing_lt_name = if let Some(id) = scope_def_id let existing_lt_name = if let Some(id) = scope_def_id
&& let Some(generics) = tcx.hir().get_generics(id) && let Some(generics) = tcx.hir_get_generics(id)
&& let named_lifetimes = generics && let named_lifetimes = generics
.params .params
.iter() .iter()
@ -349,7 +349,7 @@ pub fn suggest_new_region_bound(
// if there are more than one elided lifetimes in inputs, the explicit `'_` lifetime cannot be used. // if there are more than one elided lifetimes in inputs, the explicit `'_` lifetime cannot be used.
// introducing a new lifetime `'a` or making use of one from existing named lifetimes if any // introducing a new lifetime `'a` or making use of one from existing named lifetimes if any
if let Some(id) = scope_def_id if let Some(id) = scope_def_id
&& let Some(generics) = tcx.hir().get_generics(id) && let Some(generics) = tcx.hir_get_generics(id)
&& let mut spans_suggs = && let mut spans_suggs =
make_elided_region_spans_suggs(name, generics.params.iter()) make_elided_region_spans_suggs(name, generics.params.iter())
&& spans_suggs.len() > 1 && spans_suggs.len() > 1
@ -470,7 +470,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
def_id: DefId, def_id: DefId,
trait_objects: &FxIndexSet<DefId>, trait_objects: &FxIndexSet<DefId>,
) -> Option<(Ident, &'tcx hir::Ty<'tcx>)> { ) -> Option<(Ident, &'tcx hir::Ty<'tcx>)> {
match tcx.hir().get_if_local(def_id)? { match tcx.hir_get_if_local(def_id)? {
Node::ImplItem(impl_item) => { Node::ImplItem(impl_item) => {
let impl_did = tcx.hir().get_parent_item(impl_item.hir_id()); let impl_did = tcx.hir().get_parent_item(impl_item.hir_id());
if let hir::OwnerNode::Item(Item { if let hir::OwnerNode::Item(Item {

View file

@ -133,8 +133,8 @@ struct TypeParamSpanVisitor<'tcx> {
impl<'tcx> Visitor<'tcx> for TypeParamSpanVisitor<'tcx> { impl<'tcx> Visitor<'tcx> for TypeParamSpanVisitor<'tcx> {
type NestedFilter = nested_filter::OnlyBodies; type NestedFilter = nested_filter::OnlyBodies;
fn nested_visit_map(&mut self) -> Self::Map { fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
self.tcx.hir() self.tcx
} }
fn visit_ty(&mut self, arg: &'tcx hir::Ty<'tcx, AmbigArg>) { fn visit_ty(&mut self, arg: &'tcx hir::Ty<'tcx, AmbigArg>) {

View file

@ -543,7 +543,7 @@ impl<T> Trait<T> for X {
let tcx = self.tcx; let tcx = self.tcx;
let assoc = tcx.associated_item(proj_ty.def_id); let assoc = tcx.associated_item(proj_ty.def_id);
let (trait_ref, assoc_args) = proj_ty.trait_ref_and_own_args(tcx); let (trait_ref, assoc_args) = proj_ty.trait_ref_and_own_args(tcx);
let Some(item) = tcx.hir().get_if_local(body_owner_def_id) else { let Some(item) = tcx.hir_get_if_local(body_owner_def_id) else {
return false; return false;
}; };
let Some(hir_generics) = item.generics() else { let Some(hir_generics) = item.generics() else {
@ -625,7 +625,7 @@ impl<T> Trait<T> for X {
) )
}; };
let body_owner = tcx.hir().get_if_local(body_owner_def_id); let body_owner = tcx.hir_get_if_local(body_owner_def_id);
let current_method_ident = body_owner.and_then(|n| n.ident()).map(|i| i.name); let current_method_ident = body_owner.and_then(|n| n.ident()).map(|i| i.name);
// We don't want to suggest calling an assoc fn in a scope where that isn't feasible. // We don't want to suggest calling an assoc fn in a scope where that isn't feasible.

View file

@ -487,7 +487,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
&format!("`{sup}: {sub}`"), &format!("`{sup}: {sub}`"),
); );
// We should only suggest rewriting the `where` clause if the predicate is within that `where` clause // We should only suggest rewriting the `where` clause if the predicate is within that `where` clause
if let Some(generics) = self.tcx.hir().get_generics(impl_item_def_id) if let Some(generics) = self.tcx.hir_get_generics(impl_item_def_id)
&& generics.where_clause_span.contains(span) && generics.where_clause_span.contains(span)
{ {
self.suggest_copy_trait_method_bounds( self.suggest_copy_trait_method_bounds(
@ -590,7 +590,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
return; return;
}; };
let Some(generics) = self.tcx.hir().get_generics(impl_item_def_id) else { let Some(generics) = self.tcx.hir_get_generics(impl_item_def_id) else {
return; return;
}; };
@ -763,7 +763,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
// Get the `hir::Param` to verify whether it already has any bounds. // Get the `hir::Param` to verify whether it already has any bounds.
// We do this to avoid suggesting code that ends up as `T: 'a'b`, // We do this to avoid suggesting code that ends up as `T: 'a'b`,
// instead we suggest `T: 'a + 'b` in that case. // instead we suggest `T: 'a + 'b` in that case.
let hir_generics = self.tcx.hir().get_generics(scope).unwrap(); let hir_generics = self.tcx.hir_get_generics(scope).unwrap();
let sugg_span = match hir_generics.bounds_span_for_suggestions(def_id) { let sugg_span = match hir_generics.bounds_span_for_suggestions(def_id) {
Some((span, open_paren_sp)) => Some((span, true, open_paren_sp)), Some((span, open_paren_sp)) => Some((span, true, open_paren_sp)),
// If `param` corresponds to `Self`, no usable suggestion span. // If `param` corresponds to `Self`, no usable suggestion span.
@ -822,7 +822,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
{ {
// The lifetime found in the `impl` is longer than the one on the RPITIT. // The lifetime found in the `impl` is longer than the one on the RPITIT.
// Do not suggest `<Type as Trait>::{opaque}: 'static`. // Do not suggest `<Type as Trait>::{opaque}: 'static`.
} else if let Some(generics) = self.tcx.hir().get_generics(suggestion_scope) { } else if let Some(generics) = self.tcx.hir_get_generics(suggestion_scope) {
let pred = format!("{bound_kind}: {lt_name}"); let pred = format!("{bound_kind}: {lt_name}");
let suggestion = format!("{} {}", generics.add_where_or_trailing_comma(), pred); let suggestion = format!("{} {}", generics.add_where_or_trailing_comma(), pred);
suggs.push((generics.tail_span_for_predicate_suggestion(), suggestion)) suggs.push((generics.tail_span_for_predicate_suggestion(), suggestion))
@ -907,7 +907,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
hir::OwnerNode::Synthetic => unreachable!(), hir::OwnerNode::Synthetic => unreachable!(),
} }
let ast_generics = self.tcx.hir().get_generics(lifetime_scope).unwrap(); let ast_generics = self.tcx.hir_get_generics(lifetime_scope).unwrap();
let sugg = ast_generics let sugg = ast_generics
.span_for_lifetime_suggestion() .span_for_lifetime_suggestion()
.map(|span| (span, format!("{new_lt}, "))) .map(|span| (span, format!("{new_lt}, ")))
@ -1382,7 +1382,7 @@ fn suggest_precise_capturing<'tcx>(
new_params += name_as_bounds; new_params += name_as_bounds;
} }
let Some(generics) = tcx.hir().get_generics(fn_def_id) else { let Some(generics) = tcx.hir_get_generics(fn_def_id) else {
// This shouldn't happen, but don't ICE. // This shouldn't happen, but don't ICE.
return; return;
}; };

View file

@ -649,7 +649,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
else { else {
return; return;
}; };
let hir::Body { params, .. } = self.tcx.hir().body(*body); let hir::Body { params, .. } = self.tcx.hir_body(*body);
// 1. Get the args of the closure. // 1. Get the args of the closure.
// 2. Assume exp_found is FnOnce / FnMut / Fn, we can extract function parameters from [1]. // 2. Assume exp_found is FnOnce / FnMut / Fn, we can extract function parameters from [1].
@ -846,7 +846,6 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
true true
}; };
let hir = self.tcx.hir();
for stmt in blk.stmts.iter().rev() { for stmt in blk.stmts.iter().rev() {
let hir::StmtKind::Let(local) = &stmt.kind else { let hir::StmtKind::Let(local) = &stmt.kind else {
continue; continue;
@ -871,7 +870,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
kind: hir::ExprKind::Closure(hir::Closure { body, .. }), kind: hir::ExprKind::Closure(hir::Closure { body, .. }),
.. ..
}) => { }) => {
for param in hir.body(*body).params { for param in self.tcx.hir_body(*body).params {
param.pat.walk(&mut find_compatible_candidates); param.pat.walk(&mut find_compatible_candidates);
} }
} }

View file

@ -925,7 +925,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
let hir_id = self.tcx.local_def_id_to_hir_id(obligation.cause.body_id); let hir_id = self.tcx.local_def_id_to_hir_id(obligation.cause.body_id);
let Some(body_id) = self.tcx.hir_node(hir_id).body_id() else { return false }; let Some(body_id) = self.tcx.hir_node(hir_id).body_id() else { return false };
let ControlFlow::Break(expr) = let ControlFlow::Break(expr) =
(FindMethodSubexprOfTry { search_span: span }).visit_body(self.tcx.hir().body(body_id)) (FindMethodSubexprOfTry { search_span: span }).visit_body(self.tcx.hir_body(body_id))
else { else {
return false; return false;
}; };
@ -1012,7 +1012,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
&& let [arg] = args && let [arg] = args
&& let hir::ExprKind::Closure(closure) = arg.kind && let hir::ExprKind::Closure(closure) = arg.kind
// The closure has a block for its body with no tail expression // The closure has a block for its body with no tail expression
&& let body = self.tcx.hir().body(closure.body) && let body = self.tcx.hir_body(closure.body)
&& let hir::ExprKind::Block(block, _) = body.value.kind && let hir::ExprKind::Block(block, _) = body.value.kind
&& let None = block.expr && let None = block.expr
// The last statement is of a type that can be converted to the return error type // The last statement is of a type that can be converted to the return error type
@ -1447,7 +1447,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
let [associated_item]: &[ty::AssocItem] = &associated_items[..] else { let [associated_item]: &[ty::AssocItem] = &associated_items[..] else {
return None; return None;
}; };
match self.tcx.hir().get_if_local(associated_item.def_id) { match self.tcx.hir_get_if_local(associated_item.def_id) {
Some( Some(
hir::Node::TraitItem(hir::TraitItem { hir::Node::TraitItem(hir::TraitItem {
kind: hir::TraitItemKind::Type(_, Some(ty)), kind: hir::TraitItemKind::Type(_, Some(ty)),
@ -1514,7 +1514,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
span = match fn_decl.output { span = match fn_decl.output {
hir::FnRetTy::Return(ty) => ty.span, hir::FnRetTy::Return(ty) => ty.span,
hir::FnRetTy::DefaultReturn(_) => { hir::FnRetTy::DefaultReturn(_) => {
let body = self.tcx.hir().body(id); let body = self.tcx.hir_body(id);
match body.value.kind { match body.value.kind {
hir::ExprKind::Block( hir::ExprKind::Block(
hir::Block { expr: Some(expr), .. }, hir::Block { expr: Some(expr), .. },
@ -2850,7 +2850,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
_ => None, _ => None,
}; };
let found_node = found_did.and_then(|did| self.tcx.hir().get_if_local(did)); let found_node = found_did.and_then(|did| self.tcx.hir_get_if_local(did));
let found_span = found_did.and_then(|did| self.tcx.hir().span_if_local(did)); let found_span = found_did.and_then(|did| self.tcx.hir().span_if_local(did));
if !self.reported_signature_mismatch.borrow_mut().insert((span, found_span)) { if !self.reported_signature_mismatch.borrow_mut().insert((span, found_span)) {
@ -2896,7 +2896,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
if found.len() != expected.len() { if found.len() != expected.len() {
let (closure_span, closure_arg_span, found) = found_did let (closure_span, closure_arg_span, found) = found_did
.and_then(|did| { .and_then(|did| {
let node = self.tcx.hir().get_if_local(did)?; let node = self.tcx.hir_get_if_local(did)?;
let (found_span, closure_arg_span, found) = self.get_fn_like_arguments(node)?; let (found_span, closure_arg_span, found) = self.get_fn_like_arguments(node)?;
Some((Some(found_span), closure_arg_span, found)) Some((Some(found_span), closure_arg_span, found))
}) })
@ -2946,7 +2946,8 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
}) => ( }) => (
fn_decl_span, fn_decl_span,
fn_arg_span, fn_arg_span,
hir.body(body) self.tcx
.hir_body(body)
.params .params
.iter() .iter()
.map(|arg| { .map(|arg| {
@ -3208,7 +3209,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
Some(obligation.cause.body_id) Some(obligation.cause.body_id)
}; };
if let Some(def_id) = def_id if let Some(def_id) = def_id
&& let Some(generics) = self.tcx.hir().get_generics(def_id) && let Some(generics) = self.tcx.hir_get_generics(def_id)
{ {
err.span_suggestion_verbose( err.span_suggestion_verbose(
generics.tail_span_for_predicate_suggestion(), generics.tail_span_for_predicate_suggestion(),

View file

@ -68,8 +68,8 @@ impl<'hir> FindExprBySpan<'hir> {
impl<'v> Visitor<'v> for FindExprBySpan<'v> { impl<'v> Visitor<'v> for FindExprBySpan<'v> {
type NestedFilter = rustc_middle::hir::nested_filter::OnlyBodies; type NestedFilter = rustc_middle::hir::nested_filter::OnlyBodies;
fn nested_visit_map(&mut self) -> Self::Map { fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
self.tcx.hir() self.tcx
} }
fn visit_expr(&mut self, ex: &'v hir::Expr<'v>) { fn visit_expr(&mut self, ex: &'v hir::Expr<'v>) {
@ -418,7 +418,7 @@ pub fn report_dyn_incompatibility<'tcx>(
violations: &[DynCompatibilityViolation], violations: &[DynCompatibilityViolation],
) -> Diag<'tcx> { ) -> Diag<'tcx> {
let trait_str = tcx.def_path_str(trait_def_id); let trait_str = tcx.def_path_str(trait_def_id);
let trait_span = tcx.hir().get_if_local(trait_def_id).and_then(|node| match node { let trait_span = tcx.hir_get_if_local(trait_def_id).and_then(|node| match node {
hir::Node::Item(item) => Some(item.ident.span), hir::Node::Item(item) => Some(item.ident.span),
_ => None, _ => None,
}); });

View file

@ -790,8 +790,6 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
} }
// Get the name of the callable and the arguments to be used in the suggestion. // Get the name of the callable and the arguments to be used in the suggestion.
let hir = self.tcx.hir();
let msg = match def_id_or_name { let msg = match def_id_or_name {
DefIdOrName::DefId(def_id) => match self.tcx.def_kind(def_id) { DefIdOrName::DefId(def_id) => match self.tcx.def_kind(def_id) {
DefKind::Ctor(CtorOf::Struct, _) => { DefKind::Ctor(CtorOf::Struct, _) => {
@ -834,7 +832,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
Applicability::HasPlaceholders, Applicability::HasPlaceholders,
); );
} else if let DefIdOrName::DefId(def_id) = def_id_or_name { } else if let DefIdOrName::DefId(def_id) = def_id_or_name {
let name = match hir.get_if_local(def_id) { let name = match self.tcx.hir_get_if_local(def_id) {
Some(hir::Node::Expr(hir::Expr { Some(hir::Node::Expr(hir::Expr {
kind: hir::ExprKind::Closure(hir::Closure { fn_decl_span, .. }), kind: hir::ExprKind::Closure(hir::Closure { fn_decl_span, .. }),
.. ..
@ -950,7 +948,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
) -> bool { ) -> bool {
let self_ty = self.resolve_vars_if_possible(trait_pred.self_ty()); let self_ty = self.resolve_vars_if_possible(trait_pred.self_ty());
self.enter_forall(self_ty, |ty: Ty<'_>| { self.enter_forall(self_ty, |ty: Ty<'_>| {
let Some(generics) = self.tcx.hir().get_generics(obligation.cause.body_id) else { let Some(generics) = self.tcx.hir_get_generics(obligation.cause.body_id) else {
return false; return false;
}; };
let ty::Ref(_, inner_ty, hir::Mutability::Not) = ty.kind() else { return false }; let ty::Ref(_, inner_ty, hir::Mutability::Not) = ty.kind() else { return false };
@ -1595,7 +1593,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
&& let ty = typeck_results.expr_ty_adjusted(base) && let ty = typeck_results.expr_ty_adjusted(base)
&& let ty::FnDef(def_id, _args) = ty.kind() && let ty::FnDef(def_id, _args) = ty.kind()
&& let Some(hir::Node::Item(hir::Item { ident, span, vis_span, .. })) = && let Some(hir::Node::Item(hir::Item { ident, span, vis_span, .. })) =
hir.get_if_local(*def_id) self.tcx.hir_get_if_local(*def_id)
{ {
let msg = format!("alternatively, consider making `fn {ident}` asynchronous"); let msg = format!("alternatively, consider making `fn {ident}` asynchronous");
if vis_span.is_empty() { if vis_span.is_empty() {
@ -1703,10 +1701,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
span: Span, span: Span,
trait_pred: ty::PolyTraitPredicate<'tcx>, trait_pred: ty::PolyTraitPredicate<'tcx>,
) -> bool { ) -> bool {
let hir = self.tcx.hir();
let node = self.tcx.hir_node_by_def_id(obligation.cause.body_id); let node = self.tcx.hir_node_by_def_id(obligation.cause.body_id);
if let hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn {sig, body: body_id, .. }, .. }) = node if let hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn {sig, body: body_id, .. }, .. }) = node
&& let hir::ExprKind::Block(blk, _) = &hir.body(*body_id).value.kind && let hir::ExprKind::Block(blk, _) = &self.tcx.hir_body(*body_id).value.kind
&& sig.decl.output.span().overlaps(span) && sig.decl.output.span().overlaps(span)
&& blk.expr.is_none() && blk.expr.is_none()
&& trait_pred.self_ty().skip_binder().is_unit() && trait_pred.self_ty().skip_binder().is_unit()
@ -2790,7 +2787,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
generics, generics,
kind: hir::TraitItemKind::Type(bounds, None), kind: hir::TraitItemKind::Type(bounds, None),
.. ..
})) = tcx.hir().get_if_local(item_def_id) })) = tcx.hir_get_if_local(item_def_id)
// Do not suggest relaxing if there is an explicit `Sized` obligation. // Do not suggest relaxing if there is an explicit `Sized` obligation.
&& !bounds.iter() && !bounds.iter()
.filter_map(|bound| bound.trait_ref()) .filter_map(|bound| bound.trait_ref())
@ -3298,7 +3295,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
let trait_name = parent_trait_pred.print_modifiers_and_trait_path().to_string(); let trait_name = parent_trait_pred.print_modifiers_and_trait_path().to_string();
let msg = format!("required for `{self_ty_str}` to implement `{trait_name}`"); let msg = format!("required for `{self_ty_str}` to implement `{trait_name}`");
let mut is_auto_trait = false; let mut is_auto_trait = false;
match tcx.hir().get_if_local(data.impl_or_alias_def_id) { match tcx.hir_get_if_local(data.impl_or_alias_def_id) {
Some(Node::Item(hir::Item { Some(Node::Item(hir::Item {
kind: hir::ItemKind::Trait(is_auto, ..), kind: hir::ItemKind::Trait(is_auto, ..),
ident, ident,
@ -3423,7 +3420,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
.map_bound(|pred| pred.trait_ref) .map_bound(|pred| pred.trait_ref)
.print_only_trait_path(), .print_only_trait_path(),
); );
match tcx.hir().get_if_local(data.impl_def_id) { match tcx.hir_get_if_local(data.impl_def_id) {
Some(Node::Item(hir::Item { Some(Node::Item(hir::Item {
kind: hir::ItemKind::Impl(hir::Impl { of_trait, self_ty, .. }), kind: hir::ItemKind::Impl(hir::Impl { of_trait, self_ty, .. }),
.. ..
@ -3564,7 +3561,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
let expr = tcx.hir().expect_expr(hir_id); let expr = tcx.hir().expect_expr(hir_id);
(expr_ty, expr) (expr_ty, expr)
} else if let Some(body_id) = tcx.hir_node_by_def_id(body_id).body_id() } else if let Some(body_id) = tcx.hir_node_by_def_id(body_id).body_id()
&& let body = tcx.hir().body(body_id) && let body = tcx.hir_body(body_id)
&& let hir::ExprKind::Block(block, _) = body.value.kind && let hir::ExprKind::Block(block, _) = body.value.kind
&& let Some(expr) = block.expr && let Some(expr) = block.expr
&& let Some(expr_ty) = self && let Some(expr_ty) = self
@ -3841,7 +3838,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
&& let hir::ExprKind::Closure(hir::Closure { && let hir::ExprKind::Closure(hir::Closure {
body, fn_decl_span, .. body, fn_decl_span, ..
}) = value.kind }) = value.kind
&& let body = tcx.hir().body(*body) && let body = tcx.hir_body(*body)
&& !matches!(body.value.kind, hir::ExprKind::Block(..)) && !matches!(body.value.kind, hir::ExprKind::Block(..))
{ {
// Check if the failed predicate was an expectation of a closure type // Check if the failed predicate was an expectation of a closure type
@ -4068,7 +4065,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
&& let [arg] = args && let [arg] = args
&& let hir::ExprKind::Closure(closure) = arg.kind && let hir::ExprKind::Closure(closure) = arg.kind
{ {
let body = tcx.hir().body(closure.body); let body = tcx.hir_body(closure.body);
if let hir::ExprKind::Block(block, None) = body.value.kind if let hir::ExprKind::Block(block, None) = body.value.kind
&& let None = block.expr && let None = block.expr
&& let [.., stmt] = block.stmts && let [.., stmt] = block.stmts
@ -4761,7 +4758,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
{ {
let mut sugg_spans = let mut sugg_spans =
vec![(ret_span, " -> Result<(), Box<dyn std::error::Error>>".to_string())]; vec![(ret_span, " -> Result<(), Box<dyn std::error::Error>>".to_string())];
let body = self.tcx.hir().body(body_id); let body = self.tcx.hir_body(body_id);
if let hir::ExprKind::Block(b, _) = body.value.kind if let hir::ExprKind::Block(b, _) = body.value.kind
&& b.expr.is_none() && b.expr.is_none()
{ {
@ -4807,7 +4804,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
debug!(?pred, ?item_def_id, ?span); debug!(?pred, ?item_def_id, ?span);
let (Some(node), true) = ( let (Some(node), true) = (
self.tcx.hir().get_if_local(item_def_id), self.tcx.hir_get_if_local(item_def_id),
self.tcx.is_lang_item(pred.def_id(), LangItem::Sized), self.tcx.is_lang_item(pred.def_id(), LangItem::Sized),
) else { ) else {
return; return;
@ -5248,7 +5245,7 @@ pub fn suggest_desugaring_async_fn_to_impl_future_in_trait<'tcx>(
// If there's a body, we also need to wrap it in `async {}` // If there's a body, we also need to wrap it in `async {}`
if let hir::TraitFn::Provided(body) = body { if let hir::TraitFn::Provided(body) = body {
let body = tcx.hir().body(body); let body = tcx.hir_body(body);
let body_span = body.value.span; let body_span = body.value.span;
let body_span_without_braces = let body_span_without_braces =
body_span.with_lo(body_span.lo() + BytePos(1)).with_hi(body_span.hi() - BytePos(1)); body_span.with_lo(body_span.lo() + BytePos(1)).with_hi(body_span.hi() - BytePos(1));

View file

@ -1857,7 +1857,7 @@ pub fn impl_trait_overcapture_suggestion<'tcx>(
new_params += name_as_bounds; new_params += name_as_bounds;
} }
let Some(generics) = tcx.hir().get_generics(fn_def_id) else { let Some(generics) = tcx.hir_get_generics(fn_def_id) else {
// This shouldn't happen, but don't ICE. // This shouldn't happen, but don't ICE.
return None; return None;
}; };

View file

@ -26,7 +26,7 @@ impl<'a> DescriptionCtx<'a> {
.parent(tcx.generics_of(generic_param_scope).region_param(br, tcx).def_id) .parent(tcx.generics_of(generic_param_scope).region_param(br, tcx).def_id)
.expect_local(); .expect_local();
let span = if let Some(param) = let span = if let Some(param) =
tcx.hir().get_generics(scope).and_then(|generics| generics.get_named(br.name)) tcx.hir_get_generics(scope).and_then(|generics| generics.get_named(br.name))
{ {
param.span param.span
} else { } else {
@ -48,8 +48,7 @@ impl<'a> DescriptionCtx<'a> {
match fr.kind { match fr.kind {
ty::LateParamRegionKind::Named(_, name) => { ty::LateParamRegionKind::Named(_, name) => {
let span = if let Some(param) = tcx let span = if let Some(param) = tcx
.hir() .hir_get_generics(scope)
.get_generics(scope)
.and_then(|generics| generics.get_named(name)) .and_then(|generics| generics.get_named(name))
{ {
param.span param.span

View file

@ -128,8 +128,7 @@ fn sized_trait_bound_spans<'tcx>(
} }
fn get_sized_bounds(tcx: TyCtxt<'_>, trait_def_id: DefId) -> SmallVec<[Span; 1]> { fn get_sized_bounds(tcx: TyCtxt<'_>, trait_def_id: DefId) -> SmallVec<[Span; 1]> {
tcx.hir() tcx.hir_get_if_local(trait_def_id)
.get_if_local(trait_def_id)
.and_then(|node| match node { .and_then(|node| match node {
hir::Node::Item(hir::Item { hir::Node::Item(hir::Item {
kind: hir::ItemKind::Trait(.., generics, bounds, _), kind: hir::ItemKind::Trait(.., generics, bounds, _),
@ -304,7 +303,7 @@ pub fn dyn_compatibility_violations_for_assoc_item(
ty::AssocKind::Fn => virtual_call_violations_for_method(tcx, trait_def_id, item) ty::AssocKind::Fn => virtual_call_violations_for_method(tcx, trait_def_id, item)
.into_iter() .into_iter()
.map(|v| { .map(|v| {
let node = tcx.hir().get_if_local(item.def_id); let node = tcx.hir_get_if_local(item.def_id);
// Get an accurate span depending on the violation. // Get an accurate span depending on the violation.
let span = match (&v, node) { let span = match (&v, node) {
(MethodViolationCode::ReferencesSelfInput(Some(span)), _) => *span, (MethodViolationCode::ReferencesSelfInput(Some(span)), _) => *span,
@ -349,7 +348,7 @@ fn virtual_call_violations_for_method<'tcx>(
generics, generics,
kind: hir::TraitItemKind::Fn(sig, _), kind: hir::TraitItemKind::Fn(sig, _),
.. ..
})) = tcx.hir().get_if_local(method.def_id).as_ref() })) = tcx.hir_get_if_local(method.def_id).as_ref()
{ {
let sm = tcx.sess.source_map(); let sm = tcx.sess.source_map();
Some(( Some((
@ -383,7 +382,7 @@ fn virtual_call_violations_for_method<'tcx>(
let span = if let Some(hir::Node::TraitItem(hir::TraitItem { let span = if let Some(hir::Node::TraitItem(hir::TraitItem {
kind: hir::TraitItemKind::Fn(sig, _), kind: hir::TraitItemKind::Fn(sig, _),
.. ..
})) = tcx.hir().get_if_local(method.def_id).as_ref() })) = tcx.hir_get_if_local(method.def_id).as_ref()
{ {
Some(sig.decl.inputs[i].span) Some(sig.decl.inputs[i].span)
} else { } else {
@ -421,7 +420,7 @@ fn virtual_call_violations_for_method<'tcx>(
let span = if let Some(hir::Node::TraitItem(hir::TraitItem { let span = if let Some(hir::Node::TraitItem(hir::TraitItem {
kind: hir::TraitItemKind::Fn(sig, _), kind: hir::TraitItemKind::Fn(sig, _),
.. ..
})) = tcx.hir().get_if_local(method.def_id).as_ref() })) = tcx.hir_get_if_local(method.def_id).as_ref()
{ {
Some(sig.decl.inputs[0].span) Some(sig.decl.inputs[0].span)
} else { } else {

View file

@ -208,7 +208,7 @@ pub fn all_fields_implement_trait<'tcx>(
} }
let field_span = tcx.def_span(field.did); let field_span = tcx.def_span(field.did);
let field_ty_span = match tcx.hir().get_if_local(field.did) { let field_ty_span = match tcx.hir_get_if_local(field.did) {
Some(hir::Node::Field(field_def)) => field_def.ty.span, Some(hir::Node::Field(field_def)) => field_def.ty.span,
_ => field_span, _ => field_span,
}; };

View file

@ -289,7 +289,7 @@ fn extend_cause_with_original_assoc_item_obligation<'tcx>(
&& let Some(impl_item) = && let Some(impl_item) =
items.iter().find(|item| item.id.owner_id.to_def_id() == impl_item_id) items.iter().find(|item| item.id.owner_id.to_def_id() == impl_item_id)
{ {
Some(tcx.hir().impl_item(impl_item.id).expect_type().span) Some(tcx.hir_impl_item(impl_item.id).expect_type().span)
} else { } else {
None None
} }

View file

@ -125,7 +125,7 @@ impl<'tcx> OpaqueTypeCollector<'tcx> {
#[instrument(level = "trace", skip(self))] #[instrument(level = "trace", skip(self))]
// Recurse into these, as they are type checked with their parent // Recurse into these, as they are type checked with their parent
fn visit_nested_body(&mut self, id: rustc_hir::BodyId) { fn visit_nested_body(&mut self, id: rustc_hir::BodyId) {
let body = self.collector.tcx.hir().body(id); let body = self.collector.tcx.hir_body(id);
self.visit_body(body); self.visit_body(body);
} }
} }

View file

@ -75,7 +75,7 @@ impl rustc_driver::Callbacks for MyCallbacks {
let item = hir_krate.item(id); let item = hir_krate.item(id);
// Use pattern-matching to find a specific node inside the main function. // Use pattern-matching to find a specific node inside the main function.
if let rustc_hir::ItemKind::Fn(_, _, body_id) = item.kind { if let rustc_hir::ItemKind::Fn(_, _, body_id) = item.kind {
let expr = &tcx.hir().body(body_id).value; let expr = &tcx.hir_body(body_id).value;
if let rustc_hir::ExprKind::Block(block, _) = expr.kind { if let rustc_hir::ExprKind::Block(block, _) = expr.kind {
if let rustc_hir::StmtKind::Let(let_stmt) = block.stmts[0].kind { if let rustc_hir::StmtKind::Let(let_stmt) = block.stmts[0].kind {
if let Some(expr) = let_stmt.init { if let Some(expr) = let_stmt.init {

View file

@ -488,7 +488,7 @@ pub(crate) fn build_impl(
impl_ impl_
.items .items
.iter() .iter()
.map(|item| tcx.hir().impl_item(item.id)) .map(|item| tcx.hir_impl_item(item.id))
.filter(|item| { .filter(|item| {
// Filter out impl items whose corresponding trait item has `doc(hidden)` // Filter out impl items whose corresponding trait item has `doc(hidden)`
// not to document such impl items. // not to document such impl items.
@ -703,7 +703,7 @@ fn build_module_items(
pub(crate) fn print_inlined_const(tcx: TyCtxt<'_>, did: DefId) -> String { pub(crate) fn print_inlined_const(tcx: TyCtxt<'_>, did: DefId) -> String {
if let Some(did) = did.as_local() { if let Some(did) = did.as_local() {
let hir_id = tcx.local_def_id_to_hir_id(did); let hir_id = tcx.local_def_id_to_hir_id(did);
rustc_hir_pretty::id_to_string(&tcx.hir(), hir_id) rustc_hir_pretty::id_to_string(&tcx, hir_id)
} else { } else {
tcx.rendered_const(did).clone() tcx.rendered_const(did).clone()
} }

Some files were not shown because too many files have changed in this diff Show more