Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 24f009c

Browse files
committedDec 12, 2023
Move some methods from tcx.hir() to tcx
Renamings: - find -> opt_hir_node - get -> hir_node - find_by_def_id -> opt_hir_node_by_def_id - get_by_def_id -> hir_node_by_def_id Fix rebase changes using removed methods Use `tcx.hir_node_by_def_id()` whenever possible in compiler Fix clippy errors Fix compiler Apply suggestions from code review Co-authored-by: Vadim Petrochenkov <vadim.petrochenkov@gmail.com> Add FIXME for `tcx.hir()` returned type about its removal Simplify with with `tcx.hir_node_by_def_id`
1 parent 27d8a57 commit 24f009c

File tree

122 files changed

+390
-393
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+390
-393
lines changed
 

‎compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rustc_middle::mir::{
1818
PlaceRef, ProjectionElem, Rvalue, Statement, StatementKind, Terminator, TerminatorKind,
1919
VarBindingForm,
2020
};
21-
use rustc_middle::ty::{self, suggest_constraining_type_params, PredicateKind, Ty};
21+
use rustc_middle::ty::{self, suggest_constraining_type_params, PredicateKind, Ty, TyCtxt};
2222
use rustc_middle::util::CallKind;
2323
use rustc_mir_dataflow::move_paths::{InitKind, MoveOutIndex, MovePathIndex};
2424
use rustc_span::def_id::LocalDefId;
@@ -398,7 +398,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
398398
}
399399
let typeck = self.infcx.tcx.typeck(self.mir_def_id());
400400
let hir_id = hir.parent_id(expr.hir_id);
401-
if let Some(parent) = hir.find(hir_id) {
401+
if let Some(parent) = self.infcx.tcx.opt_hir_node(hir_id) {
402402
let (def_id, args, offset) = if let hir::Node::Expr(parent_expr) = parent
403403
&& let hir::ExprKind::MethodCall(_, _, args, _) = parent_expr.kind
404404
&& let Some(def_id) = typeck.type_dependent_def_id(parent_expr.hir_id)
@@ -413,7 +413,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
413413
(None, &[][..], 0)
414414
};
415415
if let Some(def_id) = def_id
416-
&& let Some(node) = hir.find(self.infcx.tcx.local_def_id_to_hir_id(def_id))
416+
&& let Some(node) = self
417+
.infcx
418+
.tcx
419+
.opt_hir_node(self.infcx.tcx.local_def_id_to_hir_id(def_id))
417420
&& let Some(fn_sig) = node.fn_sig()
418421
&& let Some(ident) = node.ident()
419422
&& let Some(pos) = args.iter().position(|arg| arg.hir_id == expr.hir_id)
@@ -1317,7 +1320,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
13171320
let tcx = self.infcx.tcx;
13181321
let hir = tcx.hir();
13191322

1320-
let Some(body_id) = hir.get(self.mir_hir_id()).body_id() else { return };
1323+
let Some(body_id) = tcx.hir_node(self.mir_hir_id()).body_id() else { return };
13211324
let typeck_results = tcx.typeck(self.mir_def_id());
13221325

13231326
struct ExprFinder<'hir> {
@@ -1509,7 +1512,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
15091512
let local_ty = self.body.local_decls[local].ty;
15101513

15111514
// Get the body the error happens in
1512-
let Some(body_id) = hir.get(self.mir_hir_id()).body_id() else { return };
1515+
let Some(body_id) = tcx.hir_node(self.mir_hir_id()).body_id() else { return };
15131516

15141517
let body_expr = hir.body(body_id).value;
15151518

@@ -1558,7 +1561,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
15581561
// Check that the parent of the closure is a method call,
15591562
// with receiver matching with local's type (modulo refs)
15601563
let parent = hir.parent_id(closure_expr.hir_id);
1561-
if let hir::Node::Expr(parent) = hir.get(parent) {
1564+
if let hir::Node::Expr(parent) = tcx.hir_node(parent) {
15621565
if let hir::ExprKind::MethodCall(_, recv, ..) = parent.kind {
15631566
let recv_ty = typeck_results.expr_ty(recv);
15641567

@@ -1635,15 +1638,14 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
16351638
issued_spans: &UseSpans<'tcx>,
16361639
) {
16371640
let UseSpans::ClosureUse { capture_kind_span, .. } = issued_spans else { return };
1638-
let hir = self.infcx.tcx.hir();
16391641

1640-
struct ExpressionFinder<'hir> {
1642+
struct ExpressionFinder<'tcx> {
16411643
capture_span: Span,
16421644
closure_change_spans: Vec<Span>,
16431645
closure_arg_span: Option<Span>,
16441646
in_closure: bool,
16451647
suggest_arg: String,
1646-
hir: rustc_middle::hir::map::Map<'hir>,
1648+
tcx: TyCtxt<'tcx>,
16471649
closure_local_id: Option<hir::HirId>,
16481650
closure_call_changes: Vec<(Span, String)>,
16491651
}
@@ -1657,7 +1659,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
16571659
fn_decl: hir::FnDecl { inputs, .. },
16581660
..
16591661
}) = e.kind
1660-
&& let Some(hir::Node::Expr(body)) = self.hir.find(body.hir_id)
1662+
&& let Some(hir::Node::Expr(body)) = self.tcx.opt_hir_node(body.hir_id)
16611663
{
16621664
self.suggest_arg = "this: &Self".to_string();
16631665
if inputs.len() > 0 {
@@ -1722,8 +1724,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
17221724
if let Some(hir::Node::ImplItem(hir::ImplItem {
17231725
kind: hir::ImplItemKind::Fn(_fn_sig, body_id),
17241726
..
1725-
})) = hir.find(self.mir_hir_id())
1726-
&& let Some(hir::Node::Expr(expr)) = hir.find(body_id.hir_id)
1727+
})) = self.infcx.tcx.opt_hir_node(self.mir_hir_id())
1728+
&& let Some(hir::Node::Expr(expr)) = self.infcx.tcx.opt_hir_node(body_id.hir_id)
17271729
{
17281730
let mut finder = ExpressionFinder {
17291731
capture_span: *capture_kind_span,
@@ -1733,7 +1735,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
17331735
suggest_arg: String::new(),
17341736
closure_local_id: None,
17351737
closure_call_changes: vec![],
1736-
hir,
1738+
tcx: self.infcx.tcx,
17371739
};
17381740
finder.visit_expr(expr);
17391741

@@ -2294,7 +2296,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
22942296
let proper_span = proper_span.source_callsite();
22952297
if let Some(scope) = self.body.source_scopes.get(source_info.scope)
22962298
&& let ClearCrossCrate::Set(scope_data) = &scope.local_data
2297-
&& let Some(node) = self.infcx.tcx.hir().find(scope_data.lint_root)
2299+
&& let Some(node) = self.infcx.tcx.opt_hir_node(scope_data.lint_root)
22982300
&& let Some(id) = node.body_id()
22992301
&& let hir::ExprKind::Block(block, _) = self.infcx.tcx.hir().body(id).value.kind
23002302
{

‎compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl<'tcx> BorrowExplanation<'tcx> {
8787
if let hir::ExprKind::Path(hir::QPath::Resolved(None, p)) = expr.kind
8888
&& let [hir::PathSegment { ident, args: None, .. }] = p.segments
8989
&& let hir::def::Res::Local(hir_id) = p.res
90-
&& let Some(hir::Node::Pat(pat)) = tcx.hir().find(hir_id)
90+
&& let Some(hir::Node::Pat(pat)) = tcx.opt_hir_node(hir_id)
9191
{
9292
err.span_label(pat.span, format!("binding `{ident}` declared here"));
9393
}

0 commit comments

Comments
 (0)