Skip to content

Commit 835e6a6

Browse files
committed
Move methods from Map to TyCtxt, part 2.
Continuing the work started in #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 {

0 commit comments

Comments
 (0)