Skip to content

Commit 835e6a6

Browse files
committed
Move methods from Map to TyCtxt, part 2.
Continuing the work started in rust-lang#136466. Every method gains a `hir_` prefix, though for the ones that already have a `par_` or `try_par_` prefix I added the `hir_` after that.
1 parent 42114c9 commit 835e6a6

20 files changed

+37
-45
lines changed

clippy_lints/src/default_numeric_fallback.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,10 @@ declare_lint_pass!(DefaultNumericFallback => [DEFAULT_NUMERIC_FALLBACK]);
5252

5353
impl<'tcx> LateLintPass<'tcx> for DefaultNumericFallback {
5454
fn check_body(&mut self, cx: &LateContext<'tcx>, body: &Body<'tcx>) {
55-
let hir = cx.tcx.hir();
5655
// NOTE: this is different from `clippy_utils::is_inside_always_const_context`.
5756
// Inline const supports type inference.
5857
let is_parent_const = matches!(
59-
hir.body_const_context(hir.body_owner_def_id(body.id())),
58+
cx.tcx.hir_body_const_context(cx.tcx.hir_body_owner_def_id(body.id())),
6059
Some(ConstContext::Const { inline: false } | ConstContext::Static(_))
6160
);
6261
let mut visitor = NumericFallbackVisitor::new(cx, is_parent_const);

clippy_lints/src/enum_clike.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl<'tcx> LateLintPass<'tcx> for UnportableVariant {
4141
if let ItemKind::Enum(def, _) = &item.kind {
4242
for var in def.variants {
4343
if let Some(anon_const) = &var.disr_expr {
44-
let def_id = cx.tcx.hir().body_owner_def_id(anon_const.body);
44+
let def_id = cx.tcx.hir_body_owner_def_id(anon_const.body);
4545
let mut ty = cx.tcx.type_of(def_id.to_def_id()).instantiate_identity();
4646
let constant = cx
4747
.tcx

clippy_lints/src/functions/impl_trait_in_params.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fn report(cx: &LateContext<'_>, param: &GenericParam<'_>, generics: &Generics<'_
3939

4040
pub(super) fn check_fn<'tcx>(cx: &LateContext<'_>, kind: &'tcx FnKind<'_>, body: &'tcx Body<'_>, hir_id: HirId) {
4141
if let FnKind::ItemFn(_, generics, _) = kind
42-
&& cx.tcx.visibility(cx.tcx.hir().body_owner_def_id(body.id())).is_public()
42+
&& cx.tcx.visibility(cx.tcx.hir_body_owner_def_id(body.id())).is_public()
4343
&& !is_in_test(cx.tcx, hir_id)
4444
{
4545
for param in generics.params {
@@ -57,7 +57,7 @@ pub(super) fn check_impl_item(cx: &LateContext<'_>, impl_item: &ImplItem<'_>) {
5757
&& let hir::Impl { of_trait, .. } = *impl_
5858
&& of_trait.is_none()
5959
&& let body = cx.tcx.hir_body(body_id)
60-
&& cx.tcx.visibility(cx.tcx.hir().body_owner_def_id(body.id())).is_public()
60+
&& cx.tcx.visibility(cx.tcx.hir_body_owner_def_id(body.id())).is_public()
6161
&& !is_in_test(cx.tcx, impl_item.hir_id())
6262
{
6363
for param in impl_item.generics.params {

clippy_lints/src/functions/renamed_function_params.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub(super) fn check_impl_item(cx: &LateContext<'_>, item: &ImplItem<'_>, ignored
2222
&& let Some(did) = trait_item_def_id_of_impl(items, item.owner_id)
2323
&& !is_from_ignored_trait(trait_ref, ignored_traits)
2424
{
25-
let mut param_idents_iter = cx.tcx.hir().body_param_names(body_id);
25+
let mut param_idents_iter = cx.tcx.hir_body_param_names(body_id);
2626
let mut default_param_idents_iter = cx.tcx.fn_arg_names(did).iter().copied();
2727

2828
let renames = RenamedFnArgs::new(&mut default_param_idents_iter, &mut param_idents_iter);

clippy_lints/src/manual_float_methods.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualFloatMethods {
143143
&& exprs.iter_mut().partition_in_place(|i| path_to_local(i).is_some()) == 2
144144
&& !expr.span.in_external_macro(cx.sess().source_map())
145145
&& (
146-
is_not_const(cx.tcx, cx.tcx.hir().enclosing_body_owner(expr.hir_id).into())
146+
is_not_const(cx.tcx, cx.tcx.hir_enclosing_body_owner(expr.hir_id).into())
147147
|| self.msrv.meets(msrvs::CONST_FLOAT_CLASSIFY)
148148
)
149149
&& let [first, second, const_1, const_2] = exprs

clippy_lints/src/methods/option_map_unwrap_or.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ pub(super) fn check<'tcx>(
5858
unwrap_or_span: unwrap_arg.span,
5959
};
6060

61-
let map = cx.tcx.hir();
62-
let body = map.body_owned_by(map.enclosing_body_owner(expr.hir_id));
61+
let body = cx.tcx.hir_body_owned_by(cx.tcx.hir_enclosing_body_owner(expr.hir_id));
6362

6463
// Visit the body, and return if we've found a reference
6564
if reference_visitor.visit_body(body).is_break() {

clippy_lints/src/needless_borrows_for_generic_args.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrowsForGenericArgs<'tcx> {
137137
if self
138138
.possible_borrowers
139139
.last()
140-
.is_some_and(|&(local_def_id, _)| local_def_id == cx.tcx.hir().body_owner_def_id(body.id()))
140+
.is_some_and(|&(local_def_id, _)| local_def_id == cx.tcx.hir_body_owner_def_id(body.id()))
141141
{
142142
self.possible_borrowers.pop();
143143
}
@@ -359,7 +359,7 @@ fn referent_used_exactly_once<'tcx>(
359359
&& let StatementKind::Assign(box (_, Rvalue::Ref(_, _, place))) = statement.kind
360360
&& !place.is_indirect_first_projection()
361361
{
362-
let body_owner_local_def_id = cx.tcx.hir().enclosing_body_owner(reference.hir_id);
362+
let body_owner_local_def_id = cx.tcx.hir_enclosing_body_owner(reference.hir_id);
363363
if possible_borrowers
364364
.last()
365365
.is_none_or(|&(local_def_id, _)| local_def_id != body_owner_local_def_id)

clippy_lints/src/needless_pass_by_ref_mut.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ impl MutablyUsedVariablesCtxt<'_> {
352352
fn is_in_unsafe_block(&self, item: HirId) -> bool {
353353
let hir = self.tcx.hir();
354354
for (parent, node) in hir.parent_iter(item) {
355-
if let Some(fn_sig) = hir.fn_sig_by_hir_id(parent) {
355+
if let Some(fn_sig) = self.tcx.hir_fn_sig_by_hir_id(parent) {
356356
return fn_sig.header.is_unsafe();
357357
} else if let Node::Block(block) = node {
358358
if matches!(block.rules, BlockCheckMode::UnsafeBlock(_)) {

clippy_lints/src/operators/arithmetic_side_effects.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,10 +349,10 @@ impl<'tcx> LateLintPass<'tcx> for ArithmeticSideEffects {
349349
}
350350

351351
fn check_body(&mut self, cx: &LateContext<'_>, body: &hir::Body<'_>) {
352-
let body_owner = cx.tcx.hir().body_owner(body.id());
353-
let body_owner_def_id = cx.tcx.hir().body_owner_def_id(body.id());
352+
let body_owner = cx.tcx.hir_body_owner(body.id());
353+
let body_owner_def_id = cx.tcx.hir_body_owner_def_id(body.id());
354354

355-
let body_owner_kind = cx.tcx.hir().body_owner_kind(body_owner_def_id);
355+
let body_owner_kind = cx.tcx.hir_body_owner_kind(body_owner_def_id);
356356
if let hir::BodyOwnerKind::Const { .. } | hir::BodyOwnerKind::Static(_) = body_owner_kind {
357357
let body_span = cx.tcx.hir().span_with_body(body_owner);
358358
if let Some(span) = self.const_span
@@ -365,7 +365,7 @@ impl<'tcx> LateLintPass<'tcx> for ArithmeticSideEffects {
365365
}
366366

367367
fn check_body_post(&mut self, cx: &LateContext<'_>, body: &hir::Body<'_>) {
368-
let body_owner = cx.tcx.hir().body_owner(body.id());
368+
let body_owner = cx.tcx.hir_body_owner(body.id());
369369
let body_span = cx.tcx.hir().span(body_owner);
370370
if let Some(span) = self.const_span
371371
&& span.contains(body_span)

clippy_lints/src/operators/numeric_arithmetic.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ impl Context {
6868
}
6969

7070
pub fn enter_body(&mut self, cx: &LateContext<'_>, body: &hir::Body<'_>) {
71-
let body_owner = cx.tcx.hir().body_owner(body.id());
72-
let body_owner_def_id = cx.tcx.hir().body_owner_def_id(body.id());
71+
let body_owner = cx.tcx.hir_body_owner(body.id());
72+
let body_owner_def_id = cx.tcx.hir_body_owner_def_id(body.id());
7373

74-
match cx.tcx.hir().body_owner_kind(body_owner_def_id) {
74+
match cx.tcx.hir_body_owner_kind(body_owner_def_id) {
7575
hir::BodyOwnerKind::Static(_) | hir::BodyOwnerKind::Const { .. } => {
7676
let body_span = cx.tcx.hir().span_with_body(body_owner);
7777

@@ -87,7 +87,7 @@ impl Context {
8787
}
8888

8989
pub fn body_post(&mut self, cx: &LateContext<'_>, body: &hir::Body<'_>) {
90-
let body_owner = cx.tcx.hir().body_owner(body.id());
90+
let body_owner = cx.tcx.hir_body_owner(body.id());
9191
let body_span = cx.tcx.hir().span_with_body(body_owner);
9292

9393
if let Some(span) = self.const_span {

clippy_lints/src/redundant_locals.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantLocals {
9898
/// assert_static(closure);
9999
/// ```
100100
fn is_by_value_closure_capture(cx: &LateContext<'_>, redefinition: HirId, root_variable: HirId) -> bool {
101-
let closure_def_id = cx.tcx.hir().enclosing_body_owner(redefinition);
101+
let closure_def_id = cx.tcx.hir_enclosing_body_owner(redefinition);
102102

103103
cx.tcx.is_closure_like(closure_def_id.to_def_id())
104104
&& cx.tcx.closure_captures(closure_def_id).iter().any(|c| {

clippy_lints/src/shadow.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,17 +149,15 @@ impl<'tcx> LateLintPass<'tcx> for Shadow {
149149
}
150150

151151
fn check_body(&mut self, cx: &LateContext<'_>, body: &Body<'_>) {
152-
let hir = cx.tcx.hir();
153-
let owner_id = hir.body_owner_def_id(body.id());
154-
if !matches!(hir.body_owner_kind(owner_id), BodyOwnerKind::Closure) {
152+
let owner_id = cx.tcx.hir_body_owner_def_id(body.id());
153+
if !matches!(cx.tcx.hir_body_owner_kind(owner_id), BodyOwnerKind::Closure) {
155154
self.bindings.push((FxHashMap::default(), owner_id));
156155
}
157156
}
158157

159158
fn check_body_post(&mut self, cx: &LateContext<'_>, body: &Body<'_>) {
160-
let hir = cx.tcx.hir();
161159
if !matches!(
162-
hir.body_owner_kind(hir.body_owner_def_id(body.id())),
160+
cx.tcx.hir_body_owner_kind(cx.tcx.hir_body_owner_def_id(body.id())),
163161
BodyOwnerKind::Closure
164162
) {
165163
self.bindings.pop();

clippy_lints/src/single_call_fn.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ impl SingleCallFn {
9090
|| fn_span.in_external_macro(cx.sess().source_map())
9191
|| cx
9292
.tcx
93-
.hir()
94-
.maybe_body_owned_by(fn_def_id)
93+
.hir_maybe_body_owned_by(fn_def_id)
9594
.is_none_or(|body| is_in_test_function(cx.tcx, body.value.hir_id))
9695
|| match cx.tcx.hir_node(fn_hir_id) {
9796
Node::Item(item) => is_from_proc_macro(cx, item),

clippy_lints/src/transmute/missing_transmute_annotations.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ fn get_parent_local_binding_ty<'tcx>(cx: &LateContext<'tcx>, expr_hir_id: HirId)
2828
}
2929

3030
fn is_function_block(cx: &LateContext<'_>, expr_hir_id: HirId) -> bool {
31-
let def_id = cx.tcx.hir().enclosing_body_owner(expr_hir_id);
32-
if let Some(body) = cx.tcx.hir().maybe_body_owned_by(def_id) {
31+
let def_id = cx.tcx.hir_enclosing_body_owner(expr_hir_id);
32+
if let Some(body) = cx.tcx.hir_maybe_body_owned_by(def_id) {
3333
return body.value.peel_blocks().hir_id == expr_hir_id;
3434
}
3535
false

clippy_lints/src/unconditional_recursion.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,8 @@ impl UnconditionalRecursion {
331331
&& let [return_expr] = get_return_calls_in_body(body).as_slice()
332332
&& let ExprKind::Call(call_expr, _) = return_expr.kind
333333
// We need to use typeck here to infer the actual function being called.
334-
&& let body_def_id = cx.tcx.hir().enclosing_body_owner(call_expr.hir_id)
335-
&& let Some(body_owner) = cx.tcx.hir().maybe_body_owned_by(body_def_id)
334+
&& let body_def_id = cx.tcx.hir_enclosing_body_owner(call_expr.hir_id)
335+
&& let Some(body_owner) = cx.tcx.hir_maybe_body_owned_by(body_def_id)
336336
&& let typeck = cx.tcx.typeck_body(body_owner.id())
337337
&& let Some(call_def_id) = typeck.type_dependent_def_id(call_expr.hir_id)
338338
{

clippy_lints/src/utils/author.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,7 @@ impl<'tcx> LateLintPass<'tcx> for Author {
132132
}
133133

134134
fn check_item(cx: &LateContext<'_>, hir_id: HirId) {
135-
let hir = cx.tcx.hir();
136-
if let Some(body) = hir.maybe_body_owned_by(hir_id.expect_owner().def_id) {
135+
if let Some(body) = cx.tcx.hir_maybe_body_owned_by(hir_id.expect_owner().def_id) {
137136
check_node(cx, hir_id, |v| {
138137
v.expr(&v.bind("expr", body.value));
139138
});

clippy_lints/src/utils/internal_lints/lint_without_lint_pass.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ impl<'tcx> LateLintPass<'tcx> for LintWithoutLintPass {
156156
output: &mut self.registered_lints,
157157
cx,
158158
};
159-
let body = cx.tcx.hir().body_owned_by(
159+
let body = cx.tcx.hir_body_owned_by(
160160
impl_item_refs
161161
.iter()
162162
.find(|iiref| iiref.ident.as_str() == "lint_vec")

clippy_utils/src/lib.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,7 @@ pub fn is_in_const_context(cx: &LateContext<'_>) -> bool {
237237
debug_assert!(cx.enclosing_body.is_some(), "`LateContext` has no enclosing body");
238238
cx.enclosing_body.is_some_and(|id| {
239239
cx.tcx
240-
.hir()
241-
.body_const_context(cx.tcx.hir().body_owner_def_id(id))
240+
.hir_body_const_context(cx.tcx.hir_body_owner_def_id(id))
242241
.is_some()
243242
})
244243
}
@@ -251,8 +250,7 @@ pub fn is_in_const_context(cx: &LateContext<'_>) -> bool {
251250
/// * associated constants
252251
pub fn is_inside_always_const_context(tcx: TyCtxt<'_>, hir_id: HirId) -> bool {
253252
use ConstContext::{Const, ConstFn, Static};
254-
let hir = tcx.hir();
255-
let Some(ctx) = hir.body_const_context(hir.enclosing_body_owner(hir_id)) else {
253+
let Some(ctx) = tcx.hir_body_const_context(tcx.hir_enclosing_body_owner(hir_id)) else {
256254
return false;
257255
};
258256
match ctx {
@@ -1648,7 +1646,7 @@ pub fn is_integer_const(cx: &LateContext<'_>, e: &Expr<'_>, value: u128) -> bool
16481646
if is_integer_literal(e, value) {
16491647
return true;
16501648
}
1651-
let enclosing_body = cx.tcx.hir().enclosing_body_owner(e.hir_id);
1649+
let enclosing_body = cx.tcx.hir_enclosing_body_owner(e.hir_id);
16521650
if let Some(Constant::Int(v)) =
16531651
ConstEvalCtxt::with_env(cx.tcx, cx.typing_env(), cx.tcx.typeck(enclosing_body)).eval(e)
16541652
{
@@ -2762,7 +2760,7 @@ impl<'tcx> ExprUseCtxt<'tcx> {
27622760

27632761
Node::Expr(use_expr) => match use_expr.kind {
27642762
ExprKind::Ret(_) => ExprUseNode::Return(OwnerId {
2765-
def_id: cx.tcx.hir().body_owner_def_id(cx.enclosing_body.unwrap()),
2763+
def_id: cx.tcx.hir_body_owner_def_id(cx.enclosing_body.unwrap()),
27662764
}),
27672765

27682766
ExprKind::Closure(closure) => ExprUseNode::Return(OwnerId { def_id: closure.def_id }),

clippy_utils/src/mir/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ pub fn used_exactly_once(mir: &Body<'_>, local: Local) -> Option<bool> {
136136
/// Returns the `mir::Body` containing the node associated with `hir_id`.
137137
#[allow(clippy::module_name_repetitions)]
138138
pub fn enclosing_mir(tcx: TyCtxt<'_>, hir_id: HirId) -> Option<&Body<'_>> {
139-
let body_owner_local_def_id = tcx.hir().enclosing_body_owner(hir_id);
140-
if tcx.hir().body_owner_kind(body_owner_local_def_id).is_fn_or_closure() {
139+
let body_owner_local_def_id = tcx.hir_enclosing_body_owner(hir_id);
140+
if tcx.hir_body_owner_kind(body_owner_local_def_id).is_fn_or_closure() {
141141
Some(tcx.optimized_mir(body_owner_local_def_id.to_def_id()))
142142
} else {
143143
None

clippy_utils/src/ty/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ pub fn implements_trait_with_env_from_iter<'tcx>(
267267
// through calling `body_owner_kind`, which would panic if the callee
268268
// does not have a body.
269269
if let Some(callee_id) = callee_id {
270-
let _ = tcx.hir().body_owner_kind(callee_id);
270+
let _ = tcx.hir_body_owner_kind(callee_id);
271271
}
272272

273273
let ty = tcx.erase_regions(ty);
@@ -705,7 +705,7 @@ pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option<ExprFnSig<'t
705705
ty::Closure(id, subs) => {
706706
let decl = id
707707
.as_local()
708-
.and_then(|id| cx.tcx.hir().fn_decl_by_hir_id(cx.tcx.local_def_id_to_hir_id(id)));
708+
.and_then(|id| cx.tcx.hir_fn_decl_by_hir_id(cx.tcx.local_def_id_to_hir_id(id)));
709709
Some(ExprFnSig::Closure(decl, subs.as_closure().sig()))
710710
},
711711
ty::FnDef(id, subs) => Some(ExprFnSig::Sig(cx.tcx.fn_sig(id).instantiate(cx.tcx, subs), Some(id))),

0 commit comments

Comments
 (0)