Skip to content

Commit

Permalink
Move methods from Map to TyCtxt, part 3.
Browse files Browse the repository at this point in the history
Continuing the work from #137162.

Every method gains a `hir_` prefix.
  • Loading branch information
nnethercote committed Feb 21, 2025
1 parent a81c264 commit c2d75cf
Show file tree
Hide file tree
Showing 51 changed files with 96 additions and 108 deletions.
2 changes: 1 addition & 1 deletion clippy_lints/src/assigning_clones.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl<'tcx> LateLintPass<'tcx> for AssigningClones {
&& !cx.tcx.is_builtin_derived(resolved_impl)
// Don't suggest calling a function we're implementing.
&& resolved_impl.as_local().is_none_or(|block_id| {
cx.tcx.hir().parent_owner_iter(e.hir_id).all(|(id, _)| id.def_id != block_id)
cx.tcx.hir_parent_owner_iter(e.hir_id).all(|(id, _)| id.def_id != block_id)
})
&& let resolved_assoc_items = cx.tcx.associated_items(resolved_impl)
// Only suggest if `clone_from`/`clone_into` is explicitly implemented
Expand Down
3 changes: 1 addition & 2 deletions clippy_lints/src/doc/missing_headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ pub fn check(
if !check_private_items
&& cx
.tcx
.hir()
.parent_iter(owner_id.into())
.hir_parent_iter(owner_id.into())
.any(|(id, _node)| is_doc_hidden(cx.tcx.hir().attrs(id)))
{
return;
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/doc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,7 @@ impl<'tcx> Visitor<'tcx> for FindPanicUnwrap<'_, 'tcx> {
"assert" | "assert_eq" | "assert_ne"
)
{
self.is_const = self.cx.tcx.hir().is_inside_const_context(expr.hir_id);
self.is_const = self.cx.tcx.hir_is_inside_const_context(expr.hir_id);
self.panic_span = Some(macro_call.span);
}
}
Expand Down
3 changes: 1 addition & 2 deletions clippy_lints/src/escape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal {

let parent_id = cx
.tcx
.hir()
.get_parent_item(cx.tcx.local_def_id_to_hir_id(fn_def_id))
.hir_get_parent_item(cx.tcx.local_def_id_to_hir_id(fn_def_id))
.def_id;

let mut trait_self_ty = None;
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/exit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl<'tcx> LateLintPass<'tcx> for Exit {
&& let ExprKind::Path(ref path) = path_expr.kind
&& let Some(def_id) = cx.qpath_res(path, path_expr.hir_id).opt_def_id()
&& cx.tcx.is_diagnostic_item(sym::process_exit, def_id)
&& let parent = cx.tcx.hir().get_parent_item(e.hir_id)
&& let parent = cx.tcx.hir_get_parent_item(e.hir_id)
&& let OwnerNode::Item(Item{kind: ItemKind::Fn{ .. }, ..}) = cx.tcx.hir_owner_node(parent)
// If the next item up is a function we check if it is an entry point
// and only then emit a linter warning
Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/indexing_slicing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl IndexingSlicing {
impl<'tcx> LateLintPass<'tcx> for IndexingSlicing {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
if let ExprKind::Index(array, index, _) = &expr.kind
&& (!self.suppress_restriction_lint_in_const || !cx.tcx.hir().is_inside_const_context(expr.hir_id))
&& (!self.suppress_restriction_lint_in_const || !cx.tcx.hir_is_inside_const_context(expr.hir_id))
&& let expr_ty = cx.typeck_results().expr_ty(array)
&& let mut deref = deref_chain(cx, expr_ty)
&& deref.any(|l| {
Expand Down Expand Up @@ -181,7 +181,7 @@ impl<'tcx> LateLintPass<'tcx> for IndexingSlicing {
span_lint_and_then(cx, INDEXING_SLICING, expr.span, "slicing may panic", |diag| {
diag.help(help_msg);

if cx.tcx.hir().is_inside_const_context(expr.hir_id) {
if cx.tcx.hir_is_inside_const_context(expr.hir_id) {
diag.note(note);
}
});
Expand Down Expand Up @@ -223,7 +223,7 @@ impl<'tcx> LateLintPass<'tcx> for IndexingSlicing {
span_lint_and_then(cx, INDEXING_SLICING, expr.span, "indexing may panic", |diag| {
diag.help("consider using `.get(n)` or `.get_mut(n)` instead");

if cx.tcx.hir().is_inside_const_context(expr.hir_id) {
if cx.tcx.hir_is_inside_const_context(expr.hir_id) {
diag.note(note);
}
});
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/large_stack_arrays.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeStackArrays {
&& let ty::Array(element_type, cst) = cx.typeck_results().expr_ty(expr).kind()
&& let Some(element_count) = cst.try_to_target_usize(cx.tcx)
&& let Ok(element_size) = cx.layout_of(*element_type).map(|l| l.size.bytes())
&& !cx.tcx.hir().parent_iter(expr.hir_id).any(|(_, node)| {
&& !cx.tcx.hir_parent_iter(expr.hir_id).any(|(_, node)| {
matches!(
node,
Node::Item(Item {
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/loops/infinite_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub(super) fn check<'tcx>(
}

fn get_parent_fn_ret_ty<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>) -> Option<FnRetTy<'tcx>> {
for (_, parent_node) in cx.tcx.hir().parent_iter(expr.hir_id) {
for (_, parent_node) in cx.tcx.hir_parent_iter(expr.hir_id) {
match parent_node {
// Skip `Coroutine` closures, these are the body of `async fn`, not async closures.
// This is because we still need to backtrack one parent node to get the `OpaqueDef` ty.
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/loops/manual_find.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ fn last_stmt_and_ret<'tcx>(
}
None
}
let mut parent_iter = cx.tcx.hir().parent_iter(expr.hir_id);
let mut parent_iter = cx.tcx.hir_parent_iter(expr.hir_id);
if let Some((node_hir, Node::Stmt(..))) = parent_iter.next()
// This should be the loop
// This should be the function body
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/loops/needless_range_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub(super) fn check<'tcx>(

// ensure that the indexed variable was declared before the loop, see #601
if let Some(indexed_extent) = indexed_extent {
let parent_def_id = cx.tcx.hir().get_parent_item(expr.hir_id);
let parent_def_id = cx.tcx.hir_get_parent_item(expr.hir_id);
let region_scope_tree = cx.tcx.region_scope_tree(parent_def_id);
let pat_extent = region_scope_tree.var_scope(pat.hir_id.local_id).unwrap();
if region_scope_tree.is_subscope_of(indexed_extent, pat_extent) {
Expand Down Expand Up @@ -256,7 +256,7 @@ impl<'tcx> VarVisitor<'_, 'tcx> {
let res = self.cx.qpath_res(seqpath, seqexpr.hir_id);
match res {
Res::Local(hir_id) => {
let parent_def_id = self.cx.tcx.hir().get_parent_item(expr.hir_id);
let parent_def_id = self.cx.tcx.hir_get_parent_item(expr.hir_id);
let extent = self
.cx
.tcx
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/matches/redundant_pattern_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ fn find_method_sugg_for_if_let<'tcx>(
// type needs to be considered, not just the inner type of the branch being matched on.
// Note the last expression in a block is dropped after all local bindings.
let check_ty = if has_else
|| (keyword == "if" && matches!(cx.tcx.hir().parent_iter(expr.hir_id).next(), Some((_, Node::Block(..)))))
|| (keyword == "if" && matches!(cx.tcx.hir_parent_iter(expr.hir_id).next(), Some((_, Node::Block(..)))))
{
op_ty
} else {
Expand Down
3 changes: 1 addition & 2 deletions clippy_lints/src/methods/is_empty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &'_ Expr<'_>, receiver: &Expr<'_

fn is_under_cfg(cx: &LateContext<'_>, id: HirId) -> bool {
cx.tcx
.hir()
.parent_id_iter(id)
.hir_parent_id_iter(id)
.any(|id| cx.tcx.hir().attrs(id).iter().any(|attr| attr.has_name(sym::cfg)))
}

Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/methods/iter_nth_zero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use rustc_span::sym;
use super::ITER_NTH_ZERO;

pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>, arg: &hir::Expr<'_>) {
if let OwnerNode::Item(item) = cx.tcx.hir_owner_node(cx.tcx.hir().get_parent_item(expr.hir_id))
if let OwnerNode::Item(item) = cx.tcx.hir_owner_node(cx.tcx.hir_get_parent_item(expr.hir_id))
&& let def_id = item.owner_id.to_def_id()
&& is_trait_method(cx, expr, sym::Iterator)
&& let Some(Constant::Int(0)) = ConstEvalCtxt::new(cx).eval(arg)
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/methods/manual_c_str_literals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ fn peel_ptr_cast<'tcx>(e: &'tcx Expr<'tcx>) -> &'tcx Expr<'tcx> {
/// ^ given this `x` expression, returns the `foo(...)` expression
fn peel_ptr_cast_ancestors<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'tcx>) -> &'tcx Expr<'tcx> {
let mut prev = e;
for (_, node) in cx.tcx.hir().parent_iter(e.hir_id) {
for (_, node) in cx.tcx.hir_parent_iter(e.hir_id) {
if let Node::Expr(e) = node
&& get_cast_target(e).is_some()
{
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/methods/manual_inspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ pub(crate) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, arg: &Expr<'_>, name:
};
let mut prev_expr = e;

for (_, parent) in cx.tcx.hir().parent_iter(e.hir_id) {
for (_, parent) in cx.tcx.hir_parent_iter(e.hir_id) {
if let Node::Expr(e) = parent {
match e.kind {
ExprKind::Field(_, name)
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/methods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4671,7 +4671,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
return;
}
let name = impl_item.ident.name.as_str();
let parent = cx.tcx.hir().get_parent_item(impl_item.hir_id()).def_id;
let parent = cx.tcx.hir_get_parent_item(impl_item.hir_id()).def_id;
let item = cx.tcx.hir().expect_item(parent);
let self_ty = cx.tcx.type_of(item.owner_id).instantiate_identity();

Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/methods/or_fun_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub(super) fn check<'tcx>(
let in_sugg_method_implementation = {
matches!(
suggested_method_def_id.as_local(),
Some(local_def_id) if local_def_id == cx.tcx.hir().get_parent_item(receiver.hir_id).def_id
Some(local_def_id) if local_def_id == cx.tcx.hir_get_parent_item(receiver.hir_id).def_id
)
};
if in_sugg_method_implementation {
Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/methods/str_splitn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub(super) fn check(
};
let manual = count == 2 && msrv.meets(msrvs::STR_SPLIT_ONCE);

match parse_iter_usage(cx, expr.span.ctxt(), cx.tcx.hir().parent_iter(expr.hir_id)) {
match parse_iter_usage(cx, expr.span.ctxt(), cx.tcx.hir_parent_iter(expr.hir_id)) {
Some(usage) if needless(usage.kind) => lint_needless(cx, method_name, expr, self_arg, pat_arg),
Some(usage) if manual => check_manual_split_once(cx, method_name, expr, self_arg, pat_arg, &usage),
None if manual => {
Expand Down Expand Up @@ -127,7 +127,7 @@ fn check_manual_split_once_indirect(
pat_arg: &Expr<'_>,
) -> Option<()> {
let ctxt = expr.span.ctxt();
let mut parents = cx.tcx.hir().parent_iter(expr.hir_id);
let mut parents = cx.tcx.hir_parent_iter(expr.hir_id);
if let (_, Node::LetStmt(local)) = parents.next()?
&& let PatKind::Binding(BindingMode::MUT, iter_binding_id, _, None) = local.pat.kind
&& let (iter_stmt_id, Node::Stmt(_)) = parents.next()?
Expand Down Expand Up @@ -220,7 +220,7 @@ fn indirect_usage<'tcx>(
ControlFlow::Continue(Descend::from(path_to_binding.is_none()))
});

let mut parents = cx.tcx.hir().parent_iter(path_to_binding?.hir_id);
let mut parents = cx.tcx.hir_parent_iter(path_to_binding?.hir_id);
let iter_usage = parse_iter_usage(cx, ctxt, &mut parents)?;

let (parent_id, _) = parents.find(|(_, node)| {
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/methods/unnecessary_to_owned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ fn get_input_traits_and_projections<'tcx>(

#[expect(clippy::too_many_lines)]
fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty<'a>) -> bool {
for (_, node) in cx.tcx.hir().parent_iter(expr.hir_id) {
for (_, node) in cx.tcx.hir_parent_iter(expr.hir_id) {
match node {
Node::Stmt(_) => return true,
Node::Block(..) => {},
Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/min_ident_chars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ impl Visitor<'_> for IdentVisitor<'_, '_> {
// Check whether the node is part of a `use` statement. We don't want to emit a warning if the user
// has no control over the type.
let usenode = opt_as_use_node(node).or_else(|| {
cx.tcx
.hir()
.parent_iter(hir_id)
cx
.tcx
.hir_parent_iter(hir_id)
.find_map(|(_, node)| opt_as_use_node(node))
});

Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/missing_const_for_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForFn {

// Const fns are not allowed as methods in a trait.
{
let parent = cx.tcx.hir().get_parent_item(hir_id).def_id;
let parent = cx.tcx.hir_get_parent_item(hir_id).def_id;
if parent != CRATE_DEF_ID {
if let hir::Node::Item(item) = cx.tcx.hir_node_by_def_id(parent) {
if let hir::ItemKind::Trait(..) = &item.kind {
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/missing_const_for_thread_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fn is_unreachable(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
| sym::core_panic_2015_macro
| sym::std_panic_2015_macro
| sym::core_panic_2021_macro
) && !cx.tcx.hir().is_inside_const_context(expr.hir_id))
) && !cx.tcx.hir_is_inside_const_context(expr.hir_id))
|| matches!(
diag_name,
sym::unimplemented_macro | sym::todo_macro | sym::unreachable_macro | sym::unreachable_2015_macro
Expand Down
3 changes: 1 addition & 2 deletions clippy_lints/src/needless_borrowed_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrowedRef {
&& !ref_pat.span.from_expansion()
&& cx
.tcx
.hir()
.parent_iter(ref_pat.hir_id)
.hir_parent_iter(ref_pat.hir_id)
.map_while(|(_, parent)| if let Node::Pat(pat) = parent { Some(pat) } else { None })
// Do not lint patterns that are part of an OR `|` pattern, the binding mode must match in all arms
.all(|pat| !matches!(pat.kind, PatKind::Or(_)))
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/needless_late_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ fn check<'tcx>(

impl<'tcx> LateLintPass<'tcx> for NeedlessLateInit {
fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx LetStmt<'tcx>) {
let mut parents = cx.tcx.hir().parent_iter(local.hir_id);
let mut parents = cx.tcx.hir_parent_iter(local.hir_id);
if let LetStmt {
init: None,
pat:
Expand Down
3 changes: 1 addition & 2 deletions clippy_lints/src/needless_pass_by_ref_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,7 @@ impl MutablyUsedVariablesCtxt<'_> {
// The goal here is to find if the current scope is unsafe or not. It stops when it finds
// a function or an unsafe block.
fn is_in_unsafe_block(&self, item: HirId) -> bool {
let hir = self.tcx.hir();
for (parent, node) in hir.parent_iter(item) {
for (parent, node) in self.tcx.hir_parent_iter(item) {
if let Some(fn_sig) = self.tcx.hir_fn_sig_by_hir_id(parent) {
return fn_sig.header.is_unsafe();
} else if let Node::Block(block) = node {
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/new_without_default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault {
if sig.decl.inputs.is_empty()
&& name == sym::new
&& cx.effective_visibilities.is_reachable(impl_item.owner_id.def_id)
&& let self_def_id = cx.tcx.hir().get_parent_item(id.into())
&& let self_def_id = cx.tcx.hir_get_parent_item(id.into())
&& let self_ty = cx.tcx.type_of(self_def_id).instantiate_identity()
&& self_ty == return_ty(cx, id)
&& let Some(default_trait_id) = cx.tcx.get_diagnostic_item(sym::Default)
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/no_effect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl NoEffect {
stmt.span,
"statement with no effect",
|diag| {
for parent in cx.tcx.hir().parent_iter(stmt.hir_id) {
for parent in cx.tcx.hir_parent_iter(stmt.hir_id) {
if let Node::Item(item) = parent.1
&& let ItemKind::Fn { .. } = item.kind
&& let Node::Block(block) = cx.tcx.parent_hir_node(stmt.hir_id)
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/non_copy_const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst<'tcx> {

fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx ImplItem<'_>) {
if let ImplItemKind::Const(_, body_id) = &impl_item.kind {
let item_def_id = cx.tcx.hir().get_parent_item(impl_item.hir_id()).def_id;
let item_def_id = cx.tcx.hir_get_parent_item(impl_item.hir_id()).def_id;
let item = cx.tcx.hir().expect_item(item_def_id);

match &item.kind {
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/non_zero_suggestions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl<'tcx> LateLintPass<'tcx> for NonZeroSuggestions {
check_non_zero_conversion(cx, rhs, Applicability::MachineApplicable);
} else {
// Check if the parent expression is a binary operation
let parent_is_binary = cx.tcx.hir().parent_iter(expr.hir_id).any(|(_, node)| {
let parent_is_binary = cx.tcx.hir_parent_iter(expr.hir_id).any(|(_, node)| {
matches!(node, rustc_hir::Node::Expr(parent_expr) if matches!(parent_expr.kind, ExprKind::Binary(..)))
});

Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/operators/assign_op_pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub(super) fn check<'tcx>(
let rty = cx.typeck_results().expr_ty(rhs);
if let Some((_, lang_item)) = binop_traits(op.node)
&& let Some(trait_id) = cx.tcx.lang_items().get(lang_item)
&& let parent_fn = cx.tcx.hir().get_parent_item(e.hir_id).def_id
&& let parent_fn = cx.tcx.hir_get_parent_item(e.hir_id).def_id
&& trait_ref_of_method(cx, parent_fn).is_none_or(|t| t.path.res.def_id() != trait_id)
&& implements_trait(cx, ty, trait_id, &[rty.into()])
{
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/operators/identity_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ fn needs_parenthesis(cx: &LateContext<'_>, binary: &Expr<'_>, child: &Expr<'_>)
// the parent HIR node is an expression, or if the parent HIR node
// is a Block or Stmt, and the new left hand side would need
// parenthesis be treated as a statement rather than an expression.
if let Some((_, parent)) = cx.tcx.hir().parent_iter(binary.hir_id).next() {
if let Some((_, parent)) = cx.tcx.hir_parent_iter(binary.hir_id).next() {
match parent {
Node::Expr(_) => return Parens::Needed,
Node::Block(_) | Node::Stmt(_) => {
Expand All @@ -142,7 +142,7 @@ fn needs_parenthesis(cx: &LateContext<'_>, binary: &Expr<'_>, child: &Expr<'_>)
// This would mean that the rustfix suggestion will appear at the start of a line, which causes
// these expressions to be interpreted as statements if they do not have parenthesis.
let mut prev_id = binary.hir_id;
for (_, parent) in cx.tcx.hir().parent_iter(binary.hir_id) {
for (_, parent) in cx.tcx.hir_parent_iter(binary.hir_id) {
if let Node::Expr(expr) = parent
&& let ExprKind::Binary(_, lhs, _) | ExprKind::Cast(lhs, _) | ExprKind::Unary(_, lhs) = expr.kind
&& lhs.hir_id == prev_id
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/panic_unimplemented.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl<'tcx> LateLintPass<'tcx> for PanicUnimplemented {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
if let Some(macro_call) = root_macro_call_first_node(cx, expr) {
if is_panic(cx, macro_call.def_id) {
if cx.tcx.hir().is_inside_const_context(expr.hir_id)
if cx.tcx.hir_is_inside_const_context(expr.hir_id)
|| self.allow_panic_in_tests && is_in_test(cx.tcx, expr.hir_id)
{
return;
Expand Down Expand Up @@ -139,7 +139,7 @@ impl<'tcx> LateLintPass<'tcx> for PanicUnimplemented {
&& let Res::Def(DefKind::Fn, def_id) = expr_path.res
&& match_def_path(cx, def_id, &paths::PANIC_ANY)
{
if cx.tcx.hir().is_inside_const_context(expr.hir_id)
if cx.tcx.hir_is_inside_const_context(expr.hir_id)
|| self.allow_panic_in_tests && is_in_test(cx.tcx, expr.hir_id)
{
return;
Expand Down
3 changes: 1 addition & 2 deletions clippy_lints/src/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,7 @@ impl<'tcx> LateLintPass<'tcx> for Ptr {
}

fn check_body(&mut self, cx: &LateContext<'tcx>, body: &Body<'tcx>) {
let hir = cx.tcx.hir();
let mut parents = hir.parent_iter(body.value.hir_id);
let mut parents = cx.tcx.hir_parent_iter(body.value.hir_id);
let (item_id, sig, is_trait_item) = match parents.next() {
Some((_, Node::Item(i))) => {
if let ItemKind::Fn { sig, .. } = &i.kind {
Expand Down
Loading

0 comments on commit c2d75cf

Please sign in to comment.