Move some Map methods onto TyCtxt.

The end goal is to eliminate `Map` altogether.

I added a `hir_` prefix to all of them, that seemed simplest. The
exceptions are `module_items` which became `hir_module_free_items` because
there was already a `hir_module_items`, and `items` which became
`hir_free_items` for consistency with `hir_module_free_items`.
This commit is contained in:
Nicholas Nethercote 2025-02-03 10:45:49 +11:00
parent fc532c5b32
commit 8cf9eea5b3
102 changed files with 146 additions and 150 deletions

View file

@ -338,7 +338,7 @@ impl<'tcx> LateLintPass<'tcx> for ArbitrarySourceItemOrdering {
return;
}
let items = module.item_ids.iter().map(|&id| cx.tcx.hir().item(id));
let items = module.item_ids.iter().map(|&id| cx.tcx.hir_item(id));
// Iterates over the items within a module.
//

View file

@ -60,12 +60,12 @@ impl<'tcx> LateLintPass<'tcx> for AsyncYieldsAsync {
// XXXkhuey maybe we should?
return;
},
CoroutineSource::Block => cx.tcx.hir().body(*body_id).value,
CoroutineSource::Block => cx.tcx.hir_body(*body_id).value,
CoroutineSource::Closure => {
// Like `async fn`, async closures are wrapped in an additional block
// to move all of the closure's arguments into the future.
let async_closure_body = cx.tcx.hir().body(*body_id).value;
let async_closure_body = cx.tcx.hir_body(*body_id).value;
let ExprKind::Block(block, _) = async_closure_body.kind else {
return;
};

View file

@ -22,7 +22,7 @@ pub(super) fn is_lint_level(symbol: Symbol, attr_id: AttrId) -> bool {
pub(super) fn is_relevant_item(cx: &LateContext<'_>, item: &Item<'_>) -> bool {
if let ItemKind::Fn { body: eid, .. } = item.kind {
is_relevant_expr(cx, cx.tcx.typeck_body(eid), cx.tcx.hir().body(eid).value)
is_relevant_expr(cx, cx.tcx.typeck_body(eid), cx.tcx.hir_body(eid).value)
} else {
true
}
@ -30,7 +30,7 @@ pub(super) fn is_relevant_item(cx: &LateContext<'_>, item: &Item<'_>) -> bool {
pub(super) fn is_relevant_impl(cx: &LateContext<'_>, item: &ImplItem<'_>) -> bool {
match item.kind {
ImplItemKind::Fn(_, eid) => is_relevant_expr(cx, cx.tcx.typeck_body(eid), cx.tcx.hir().body(eid).value),
ImplItemKind::Fn(_, eid) => is_relevant_expr(cx, cx.tcx.typeck_body(eid), cx.tcx.hir_body(eid).value),
_ => false,
}
}
@ -39,7 +39,7 @@ pub(super) fn is_relevant_trait(cx: &LateContext<'_>, item: &TraitItem<'_>) -> b
match item.kind {
TraitItemKind::Fn(_, TraitFn::Required(_)) => true,
TraitItemKind::Fn(_, TraitFn::Provided(eid)) => {
is_relevant_expr(cx, cx.tcx.typeck_body(eid), cx.tcx.hir().body(eid).value)
is_relevant_expr(cx, cx.tcx.typeck_body(eid), cx.tcx.hir_body(eid).value)
},
_ => false,
}

View file

@ -452,7 +452,7 @@ fn simplify_not(cx: &LateContext<'_>, curr_msrv: &Msrv, expr: &Expr<'_>) -> Opti
})
},
ExprKind::Closure(closure) => {
let body = cx.tcx.hir().body(closure.body);
let body = cx.tcx.hir_body(closure.body);
let params = body
.params
.iter()

View file

@ -118,7 +118,7 @@ fn has_no_read_access<'tcx, T: Visitable<'tcx>>(cx: &LateContext<'tcx>, id: HirI
let is_read_in_closure_arg = args.iter().any(|arg| {
if let ExprKind::Closure(closure) = arg.kind
// To keep things simple, we only check the first param to see if its read.
&& let Body { params: [param, ..], value } = cx.tcx.hir().body(closure.body)
&& let Body { params: [param, ..], value } = cx.tcx.hir_body(closure.body)
{
!has_no_read_access(cx, param.hir_id, *value)
} else {

View file

@ -197,7 +197,7 @@ impl<'tcx> LateLintPass<'tcx> for DerivableImpls {
&& let impl_item_hir = child.id.hir_id()
&& let Node::ImplItem(impl_item) = cx.tcx.hir_node(impl_item_hir)
&& let ImplItemKind::Fn(_, b) = &impl_item.kind
&& let Body { value: func_expr, .. } = cx.tcx.hir().body(*b)
&& let Body { value: func_expr, .. } = cx.tcx.hir_body(*b)
&& let &ty::Adt(adt_def, args) = cx.tcx.type_of(item.owner_id).instantiate_identity().kind()
&& let attrs = cx.tcx.hir().attrs(item.hir_id())
&& !attrs.iter().any(|attr| attr.doc_str().is_some())

View file

@ -68,7 +68,7 @@ pub fn check(
} else if let Some(body_id) = body_id
&& let Some(future) = cx.tcx.lang_items().future_trait()
&& let typeck = cx.tcx.typeck_body(body_id)
&& let body = cx.tcx.hir().body(body_id)
&& let body = cx.tcx.hir_body(body_id)
&& let ret_ty = typeck.expr_ty(body.value)
&& implements_trait_with_env(
cx.tcx,

View file

@ -597,7 +597,7 @@ impl<'tcx> LateLintPass<'tcx> for Documentation {
if !(is_entrypoint_fn(cx, item.owner_id.to_def_id())
|| item.span.in_external_macro(cx.tcx.sess.source_map()))
{
let body = cx.tcx.hir().body(body_id);
let body = cx.tcx.hir_body(body_id);
let panic_info = FindPanicUnwrap::find_span(cx, cx.tcx.typeck(item.owner_id), body.value);
missing_headers::check(
@ -649,7 +649,7 @@ impl<'tcx> LateLintPass<'tcx> for Documentation {
&& !impl_item.span.in_external_macro(cx.tcx.sess.source_map())
&& !is_trait_impl_item(cx, impl_item.hir_id())
{
let body = cx.tcx.hir().body(body_id);
let body = cx.tcx.hir_body(body_id);
let panic_span = FindPanicUnwrap::find_span(cx, cx.tcx.typeck(impl_item.owner_id), body.value);
missing_headers::check(

View file

@ -44,7 +44,7 @@ impl LateLintPass<'_> for EmptyDrop {
&& let impl_item_hir = child.id.hir_id()
&& let Node::ImplItem(impl_item) = cx.tcx.hir_node(impl_item_hir)
&& let ImplItemKind::Fn(_, b) = &impl_item.kind
&& let Body { value: func_expr, .. } = cx.tcx.hir().body(*b)
&& let Body { value: func_expr, .. } = cx.tcx.hir_body(*b)
&& let func_expr = peel_blocks(func_expr)
&& let ExprKind::Block(block, _) = func_expr.kind
&& block.stmts.is_empty()

View file

@ -97,7 +97,7 @@ fn check_closure<'tcx>(cx: &LateContext<'tcx>, outer_receiver: Option<&Expr<'tcx
&& matches!(c.fn_decl.output, FnRetTy::DefaultReturn(_))
&& !expr.span.from_expansion()
{
cx.tcx.hir().body(c.body)
cx.tcx.hir_body(c.body)
} else {
return;
};

View file

@ -247,7 +247,7 @@ impl<'tcx> Visitor<'tcx> for TypeWalker<'_, 'tcx> {
}
fn is_empty_body(cx: &LateContext<'_>, body: BodyId) -> bool {
matches!(cx.tcx.hir().body(body).value.kind, ExprKind::Block(b, _) if b.stmts.is_empty() && b.expr.is_none())
matches!(cx.tcx.hir_body(body).value.kind, ExprKind::Block(b, _) if b.stmts.is_empty() && b.expr.is_none())
}
impl<'tcx> LateLintPass<'tcx> for ExtraUnusedTypeParameters {

View file

@ -98,10 +98,10 @@ fn lint_impl_body(cx: &LateContext<'_>, impl_span: Span, impl_items: &[hir::Impl
for impl_item in impl_items {
if impl_item.ident.name == sym::from
&& let ImplItemKind::Fn(_, body_id) = cx.tcx.hir().impl_item(impl_item.id).kind
&& let ImplItemKind::Fn(_, body_id) = cx.tcx.hir_impl_item(impl_item.id).kind
{
// check the body for `begin_panic` or `unwrap`
let body = cx.tcx.hir().body(body_id);
let body = cx.tcx.hir_body(body_id);
let mut fpu = FindPanicUnwrap {
lcx: cx,
typeck_results: cx.tcx.typeck(impl_item.id.owner_id.def_id),

View file

@ -262,7 +262,7 @@ fn is_format_trait_impl(cx: &LateContext<'_>, impl_item: &ImplItem<'_>) -> Optio
&& let Some(name) = cx.tcx.get_diagnostic_name(did)
&& matches!(name, sym::Debug | sym::Display)
{
let body = cx.tcx.hir().body(body_id);
let body = cx.tcx.hir_body(body_id);
let formatter_name = body
.params
.get(1)

View file

@ -175,11 +175,11 @@ fn convert_to_from(
// bad suggestion/fix.
return None;
}
let impl_item = cx.tcx.hir().impl_item(impl_item_ref.id);
let impl_item = cx.tcx.hir_impl_item(impl_item_ref.id);
let ImplItemKind::Fn(ref sig, body_id) = impl_item.kind else {
return None;
};
let body = cx.tcx.hir().body(body_id);
let body = cx.tcx.hir_body(body_id);
let [input] = body.params else { return None };
let PatKind::Binding(.., self_ident, None) = input.pat.kind else {
return None;

View file

@ -56,7 +56,7 @@ pub(super) fn check_impl_item(cx: &LateContext<'_>, impl_item: &ImplItem<'_>) {
&& let hir::ItemKind::Impl(impl_) = item.kind
&& let hir::Impl { of_trait, .. } = *impl_
&& of_trait.is_none()
&& let body = cx.tcx.hir().body(body_id)
&& let body = cx.tcx.hir_body(body_id)
&& cx.tcx.visibility(cx.tcx.hir().body_owner_def_id(body.id())).is_public()
&& !is_in_test(cx.tcx, impl_item.hir_id())
{

View file

@ -37,7 +37,7 @@ pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>
check_must_use_candidate(
cx,
sig.decl,
cx.tcx.hir().body(*body_id),
cx.tcx.hir_body(*body_id),
item.span,
item.owner_id,
item.span.with_hi(sig.decl.output.span().hi()),
@ -59,7 +59,7 @@ pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Imp
check_must_use_candidate(
cx,
sig.decl,
cx.tcx.hir().body(*body_id),
cx.tcx.hir_body(*body_id),
item.span,
item.owner_id,
item.span.with_hi(sig.decl.output.span().hi()),
@ -79,7 +79,7 @@ pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Tr
if let Some(attr) = attr {
check_needless_must_use(cx, sig.decl, item.owner_id, item.span, fn_header_span, attr, attrs, sig);
} else if let hir::TraitFn::Provided(eid) = *eid {
let body = cx.tcx.hir().body(eid);
let body = cx.tcx.hir_body(eid);
if attr.is_none() && is_public && !is_proc_macro(attrs) {
check_must_use_candidate(
cx,

View file

@ -30,7 +30,7 @@ pub(super) fn check_fn<'tcx>(
pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) {
if let hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Provided(eid)) = item.kind {
let body = cx.tcx.hir().body(eid);
let body = cx.tcx.hir_body(eid);
check_raw_ptr(cx, sig.header.safety(), sig.decl, body, item.owner_id.def_id);
}
}

View file

@ -130,7 +130,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitHasher {
});
let mut ctr_vis = ImplicitHasherConstructorVisitor::new(cx, target);
for item in impl_.items.iter().map(|item| cx.tcx.hir().impl_item(item.id)) {
for item in impl_.items.iter().map(|item| cx.tcx.hir_impl_item(item.id)) {
ctr_vis.visit_impl_item(item);
}
@ -154,7 +154,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitHasher {
body: body_id,
..
} => {
let body = cx.tcx.hir().body(body_id);
let body = cx.tcx.hir_body(body_id);
for ty in sig.decl.inputs {
let mut vis = ImplicitHasherTypeVisitor::new(cx);

View file

@ -159,7 +159,7 @@ fn is_infinite(cx: &LateContext<'_>, expr: &Expr<'_>) -> Finiteness {
}
if method.ident.name.as_str() == "flat_map" && args.len() == 1 {
if let ExprKind::Closure(&Closure { body, .. }) = args[0].kind {
let body = cx.tcx.hir().body(body);
let body = cx.tcx.hir_body(body);
return is_infinite(cx, body.value);
}
}

View file

@ -59,7 +59,7 @@ impl LateLintPass<'_> for ItemsAfterStatements {
.iter()
.skip_while(|stmt| matches!(stmt.kind, StmtKind::Item(..)))
.filter_map(|stmt| match stmt.kind {
StmtKind::Item(id) => Some(cx.tcx.hir().item(id)),
StmtKind::Item(id) => Some(cx.tcx.hir_item(id)),
_ => None,
})
// Ignore macros since they can only see previously defined locals.

View file

@ -58,7 +58,7 @@ fn cfg_test_module<'tcx>(cx: &LateContext<'tcx>, item: &Item<'tcx>) -> bool {
impl LateLintPass<'_> for ItemsAfterTestModule {
fn check_mod(&mut self, cx: &LateContext<'_>, module: &Mod<'_>, _: HirId) {
let mut items = module.item_ids.iter().map(|&id| cx.tcx.hir().item(id));
let mut items = module.item_ids.iter().map(|&id| cx.tcx.hir_item(id));
let Some((mod_pos, test_mod)) = items.by_ref().enumerate().find(|(_, item)| cfg_test_module(cx, item)) else {
return;
@ -91,7 +91,7 @@ impl LateLintPass<'_> for ItemsAfterTestModule {
"items after a test module",
|diag| {
if let Some(prev) = mod_pos.checked_sub(1)
&& let prev = cx.tcx.hir().item(module.item_ids[prev])
&& let prev = cx.tcx.hir_item(module.item_ids[prev])
&& let items_span = last.span.with_lo(test_mod.span.hi())
&& let Some(items) = items_span.get_source_text(cx)
{

View file

@ -142,7 +142,7 @@ impl LateLintPass<'_> for IterWithoutIntoIter {
})
&& let Some(iter_assoc_span) = imp.items.iter().find_map(|item| {
if item.ident.name.as_str() == "IntoIter" {
Some(cx.tcx.hir().impl_item(item.id).expect_type().span)
Some(cx.tcx.hir_impl_item(item.id).expect_type().span)
} else {
None
}

View file

@ -316,7 +316,7 @@ enum LenOutput {
fn extract_future_output<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option<&'tcx PathSegment<'tcx>> {
if let ty::Alias(_, alias_ty) = ty.kind()
&& let Some(Node::OpaqueTy(opaque)) = cx.tcx.hir().get_if_local(alias_ty.def_id)
&& let Some(Node::OpaqueTy(opaque)) = cx.tcx.hir_get_if_local(alias_ty.def_id)
&& let OpaqueTyOrigin::AsyncFn { .. } = opaque.origin
&& let [GenericBound::Trait(trait_ref)] = &opaque.bounds
&& let Some(segment) = trait_ref.trait_ref.path.segments.last()

View file

@ -275,7 +275,7 @@ fn could_use_elision<'tcx>(
}
if let Some(body_id) = body {
let body = cx.tcx.hir().body(body_id);
let body = cx.tcx.hir_body(body_id);
let first_ident = body.params.first().and_then(|param| param.pat.simple_ident());
if non_elidable_self_type(cx, func, first_ident, msrv) {

View file

@ -101,7 +101,7 @@ fn should_lint(cx: &LateContext<'_>, args: &[Expr<'_>], method_str: &str) -> boo
ExprKind::Closure(Closure { body, .. }) => {
if let Body {
params: [param], value, ..
} = cx.tcx.hir().body(*body)
} = cx.tcx.hir_body(*body)
&& let ExprKind::MethodCall(method, receiver, [], _) = value.kind
&& path_to_local_id(receiver, param.pat.hir_id)
&& let Some(method_did) = cx.typeck_results().type_dependent_def_id(value.hir_id)

View file

@ -370,7 +370,7 @@ impl<'tcx> Visitor<'tcx> for VarVisitor<'_, 'tcx> {
}
},
ExprKind::Closure(&Closure { body, .. }) => {
let body = self.cx.tcx.hir().body(body);
let body = self.cx.tcx.hir_body(body);
self.visit_expr(body.value);
},
_ => walk_expr(self, expr),

View file

@ -351,7 +351,7 @@ fn needs_mutable_borrow(cx: &LateContext<'_>, iter_expr: &IterExpr, loop_expr: &
loop_id: loop_expr.hir_id,
after_loop: false,
};
v.visit_expr(cx.tcx.hir().body(cx.enclosing_body.unwrap()).value)
v.visit_expr(cx.tcx.hir_body(cx.enclosing_body.unwrap()).value)
.is_break()
}
}

View file

@ -168,7 +168,7 @@ fn desugared_async_block<'tcx>(cx: &LateContext<'tcx>, block: &'tcx Block<'tcx>)
&& let ClosureKind::Coroutine(CoroutineKind::Desugared(CoroutineDesugaring::Async, CoroutineSource::Block)) =
kind
{
return Some(cx.tcx.hir().body(body));
return Some(cx.tcx.hir_body(body));
}
None

View file

@ -191,7 +191,7 @@ fn check_arms(cx: &LateContext<'_>, none_arm: &Arm<'_>, some_arm: &Arm<'_>) -> b
fn returns_empty_slice(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
match expr.kind {
ExprKind::Path(_) => clippy_utils::is_path_diagnostic_item(cx, expr, sym::default_fn),
ExprKind::Closure(cl) => is_empty_slice(cx, cx.tcx.hir().body(cl.body).value),
ExprKind::Closure(cl) => is_empty_slice(cx, cx.tcx.hir_body(cl.body).value),
_ => false,
}
}

View file

@ -92,7 +92,7 @@ fn check_into_iter(
&& SpanlessEq::new(cx).eq_expr(left_expr, struct_expr)
&& let hir::ExprKind::MethodCall(_, _, [closure_expr], _) = target_expr.kind
&& let hir::ExprKind::Closure(closure) = closure_expr.kind
&& let filter_body = cx.tcx.hir().body(closure.body)
&& let filter_body = cx.tcx.hir_body(closure.body)
&& let [filter_params] = filter_body.params
{
if match_map_type(cx, left_expr) {
@ -139,7 +139,7 @@ fn check_iter(
&& SpanlessEq::new(cx).eq_expr(left_expr, struct_expr)
&& let hir::ExprKind::MethodCall(_, _, [closure_expr], _) = filter_expr.kind
&& let hir::ExprKind::Closure(closure) = closure_expr.kind
&& let filter_body = cx.tcx.hir().body(closure.body)
&& let filter_body = cx.tcx.hir_body(closure.body)
&& let [filter_params] = filter_body.params
{
match filter_params.pat.kind {
@ -198,7 +198,7 @@ fn check_to_owned(
&& SpanlessEq::new(cx).eq_expr(left_expr, str_expr)
&& let hir::ExprKind::MethodCall(_, _, [closure_expr], _) = filter_expr.kind
&& let hir::ExprKind::Closure(closure) = closure_expr.kind
&& let filter_body = cx.tcx.hir().body(closure.body)
&& let filter_body = cx.tcx.hir_body(closure.body)
&& let [filter_params] = filter_body.params
{
if let hir::PatKind::Ref(pat, _) = filter_params.pat.kind {

View file

@ -163,7 +163,7 @@ fn unit_closure<'tcx>(
expr: &hir::Expr<'_>,
) -> Option<(&'tcx hir::Param<'tcx>, &'tcx hir::Expr<'tcx>)> {
if let hir::ExprKind::Closure(&hir::Closure { fn_decl, body, .. }) = expr.kind
&& let body = cx.tcx.hir().body(body)
&& let body = cx.tcx.hir_body(body)
&& let body_expr = &body.value
&& fn_decl.inputs.len() == 1
&& is_unit_expression(cx, body_expr)

View file

@ -163,7 +163,7 @@ impl BindInsteadOfMap {
match arg.kind {
hir::ExprKind::Closure(&hir::Closure { body, fn_decl_span, .. }) => {
let closure_body = cx.tcx.hir().body(body);
let closure_body = cx.tcx.hir_body(body);
let closure_expr = peel_blocks(closure_body.value);
if self.lint_closure_autofixable(cx, expr, recv, closure_expr, fn_decl_span) {

View file

@ -18,7 +18,7 @@ pub(super) fn check<'tcx>(
filter_arg: &'tcx Expr<'_>,
) {
if let ExprKind::Closure(&Closure { body, .. }) = filter_arg.kind
&& let body = cx.tcx.hir().body(body)
&& let body = cx.tcx.hir_body(body)
&& let [param] = body.params
&& let PatKind::Binding(_, arg_id, _, _) = strip_pat_refs(param.pat).kind
&& let ExprKind::Binary(ref op, l, r) = body.value.kind

View file

@ -22,7 +22,7 @@ fn is_method(cx: &LateContext<'_>, expr: &Expr<'_>, method_name: Symbol) -> bool
ExprKind::Path(QPath::Resolved(_, segments)) => segments.segments.last().unwrap().ident.name == method_name,
ExprKind::MethodCall(segment, _, _, _) => segment.ident.name == method_name,
ExprKind::Closure(Closure { body, .. }) => {
let body = cx.tcx.hir().body(*body);
let body = cx.tcx.hir_body(*body);
let closure_expr = peel_blocks(body.value);
match closure_expr.kind {
ExprKind::MethodCall(PathSegment { ident, .. }, receiver, ..) => {
@ -404,7 +404,7 @@ fn is_find_or_filter<'a>(
if is_trait_method(cx, map_recv, sym::Iterator)
// filter(|x| ...is_some())...
&& let ExprKind::Closure(&Closure { body: filter_body_id, .. }) = filter_arg.kind
&& let filter_body = cx.tcx.hir().body(filter_body_id)
&& let filter_body = cx.tcx.hir_body(filter_body_id)
&& let [filter_param] = filter_body.params
// optional ref pattern: `filter(|&x| ..)`
&& let (filter_pat, is_filter_param_ref) = if let PatKind::Ref(ref_pat, _) = filter_param.pat.kind {
@ -417,7 +417,7 @@ fn is_find_or_filter<'a>(
&& let Some(mut offending_expr) = OffendingFilterExpr::hir(cx, filter_body.value, filter_param_id)
&& let ExprKind::Closure(&Closure { body: map_body_id, .. }) = map_arg.kind
&& let map_body = cx.tcx.hir().body(map_body_id)
&& let map_body = cx.tcx.hir_body(map_body_id)
&& let [map_param] = map_body.params
&& let PatKind::Binding(_, map_param_id, map_param_ident, None) = map_param.pat.kind

View file

@ -14,7 +14,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, arg: &
if !expr.span.in_external_macro(cx.sess().source_map())
&& is_trait_method(cx, expr, sym::Iterator)
&& let ExprKind::Closure(closure) = arg.kind
&& let body = cx.tcx.hir().body(closure.body)
&& let body = cx.tcx.hir_body(closure.body)
&& let value = peel_blocks(body.value)
// Indexing should be fine as `filter_map` always has 1 input, we unfortunately need both
// `inputs` and `params` here as we need both the type and the span
@ -31,7 +31,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, arg: &
&& is_copy(cx, param_ty)
&& let ExprKind::MethodCall(_, recv, [then_arg], _) = value.kind
&& let ExprKind::Closure(then_closure) = then_arg.kind
&& let then_body = peel_blocks(cx.tcx.hir().body(then_closure.body).value)
&& let then_body = peel_blocks(cx.tcx.hir_body(then_closure.body).value)
&& let Some(def_id) = cx.typeck_results().type_dependent_def_id(value.hir_id)
&& cx.tcx.is_diagnostic_item(sym::bool_then, def_id)
&& !is_from_proc_macro(cx, expr)

View file

@ -19,7 +19,7 @@ fn peel_non_expn_blocks<'tcx>(expr: &'tcx Expr<'tcx>) -> Option<&'tcx Expr<'tcx>
pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, map_arg: &Expr<'_>, map_span: Span) {
if is_type_lang_item(cx, cx.typeck_results().expr_ty(expr), LangItem::String)
&& let ExprKind::Closure(closure) = map_arg.kind
&& let body = cx.tcx.hir().body(closure.body)
&& let body = cx.tcx.hir_body(closure.body)
&& let Some(value) = peel_non_expn_blocks(body.value)
&& let Some(mac) = root_macro_call_first_node(cx, value)
&& is_format_macro(cx, mac.def_id)

View file

@ -95,7 +95,7 @@ fn is_method(
false
},
ExprKind::Closure(&hir::Closure { body, .. }) => {
let body = cx.tcx.hir().body(body);
let body = cx.tcx.hir_body(body);
let closure_expr = peel_blocks(body.value);
let params = body.params.iter().map(|param| param.pat).collect::<Vec<_>>();
is_method(cx, closure_expr, type_symbol, method_name, params.as_slice())

View file

@ -30,7 +30,7 @@ pub(super) fn check<'tcx>(
&& let Body {
params: [p],
value: body_expr,
} = cx.tcx.hir().body(c.body)
} = cx.tcx.hir_body(c.body)
&& let PatKind::Tuple([key_pat, val_pat], _) = p.pat.kind
&& let (replacement_kind, annotation, bound_ident) = match (&key_pat.kind, &val_pat.kind) {
(key, PatKind::Binding(ann, _, value, _)) if pat_is_wild(cx, key, m_arg) => ("value", ann, value),

View file

@ -62,7 +62,7 @@ pub(super) fn check<'tcx>(
let ExprKind::Closure(closure) = expr.kind else {
return;
};
let body @ Body { params: [p], .. } = cx.tcx.hir().body(closure.body) else {
let body @ Body { params: [p], .. } = cx.tcx.hir_body(closure.body) else {
return;
};
let mut delegate = MoveDelegate {

View file

@ -22,7 +22,7 @@ pub(crate) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, arg: &Expr<'_>, name:
&& (is_diag_trait_item(cx, fn_id, sym::Iterator)
|| (msrv.meets(msrvs::OPTION_RESULT_INSPECT)
&& (is_diag_item_method(cx, fn_id, sym::Option) || is_diag_item_method(cx, fn_id, sym::Result))))
&& let body = cx.tcx.hir().body(c.body)
&& let body = cx.tcx.hir_body(c.body)
&& let [param] = body.params
&& let PatKind::Binding(BindingMode(ByRef::No, Mutability::Not), arg_id, _, None) = param.pat.kind
&& let arg_ty = typeck.node_type(arg_id)
@ -45,7 +45,7 @@ pub(crate) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, arg: &Expr<'_>, name:
let can_lint = for_each_expr_without_closures(block.stmts, |e| {
if let ExprKind::Closure(c) = e.kind {
// Nested closures don't need to treat returns specially.
let _: Option<!> = for_each_expr(cx, cx.tcx.hir().body(c.body).value, |e| {
let _: Option<!> = for_each_expr(cx, cx.tcx.hir_body(c.body).value, |e| {
if path_to_local_id(e, arg_id) {
let (kind, same_ctxt) = check_use(cx, e);
match (kind, same_ctxt && e.span.ctxt() == ctxt) {

View file

@ -44,7 +44,7 @@ fn is_ok_wrapping(cx: &LateContext<'_>, map_expr: &Expr<'_>) -> bool {
match map_expr.kind {
ExprKind::Path(ref qpath) if is_res_lang_ctor(cx, cx.qpath_res(qpath, map_expr.hir_id), ResultOk) => true,
ExprKind::Closure(closure) => {
let body = cx.tcx.hir().body(closure.body);
let body = cx.tcx.hir_body(closure.body);
if let PatKind::Binding(_, param_id, ..) = body.params[0].pat.kind
&& let ExprKind::Call(callee, [ok_arg]) = body.value.kind
&& is_res_lang_ctor(cx, path_res(cx, callee), ResultOk)

View file

@ -47,7 +47,7 @@ pub(super) fn check(cx: &LateContext<'_>, e: &hir::Expr<'_>, recv: &hir::Expr<'_
{
match arg.kind {
hir::ExprKind::Closure(&hir::Closure { body, .. }) => {
let closure_body = cx.tcx.hir().body(body);
let closure_body = cx.tcx.hir_body(body);
let closure_expr = peel_blocks(closure_body.value);
match closure_body.params[0].pat.kind {
hir::PatKind::Ref(inner, Mutability::Not) => {

View file

@ -16,7 +16,7 @@ pub(super) fn check(cx: &LateContext<'_>, e: &Expr<'_>, arg: &Expr<'_>) {
fn_decl_span,
..
}) = arg.kind
&& let closure_body = cx.tcx.hir().body(body)
&& let closure_body = cx.tcx.hir_body(body)
&& let [param] = closure_body.params
&& let PatKind::Wild = param.pat.kind
{

View file

@ -68,7 +68,7 @@ pub(super) fn check(
let mut applicability = Applicability::MaybeIncorrect;
if let Some(range) = higher::Range::hir(receiver)
&& let ExprKind::Closure(Closure { body, .. }) = arg.kind
&& let body_hir = cx.tcx.hir().body(*body)
&& let body_hir = cx.tcx.hir_body(*body)
&& let Body {
params: [param],
value: body_expr,

View file

@ -4716,7 +4716,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
if sig.decl.implicit_self.has_implicit_self()
&& !(self.avoid_breaking_exported_api
&& cx.effective_visibilities.is_exported(impl_item.owner_id.def_id))
&& let Some(first_arg) = iter_input_pats(sig.decl, cx.tcx.hir().body(id)).next()
&& let Some(first_arg) = iter_input_pats(sig.decl, cx.tcx.hir_body(id)).next()
&& let Some(first_arg_ty) = first_arg_ty_opt
{
wrong_self_convention::check(
@ -4852,7 +4852,7 @@ impl Methods {
),
Some(("chars", recv, _, _, _))
if let ExprKind::Closure(arg) = arg.kind
&& let body = cx.tcx.hir().body(arg.body)
&& let body = cx.tcx.hir_body(arg.body)
&& let [param] = body.params =>
{
string_lit_chars_any::check(cx, expr, recv, param, peel_blocks(body.value), &self.msrv);

View file

@ -99,7 +99,7 @@ fn handle_expr(
pub(super) fn check(cx: &LateContext<'_>, call_expr: &Expr<'_>, recv: &Expr<'_>, closure_arg: &Expr<'_>, is_all: bool) {
if let ExprKind::Closure(&Closure { body, .. }) = closure_arg.kind
&& let body = cx.tcx.hir().body(body)
&& let body = cx.tcx.hir_body(body)
&& let Some(first_param) = body.params.first()
&& let ExprKind::MethodCall(method, mut recv, [], _) = recv.kind
&& method.ident.name.as_str() == "chars"

View file

@ -498,7 +498,7 @@ fn get_captured_ids(cx: &LateContext<'_>, ty: Ty<'_>) -> HirIdSet {
}
},
ty::Closure(def_id, _) => {
let closure_hir_node = cx.tcx.hir().get_if_local(*def_id).unwrap();
let closure_hir_node = cx.tcx.hir_get_if_local(*def_id).unwrap();
if let Node::Expr(closure_expr) = closure_hir_node {
can_move_expr_to_closure(cx, closure_expr)
.unwrap()

View file

@ -27,7 +27,7 @@ pub(super) fn check<'tcx>(
let if_then = match then_method_name {
"then" if let ExprKind::Closure(closure) = then_arg.kind => {
let body = cx.tcx.hir().body(closure.body);
let body = cx.tcx.hir_body(closure.body);
snippet_with_applicability(cx, body.value.span, "..", &mut applicability)
},
"then_some" => snippet_with_applicability(cx, then_arg.span, "..", &mut applicability),

View file

@ -54,7 +54,7 @@ pub(super) fn check(
})
},
hir::ExprKind::Closure(&hir::Closure { body, .. }) => {
let closure_body = cx.tcx.hir().body(body);
let closure_body = cx.tcx.hir_body(body);
let closure_expr = peel_blocks(closure_body.value);
match &closure_expr.kind {

View file

@ -60,7 +60,7 @@ pub(super) fn check<'tcx>(
let self_snippet = snippet(cx, recv.span, "..");
if let hir::ExprKind::Closure(&hir::Closure { body, fn_decl_span, .. }) = map_arg.kind
&& let arg_snippet = snippet(cx, fn_decl_span, "..")
&& let body = cx.tcx.hir().body(body)
&& let body = cx.tcx.hir_body(body)
&& let Some((func, [arg_char])) = reduce_unit_expression(body.value)
&& let Some(id) = path_def_id(cx, func).map(|ctor_id| cx.tcx.parent(ctor_id))
&& Some(id) == cx.tcx.lang_items().option_some_variant()

View file

@ -253,7 +253,7 @@ pub(super) fn check<'tcx>(
fn closure_body_returns_empty_to_string(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> bool {
if let hir::ExprKind::Closure(&hir::Closure { body, .. }) = e.kind {
let body = cx.tcx.hir().body(body);
let body = cx.tcx.hir_body(body);
if body.params.is_empty()
&& let hir::Expr { kind, .. } = &body.value

View file

@ -23,7 +23,7 @@ pub(super) fn check<'tcx>(
// We check that it is mapped as `Some`.
&& is_res_lang_ctor(cx, path_res(cx, map_arg), OptionSome)
&& let hir::ExprKind::Closure(&hir::Closure { body, .. }) = def_arg.kind
&& let body = cx.tcx.hir().body(body)
&& let body = cx.tcx.hir_body(body)
// And finally we check that we return a `None` in the "else case".
&& is_res_lang_ctor(cx, path_res(cx, peel_blocks(body.value)), OptionNone)
{

View file

@ -44,7 +44,7 @@ pub(super) fn check<'tcx>(
};
let closure_arg = fn_decl.inputs[0];
let closure_expr = peel_blocks(cx.tcx.hir().body(body).value);
let closure_expr = peel_blocks(cx.tcx.hir_body(body).value);
let mut applicability = Applicability::MachineApplicable;
let arg_snip = snippet_with_applicability(cx, closure_arg.span, "_", &mut applicability);

View file

@ -37,7 +37,7 @@ pub(super) fn check<'tcx>(
let mut applicability = Applicability::MachineApplicable;
let any_search_snippet = if search_method == "find"
&& let ExprKind::Closure(&hir::Closure { body, .. }) = search_arg.kind
&& let closure_body = cx.tcx.hir().body(body)
&& let closure_body = cx.tcx.hir_body(body)
&& let Some(closure_arg) = closure_body.params.first()
{
if let PatKind::Ref(..) = closure_arg.pat.kind {

View file

@ -10,7 +10,7 @@ use super::SUSPICIOUS_MAP;
pub fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, count_recv: &hir::Expr<'_>, map_arg: &hir::Expr<'_>) {
if is_trait_method(cx, count_recv, sym::Iterator)
&& let hir::ExprKind::Closure(closure) = expr_or_init(cx, map_arg).kind
&& let closure_body = cx.tcx.hir().body(closure.body)
&& let closure_body = cx.tcx.hir_body(closure.body)
&& !cx.typeck_results().expr_ty(closure_body.value).is_unit()
{
if let Some(map_mutated_vars) = mutated_variables(closure_body.value, cx) {

View file

@ -20,7 +20,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'tcx>, a
}
if let hir::ExprKind::Closure(&hir::Closure { body, .. }) = arg.kind {
let body = cx.tcx.hir().body(body);
let body = cx.tcx.hir_body(body);
let arg_id = body.params[0].pat.hir_id;
let mutates_arg = mutated_variables(body.value, cx).is_none_or(|used_mutably| used_mutably.contains(&arg_id));
let (clone_or_copy_needed, _) = clone_or_copy_needed(cx, body.params[0].pat, body.value);

View file

@ -62,7 +62,7 @@ fn check_fold_with_op(
) {
if let hir::ExprKind::Closure(&hir::Closure { body, .. }) = acc.kind
// Extract the body of the closure passed to fold
&& let closure_body = cx.tcx.hir().body(body)
&& let closure_body = cx.tcx.hir_body(body)
&& let closure_expr = peel_blocks(closure_body.value)
// Check if the closure body is of the form `acc <op> some_expr(x)`

View file

@ -25,7 +25,7 @@ pub(super) fn check<'tcx>(
if is_option || is_result || is_bool {
if let hir::ExprKind::Closure(&hir::Closure { body, fn_decl, .. }) = arg.kind {
let body = cx.tcx.hir().body(body);
let body = cx.tcx.hir_body(body);
let body_expr = &body.value;
if usage::BindingUsageFinder::are_params_used(cx, body) || is_from_proc_macro(cx, expr) {

View file

@ -99,7 +99,7 @@ pub(super) fn check(
("None", "unwrap_or_else", _) => match args[0].kind {
hir::ExprKind::Closure(hir::Closure { body, .. }) => Some(vec![
(
expr.span.with_hi(cx.tcx.hir().body(*body).value.span.lo()),
expr.span.with_hi(cx.tcx.hir_body(*body).value.span.lo()),
String::new(),
),
(expr.span.with_lo(args[0].span.hi()), String::new()),

View file

@ -63,7 +63,7 @@ pub(super) fn check<'a>(
let ext_def_span = def.span.until(map.span);
let (sugg, method, applicability) = if let ExprKind::Closure(map_closure) = map.kind
&& let closure_body = cx.tcx.hir().body(map_closure.body)
&& let closure_body = cx.tcx.hir_body(map_closure.body)
&& let closure_body_value = closure_body.value.peel_blocks()
&& let ExprKind::Binary(op, l, r) = closure_body_value.kind
&& let Some(param) = closure_body.params.first()

View file

@ -53,7 +53,7 @@ pub(super) fn check<'tcx>(
// lint if the caller of `map_or_else()` is a `Result`
if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(recv), sym::Result)
&& let ExprKind::Closure(&Closure { body, .. }) = map_arg.kind
&& let body = cx.tcx.hir().body(body)
&& let body = cx.tcx.hir_body(body)
&& let Some(first_param) = body.params.first()
{
let body_expr = peel_blocks(body.value);

View file

@ -117,7 +117,7 @@ fn detect_lint(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, arg: &Exp
&& let Some(impl_id) = cx.tcx.impl_of_method(method_id)
&& cx.tcx.type_of(impl_id).instantiate_identity().is_slice()
&& let ExprKind::Closure(&Closure { body, .. }) = arg.kind
&& let closure_body = cx.tcx.hir().body(body)
&& let closure_body = cx.tcx.hir_body(body)
&& let &[
Param {
pat:

View file

@ -506,7 +506,7 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty<
if has_lifetime(output_ty) && has_lifetime(ty) {
return false;
}
let body = cx.tcx.hir().body(*body_id);
let body = cx.tcx.hir_body(*body_id);
let body_expr = &body.value;
let mut count = 0;
return find_all_ret_expressions(cx, body_expr, |_| {

View file

@ -46,7 +46,7 @@ pub(super) fn check(cx: &LateContext<'_>, call_expr: &Expr<'_>, recv: &Expr<'_>,
&& is_trait_method(cx, call_expr, sym::Iterator)
// And the map argument is a closure
&& let ExprKind::Closure(closure) = closure_arg.kind
&& let closure_body = cx.tcx.hir().body(closure.body)
&& let closure_body = cx.tcx.hir_body(closure.body)
// And that closure has one argument ...
&& let [closure_param] = closure_body.params
// .. which is a tuple of 2 elements

View file

@ -113,7 +113,7 @@ fn is_calling_clone(cx: &LateContext<'_>, arg: &hir::Expr<'_>) -> bool {
match arg.kind {
hir::ExprKind::Closure(&hir::Closure { body, .. })
// If it's a closure, we need to check what is called.
if let closure_body = cx.tcx.hir().body(body)
if let closure_body = cx.tcx.hir_body(body)
&& let [param] = closure_body.params
&& let hir::PatKind::Binding(_, local_id, ..) = strip_pat_refs(param.pat).kind =>
{

View file

@ -213,8 +213,8 @@ impl<'tcx> LateLintPass<'tcx> for MissingFieldsInDebug {
&& !item.span.from_expansion()
// find `Debug::fmt` function
&& let Some(fmt_item) = items.iter().find(|i| i.ident.name == sym::fmt)
&& let ImplItem { kind: ImplItemKind::Fn(_, body_id), .. } = cx.tcx.hir().impl_item(fmt_item.id)
&& let body = cx.tcx.hir().body(*body_id)
&& let ImplItem { kind: ImplItemKind::Fn(_, body_id), .. } = cx.tcx.hir_impl_item(fmt_item.id)
&& let body = cx.tcx.hir_body(*body_id)
&& let ExprKind::Block(block, _) = body.value.kind
// inspect `self`
&& let self_ty = cx.tcx.type_of(self_path_did).skip_binder().peel_refs()

View file

@ -105,7 +105,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
// note: we need to check if the trait is exported so we can't use
// `LateLintPass::check_trait_item` here.
for tit in trait_items {
let tit_ = cx.tcx.hir().trait_item(tit.id);
let tit_ = cx.tcx.hir_trait_item(tit.id);
match tit_.kind {
hir::TraitItemKind::Const(..) | hir::TraitItemKind::Type(..) => {},
hir::TraitItemKind::Fn(..) => {
@ -113,7 +113,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
// trait method with default body needs inline in case
// an impl is not provided
let desc = "a default trait method";
let item = cx.tcx.hir().trait_item(tit.id);
let item = cx.tcx.hir_trait_item(tit.id);
let attrs = cx.tcx.hir().attrs(item.hir_id());
check_missing_inline_attrs(cx, attrs, item.span, desc);
}

View file

@ -71,7 +71,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessForEach {
// Skip the lint if the body is not block because this is simpler than `for` loop.
// e.g. `v.iter().for_each(f)` is simpler and clearer than using `for` loop.
&& let ExprKind::Closure(&Closure { body, .. }) = for_each_arg.kind
&& let body = cx.tcx.hir().body(body)
&& let body = cx.tcx.hir_body(body)
// Skip the lint if the body is not safe, so as not to suggest `for … in … unsafe {}`
// and suggesting `for … in … { unsafe { } }` is a little ugly.
&& let ExprKind::Block(Block { rules: BlockCheckMode::DefaultBlock, .. }, ..) = body.value.kind

View file

@ -103,7 +103,6 @@ fn check_closures<'tcx>(
checked_closures: &mut FxHashSet<LocalDefId>,
closures: FxIndexSet<LocalDefId>,
) {
let hir = cx.tcx.hir();
for closure in closures {
if !checked_closures.insert(closure) {
continue;
@ -114,7 +113,7 @@ fn check_closures<'tcx>(
.tcx
.hir_node_by_def_id(closure)
.associated_body()
.map(|(_, body_id)| hir.body(body_id))
.map(|(_, body_id)| cx.tcx.hir_body(body_id))
{
euv::ExprUseVisitor::for_clippy(cx, closure, &mut *ctx)
.consume_body(body)

View file

@ -67,7 +67,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault {
{
for assoc_item in *items {
if assoc_item.kind == (hir::AssocItemKind::Fn { has_self: false }) {
let impl_item = cx.tcx.hir().impl_item(assoc_item.id);
let impl_item = cx.tcx.hir_impl_item(assoc_item.id);
if impl_item.span.in_external_macro(cx.sess().source_map()) {
return;
}

View file

@ -121,10 +121,10 @@ impl LateLintPass<'_> for NonCanonicalImpls {
if cx.tcx.is_automatically_derived(item.owner_id.to_def_id()) {
return;
}
let ImplItemKind::Fn(_, impl_item_id) = cx.tcx.hir().impl_item(impl_item.impl_item_id()).kind else {
let ImplItemKind::Fn(_, impl_item_id) = cx.tcx.hir_impl_item(impl_item.impl_item_id()).kind else {
return;
};
let body = cx.tcx.hir().body(impl_item_id);
let body = cx.tcx.hir_body(impl_item_id);
let ExprKind::Block(block, ..) = body.value.kind else {
return;
};

View file

@ -214,7 +214,7 @@ impl LazyInfo {
&& state.once_cell_sync_lazy.contains(&path_def_id)
{
let ty_span_no_args = path_span_without_args(path);
let body = cx.tcx.hir().body(body_id);
let body = cx.tcx.hir_body(body_id);
// visit body to collect `Lazy::new` calls
let mut new_fn_calls = FxIndexMap::default();

View file

@ -136,7 +136,7 @@ impl PassByRefOrValue {
}
let fn_sig = cx.tcx.fn_sig(def_id).instantiate_identity();
let fn_body = cx.enclosing_body.map(|id| cx.tcx.hir().body(id));
let fn_body = cx.enclosing_body.map(|id| cx.tcx.hir_body(id));
// Gather all the lifetimes found in the output type which may affect whether
// `TRIVIALLY_COPY_PASS_BY_REF` should be linted.

View file

@ -75,7 +75,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantAsyncBlock {
/// any variable by ref.
fn desugar_async_block<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<&'tcx Expr<'tcx>> {
if let ExprKind::Closure(Closure { body, def_id, kind, .. }) = expr.kind
&& let body = cx.tcx.hir().body(*body)
&& let body = cx.tcx.hir_body(*body)
&& matches!(
kind,
ClosureKind::Coroutine(CoroutineKind::Desugared(

View file

@ -90,7 +90,7 @@ fn find_innermost_closure<'tcx>(
let mut data = None;
while let ExprKind::Closure(closure) = expr.kind
&& let body = cx.tcx.hir().body(closure.body)
&& let body = cx.tcx.hir_body(closure.body)
&& {
let mut visitor = ReturnVisitor;
!visitor.visit_expr(body.value).is_break()
@ -179,7 +179,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClosureCall {
// Like `async fn`, async closures are wrapped in an additional block
// to move all of the closure's arguments into the future.
let async_closure_body = cx.tcx.hir().body(closure.body).value;
let async_closure_body = cx.tcx.hir_body(closure.body).value;
let ExprKind::Block(block, _) = async_closure_body.kind else {
return;
};

View file

@ -205,7 +205,7 @@ impl<'tcx> LateLintPass<'tcx> for Return {
// Ensure this is not the final stmt, otherwise removing it would cause a compile error
&& let OwnerNode::Item(item) = cx.tcx.hir_owner_node(cx.tcx.hir().get_parent_item(expr.hir_id))
&& let ItemKind::Fn { body, .. } = item.kind
&& let block = cx.tcx.hir().body(body).value
&& let block = cx.tcx.hir_body(body).value
&& let ExprKind::Block(block, _) = block.kind
&& !is_inside_let_else(cx.tcx, expr)
&& let [.., final_stmt] = block.stmts

View file

@ -50,9 +50,9 @@ impl<'tcx> LateLintPass<'tcx> for SameNameMethod {
fn check_crate_post(&mut self, cx: &LateContext<'tcx>) {
let mut map = FxHashMap::<Res, ExistingName>::default();
for id in cx.tcx.hir().items() {
for id in cx.tcx.hir_free_items() {
if matches!(cx.tcx.def_kind(id.owner_id), DefKind::Impl { .. })
&& let item = cx.tcx.hir().item(id)
&& let item = cx.tcx.hir_item(id)
&& let ItemKind::Impl(Impl {
items,
of_trait,

View file

@ -138,7 +138,7 @@ fn get_char_span<'tcx>(cx: &'_ LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Optio
fn check_manual_pattern_char_comparison(cx: &LateContext<'_>, method_arg: &Expr<'_>, msrv: &Msrv) {
if let ExprKind::Closure(closure) = method_arg.kind
&& let body = cx.tcx.hir().body(closure.body)
&& let body = cx.tcx.hir_body(closure.body)
&& let Some(PatKind::Binding(_, binding, ..)) = body.params.first().map(|p| p.pat.kind)
{
let mut set_char_spans: Vec<Span> = Vec::new();

View file

@ -66,7 +66,7 @@ impl<'tcx> LateLintPass<'tcx> for SuspiciousImpl {
&& let parent_fn = cx.tcx.hir().get_parent_item(expr.hir_id).def_id
&& let hir::Node::ImplItem(impl_item) = cx.tcx.hir_node_by_def_id(parent_fn)
&& let hir::ImplItemKind::Fn(_, body_id) = impl_item.kind
&& let body = cx.tcx.hir().body(body_id)
&& let body = cx.tcx.hir_body(body_id)
&& let parent_fn = cx.tcx.hir().get_parent_item(expr.hir_id).def_id
&& let Some(trait_ref) = trait_ref_of_method(cx, parent_fn)
&& let trait_id = trait_ref.path.res.def_id()

View file

@ -135,7 +135,7 @@ impl<'tcx> LateLintPass<'tcx> for TraitBounds {
&& let Some(Node::Item(Item {
kind: ItemKind::Trait(_, _, _, self_bounds, _),
..
})) = cx.tcx.hir().get_if_local(*def_id)
})) = cx.tcx.hir_get_if_local(*def_id)
{
if self_bounds_map.is_empty() {
for bound in *self_bounds {

View file

@ -96,10 +96,10 @@ fn is_any_trait(cx: &LateContext<'_>, t: &hir::Ty<'_>) -> bool {
fn get_bounds_if_impl_trait<'tcx>(cx: &LateContext<'tcx>, qpath: &QPath<'_>, id: HirId) -> Option<GenericBounds<'tcx>> {
if let Some(did) = cx.qpath_res(qpath, id).opt_def_id()
&& let Some(Node::GenericParam(generic_param)) = cx.tcx.hir().get_if_local(did)
&& let Some(Node::GenericParam(generic_param)) = cx.tcx.hir_get_if_local(did)
&& let GenericParamKind::Type { synthetic, .. } = generic_param.kind
&& synthetic
&& let Some(generics) = cx.tcx.hir().get_generics(id.owner.def_id)
&& let Some(generics) = cx.tcx.hir_get_generics(id.owner.def_id)
&& let Some(pred) = generics.bounds_for_param(did.expect_local()).next()
{
Some(pred.bounds)

View file

@ -326,9 +326,9 @@ impl UnconditionalRecursion {
.find(|item| {
item.kind == AssocKind::Fn && item.def_id.is_local() && item.name == kw::Default
})
&& let Some(body_node) = cx.tcx.hir().get_if_local(assoc_item.def_id)
&& let Some(body_node) = cx.tcx.hir_get_if_local(assoc_item.def_id)
&& let Some(body_id) = body_node.body_id()
&& let body = cx.tcx.hir().body(body_id)
&& let body = cx.tcx.hir_body(body_id)
// We don't want to keep it if it has conditional return.
&& let [return_expr] = get_return_calls_in_body(body).as_slice()
&& let ExprKind::Call(call_expr, _) = return_expr.kind

View file

@ -245,7 +245,7 @@ impl<'tcx> LateLintPass<'tcx> for UndocumentedUnsafeBlocks {
// const and static items only need a safety comment if their body is an unsafe block, lint otherwise
(&ItemKind::Const(.., body) | &ItemKind::Static(.., body), HasSafetyComment::Yes(pos)) => {
if !is_lint_allowed(cx, UNNECESSARY_SAFETY_COMMENT, body.hir_id) {
let body = cx.tcx.hir().body(body);
let body = cx.tcx.hir_body(body);
if !matches!(
body.value.kind, hir::ExprKind::Block(block, _)
if block.rules == BlockCheckMode::UnsafeBlock(UnsafeSource::UserProvided)
@ -558,7 +558,7 @@ fn comment_start_before_item_in_mod(
// some_item /* comment */ unsafe impl T {}
// ^-------^ returns the end of this span
// ^---------------^ finally checks comments in this range
let prev_item = cx.tcx.hir().item(parent_mod.item_ids[idx - 1]);
let prev_item = cx.tcx.hir_item(parent_mod.item_ids[idx - 1]);
if let Some(sp) = walk_span_to_context(prev_item.span, SyntaxContext::root()) {
return Some(sp.hi());
}
@ -605,7 +605,7 @@ fn span_from_macro_expansion_has_safety_comment(cx: &LateContext<'_>, span: Span
fn get_body_search_span(cx: &LateContext<'_>) -> Option<Span> {
let body = cx.enclosing_body?;
let map = cx.tcx.hir();
let mut span = map.body(body).value.span;
let mut span = cx.tcx.hir_body(body).value.span;
let mut maybe_global_var = false;
for (_, node) in map.parent_iter(body.hir_id) {
match node {

View file

@ -123,7 +123,7 @@ fn check_arg<'tcx>(cx: &LateContext<'tcx>, arg: &'tcx Expr<'tcx>) -> Option<(Spa
&& let ty = cx.tcx.instantiate_bound_regions_with_erased(ret_ty)
&& ty.is_unit()
{
let body = cx.tcx.hir().body(body);
let body = cx.tcx.hir_body(body);
if let ExprKind::Block(block, _) = body.value.kind
&& block.expr.is_none()
&& let Some(stmt) = block.stmts.last()

View file

@ -84,7 +84,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, local: &'tcx LetStmt<'_>) {
if let PatKind::Binding(_, binding_hir_id, ..) = local.pat.kind
&& let Some(body_id) = cx.enclosing_body.as_ref()
{
let body = cx.tcx.hir().body(*body_id);
let body = cx.tcx.hir_body(*body_id);
// Collect variable usages
let mut visitor = UnitVariableCollector::new(binding_hir_id);

View file

@ -77,7 +77,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedSelf {
&& assoc_item.fn_has_self_parameter
&& let ImplItemKind::Fn(.., body_id) = &impl_item.kind
&& (!cx.effective_visibilities.is_exported(impl_item.owner_id.def_id) || !self.avoid_breaking_exported_api)
&& let body = cx.tcx.hir().body(*body_id)
&& let body = cx.tcx.hir_body(*body_id)
&& let [self_param, ..] = body.params
&& !is_local_used(cx, body, self_param.pat.hir_id)
&& !contains_todo(cx, body)

View file

@ -74,7 +74,7 @@ impl<'tcx> LateLintPass<'tcx> for UnwrapInResult {
fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_item: &'tcx hir::ImplItem<'_>) {
if let ImplItemKind::Fn(_, body_id) = impl_item.kind {
let body = cx.tcx.hir().body(body_id);
let body = cx.tcx.hir_body(body_id);
let typeck = cx.tcx.typeck(impl_item.owner_id.def_id);
let mut result = Vec::new();
let _: Option<!> = for_each_expr(cx, body.value, |e| {

View file

@ -637,9 +637,9 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
}
fn body(&self, body_id: &Binding<hir::BodyId>) {
let expr = self.cx.tcx.hir().body(body_id.value).value;
let expr = self.cx.tcx.hir_body(body_id.value).value;
bind!(self, expr);
chain!(self, "{expr} = &cx.tcx.hir().body({body_id}).value");
chain!(self, "{expr} = &cx.tcx.hir_body({body_id}).value");
self.expr(expr);
}

View file

@ -80,7 +80,7 @@ impl<'tcx> LateLintPass<'tcx> for CollapsibleCalls {
if let ExprKind::Call(func, [call_cx, call_lint, call_sp, call_msg, call_f]) = expr.kind
&& is_expr_path_def_path(cx, func, &["clippy_utils", "diagnostics", "span_lint_and_then"])
&& let ExprKind::Closure(&Closure { body, .. }) = call_f.kind
&& let body = cx.tcx.hir().body(body)
&& let body = cx.tcx.hir_body(body)
&& let only_expr = peel_blocks_with_stmt(body.value)
&& let ExprKind::MethodCall(ps, recv, span_call_args, _) = &only_expr.kind
&& let ExprKind::Path(..) = recv.kind

View file

@ -37,7 +37,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidPaths {
ty::TypingEnv::post_analysis(cx.tcx, item.owner_id),
cx.tcx.typeck(item.owner_id),
)
.eval_simple(cx.tcx.hir().body(body_id).value)
.eval_simple(cx.tcx.hir_body(body_id).value)
&& let Some(path) = path
.iter()
.map(|x| {

View file

@ -108,7 +108,7 @@ impl<'tcx> LateLintPass<'tcx> for LintWithoutLintPass {
if is_lint_ref_type(cx, ty) {
check_invalid_clippy_version_attribute(cx, item);
let expr = &cx.tcx.hir().body(body_id).value;
let expr = &cx.tcx.hir_body(body_id).value;
let fields = if let ExprKind::AddrOf(_, _, inner_exp) = expr.kind
&& let ExprKind::Struct(_, struct_fields, _) = inner_exp.kind
{

View file

@ -47,7 +47,6 @@ declare_lint_pass!(ZeroRepeatSideEffects => [ZERO_REPEAT_SIDE_EFFECTS]);
impl LateLintPass<'_> for ZeroRepeatSideEffects {
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &rustc_hir::Expr<'_>) {
let hir_map = cx.tcx.hir();
if let Some(args) = VecArgs::hir(cx, expr)
&& let VecArgs::Repeat(inner_expr, len) = args
&& let ExprKind::Lit(l) = len.kind
@ -62,7 +61,7 @@ impl LateLintPass<'_> for ZeroRepeatSideEffects {
// sessions).
else if let ExprKind::Repeat(inner_expr, const_arg) = expr.kind
&& let ConstArgKind::Anon(anon_const) = const_arg.kind
&& let length_expr = hir_map.body(anon_const.body).value
&& let length_expr = cx.tcx.hir_body(anon_const.body).value
&& !length_expr.span.from_expansion()
&& let ExprKind::Lit(literal) = length_expr.kind
&& let LitKind::Int(Pu128(0), _) = literal.node