Skip to content

Commit fe37cc1

Browse files
committed
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 c8213a4 commit fe37cc1

39 files changed

+59
-60
lines changed

clippy_lints/src/absolute_paths.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl LateLintPass<'_> for AbsolutePaths {
6262
} = self;
6363

6464
if !path.span.from_expansion()
65-
&& let Some(node) = cx.tcx.hir().find(hir_id)
65+
&& let Some(node) = cx.tcx.opt_hir_node(hir_id)
6666
&& !matches!(node, Node::Item(item) if matches!(item.kind, ItemKind::Use(_, _)))
6767
&& let [first, rest @ ..] = path.segments
6868
// Handle `::std`

clippy_lints/src/casts/cast_slice_different_sizes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>, msrv: &Msrv
6969
fn is_child_of_cast(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
7070
let map = cx.tcx.hir();
7171
if let Some(parent_id) = map.opt_parent_id(expr.hir_id)
72-
&& let Some(parent) = map.find(parent_id)
72+
&& let Some(parent) = cx.tcx.opt_hir_node(parent_id)
7373
{
7474
let expr = match parent {
7575
Node::Block(block) => {

clippy_lints/src/dereference.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1090,7 +1090,7 @@ fn report<'tcx>(
10901090
if parent_id == data.first_expr.hir_id {
10911091
return;
10921092
}
1093-
(cx.tcx.hir().get(parent_id).expect_expr().span, true)
1093+
(cx.tcx.hir_node(parent_id).expect_expr().span, true)
10941094
} else {
10951095
(expr.span, false)
10961096
};

clippy_lints/src/derivable_impls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ impl<'tcx> LateLintPass<'tcx> for DerivableImpls {
195195
&& let Some(def_id) = trait_ref.trait_def_id()
196196
&& cx.tcx.is_diagnostic_item(sym::Default, def_id)
197197
&& let impl_item_hir = child.id.hir_id()
198-
&& let Some(Node::ImplItem(impl_item)) = cx.tcx.hir().find(impl_item_hir)
198+
&& let Some(Node::ImplItem(impl_item)) = cx.tcx.opt_hir_node(impl_item_hir)
199199
&& let ImplItemKind::Fn(_, b) = &impl_item.kind
200200
&& let Body { value: func_expr, .. } = cx.tcx.hir().body(*b)
201201
&& let &Adt(adt_def, args) = cx.tcx.type_of(item.owner_id).instantiate_identity().kind()

clippy_lints/src/empty_drop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ impl LateLintPass<'_> for EmptyDrop {
4242
}) = item.kind
4343
&& trait_ref.trait_def_id() == cx.tcx.lang_items().drop_trait()
4444
&& let impl_item_hir = child.id.hir_id()
45-
&& let Some(Node::ImplItem(impl_item)) = cx.tcx.hir().find(impl_item_hir)
45+
&& let Some(Node::ImplItem(impl_item)) = cx.tcx.opt_hir_node(impl_item_hir)
4646
&& let ImplItemKind::Fn(_, b) = &impl_item.kind
4747
&& let Body { value: func_expr, .. } = cx.tcx.hir().body(*b)
4848
&& let func_expr = peel_blocks(func_expr)

clippy_lints/src/escape.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_infer::infer::TyCtxtInferExt;
55
use rustc_lint::{LateContext, LateLintPass};
66
use rustc_middle::mir::FakeReadCause;
77
use rustc_middle::ty::layout::LayoutOf;
8-
use rustc_middle::ty::{self, TraitRef, Ty};
8+
use rustc_middle::ty::{self, TraitRef, Ty, TyCtxt};
99
use rustc_session::impl_lint_pass;
1010
use rustc_span::def_id::LocalDefId;
1111
use rustc_span::symbol::kw;
@@ -76,7 +76,7 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal {
7676
.hir()
7777
.get_parent_item(cx.tcx.local_def_id_to_hir_id(fn_def_id))
7878
.def_id;
79-
let parent_node = cx.tcx.hir().find_by_def_id(parent_id);
79+
let parent_node = cx.tcx.opt_hir_node_by_def_id(parent_id);
8080

8181
let mut trait_self_ty = None;
8282
if let Some(Node::Item(item)) = parent_node {
@@ -122,16 +122,16 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal {
122122
}
123123

124124
// TODO: Replace with Map::is_argument(..) when it's fixed
125-
fn is_argument(map: rustc_middle::hir::map::Map<'_>, id: HirId) -> bool {
126-
match map.find(id) {
125+
fn is_argument(tcx: TyCtxt<'_>, id: HirId) -> bool {
126+
match tcx.opt_hir_node(id) {
127127
Some(Node::Pat(Pat {
128128
kind: PatKind::Binding(..),
129129
..
130130
})) => (),
131131
_ => return false,
132132
}
133133

134-
matches!(map.find_parent(id), Some(Node::Param(_)))
134+
matches!(tcx.hir().find_parent(id), Some(Node::Param(_)))
135135
}
136136

137137
impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
@@ -154,7 +154,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
154154
fn mutate(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId) {
155155
if cmt.place.projections.is_empty() {
156156
let map = &self.cx.tcx.hir();
157-
if is_argument(*map, cmt.hir_id) {
157+
if is_argument(self.cx.tcx, cmt.hir_id) {
158158
// Skip closure arguments
159159
let parent_id = map.parent_id(cmt.hir_id);
160160
if let Some(Node::Expr(..)) = map.find_parent(parent_id) {

clippy_lints/src/exit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl<'tcx> LateLintPass<'tcx> for Exit {
4646
&& let Some(def_id) = cx.qpath_res(path, path_expr.hir_id).opt_def_id()
4747
&& cx.tcx.is_diagnostic_item(sym::process_exit, def_id)
4848
&& let parent = cx.tcx.hir().get_parent_item(e.hir_id).def_id
49-
&& let Some(Node::Item(Item{kind: ItemKind::Fn(..), ..})) = cx.tcx.hir().find_by_def_id(parent)
49+
&& let Some(Node::Item(Item{kind: ItemKind::Fn(..), ..})) = cx.tcx.opt_hir_node_by_def_id(parent)
5050
// If the next item up is a function we check if it is an entry point
5151
// and only then emit a linter warning
5252
&& !is_entrypoint_fn(cx, parent.to_def_id())

clippy_lints/src/explicit_write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ fn look_in_block<'tcx, 'hir>(cx: &LateContext<'tcx>, kind: &'tcx ExprKind<'hir>)
111111
// Find id of the local that expr_end_of_block resolves to
112112
&& let ExprKind::Path(QPath::Resolved(None, expr_path)) = expr_end_of_block.kind
113113
&& let Res::Local(expr_res) = expr_path.res
114-
&& let Some(Node::Pat(res_pat)) = cx.tcx.hir().find(expr_res)
114+
&& let Some(Node::Pat(res_pat)) = cx.tcx.opt_hir_node(expr_res)
115115

116116
// Find id of the local we found in the block
117117
&& let PatKind::Binding(BindingAnnotation::NONE, local_hir_id, _ident, None) = local.pat.kind

clippy_lints/src/functions/result.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ fn check_result_large_err<'tcx>(cx: &LateContext<'tcx>, err_ty: Ty<'tcx>, hir_ty
9292
.expect("already checked this is adt")
9393
.did()
9494
.as_local()
95-
&& let Some(hir::Node::Item(item)) = cx.tcx.hir().find_by_def_id(local_def_id)
95+
&& let Some(hir::Node::Item(item)) = cx.tcx.opt_hir_node_by_def_id(local_def_id)
9696
&& let hir::ItemKind::Enum(ref def, _) = item.kind
9797
{
9898
let variants_size = AdtVariantInfo::new(cx, *adt, subst);

clippy_lints/src/index_refutable_slice.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,15 +248,15 @@ impl<'a, 'tcx> Visitor<'tcx> for SliceIndexLintingVisitor<'a, 'tcx> {
248248

249249
// Checking for slice indexing
250250
&& let parent_id = map.parent_id(expr.hir_id)
251-
&& let Some(hir::Node::Expr(parent_expr)) = map.find(parent_id)
251+
&& let Some(hir::Node::Expr(parent_expr)) = cx.tcx.opt_hir_node(parent_id)
252252
&& let hir::ExprKind::Index(_, index_expr, _) = parent_expr.kind
253253
&& let Some(Constant::Int(index_value)) = constant(cx, cx.typeck_results(), index_expr)
254254
&& let Ok(index_value) = index_value.try_into()
255255
&& index_value < max_suggested_slice
256256

257257
// Make sure that this slice index is read only
258258
&& let maybe_addrof_id = map.parent_id(parent_id)
259-
&& let Some(hir::Node::Expr(maybe_addrof_expr)) = map.find(maybe_addrof_id)
259+
&& let Some(hir::Node::Expr(maybe_addrof_expr)) = cx.tcx.opt_hir_node(maybe_addrof_id)
260260
&& let hir::ExprKind::AddrOf(_kind, hir::Mutability::Not, _inner_expr) = maybe_addrof_expr.kind
261261
{
262262
use_info.index_use.push((index_value, map.span(parent_expr.hir_id)));

0 commit comments

Comments
 (0)