Move methods from Map to TyCtxt, part 3.
Continuing the work from #137162. Every method gains a `hir_` prefix.
This commit is contained in:
parent
43c2b0086a
commit
806be25fc9
105 changed files with 243 additions and 273 deletions
|
|
@ -177,7 +177,7 @@ where
|
|||
// If the enclosing item has a span coming from a proc macro, then we also don't want to
|
||||
// include the example.
|
||||
let enclosing_item_span =
|
||||
tcx.hir().span_with_body(tcx.hir().get_parent_item(ex.hir_id).into());
|
||||
tcx.hir().span_with_body(tcx.hir_get_parent_item(ex.hir_id).into());
|
||||
if enclosing_item_span.from_expansion() {
|
||||
trace!("Rejecting expr ({call_span:?}) from macro item: {enclosing_item_span:?}");
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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| {
|
||||
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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)))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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 => {
|
||||
|
|
@ -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()?
|
||||
|
|
@ -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)| {
|
||||
|
|
|
|||
|
|
@ -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(..) => {},
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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(_)))
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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(..)))
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -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()])
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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(_) => {
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -122,8 +122,7 @@ fn find_binding(pat: &Pat<'_>, name: Ident) -> Option<BindingMode> {
|
|||
|
||||
/// Check if a rebinding of a local changes the effect of assignments to the binding.
|
||||
fn affects_assignments(cx: &LateContext<'_>, mutability: Mutability, bind: HirId, rebind: HirId) -> bool {
|
||||
let hir = cx.tcx.hir();
|
||||
|
||||
// the binding is mutable and the rebinding is in a different scope than the original binding
|
||||
mutability == Mutability::Mut && hir.get_enclosing_scope(bind) != hir.get_enclosing_scope(rebind)
|
||||
mutability == Mutability::Mut
|
||||
&& cx.tcx.hir_get_enclosing_scope(bind) != cx.tcx.hir_get_enclosing_scope(rebind)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -177,8 +177,7 @@ declare_lint_pass!(Return => [LET_AND_RETURN, NEEDLESS_RETURN, NEEDLESS_RETURN_W
|
|||
/// because of the never-ness of `return` expressions
|
||||
fn stmt_needs_never_type(cx: &LateContext<'_>, stmt_hir_id: HirId) -> bool {
|
||||
cx.tcx
|
||||
.hir()
|
||||
.parent_iter(stmt_hir_id)
|
||||
.hir_parent_iter(stmt_hir_id)
|
||||
.find_map(|(_, node)| if let Node::Expr(expr) = node { Some(expr) } else { None })
|
||||
.is_some_and(|e| {
|
||||
cx.typeck_results()
|
||||
|
|
@ -203,7 +202,7 @@ impl<'tcx> LateLintPass<'tcx> for Return {
|
|||
&& is_res_lang_ctor(cx, path_res(cx, maybe_constr), ResultErr)
|
||||
|
||||
// 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 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 ExprKind::Block(block, _) = block.kind
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ impl<'tcx> LateLintPass<'tcx> for SelfNamedConstructors {
|
|||
_ => return,
|
||||
}
|
||||
|
||||
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();
|
||||
let ret_ty = return_ty(cx, impl_item.owner_id);
|
||||
|
|
|
|||
|
|
@ -224,9 +224,9 @@ fn lint_shadow(cx: &LateContext<'_>, pat: &Pat<'_>, shadowed: HirId, span: Span)
|
|||
|
||||
/// Returns true if the expression is a simple transformation of a local binding such as `&x`
|
||||
fn is_self_shadow(cx: &LateContext<'_>, pat: &Pat<'_>, mut expr: &Expr<'_>, hir_id: HirId) -> bool {
|
||||
let hir = cx.tcx.hir();
|
||||
let is_direct_binding = hir
|
||||
.parent_iter(pat.hir_id)
|
||||
let is_direct_binding = cx
|
||||
.tcx
|
||||
.hir_parent_iter(pat.hir_id)
|
||||
.map_while(|(_id, node)| match node {
|
||||
Node::Pat(pat) => Some(pat),
|
||||
_ => None,
|
||||
|
|
@ -259,14 +259,14 @@ fn is_self_shadow(cx: &LateContext<'_>, pat: &Pat<'_>, mut expr: &Expr<'_>, hir_
|
|||
/// For closure arguments passed to a method call, returns the method call, and the `HirId` of the
|
||||
/// closure (which will later be skipped). This is for <https://github.com/rust-lang/rust-clippy/issues/10780>
|
||||
fn find_init<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option<(&'tcx Expr<'tcx>, Option<HirId>)> {
|
||||
for (hir_id, node) in cx.tcx.hir().parent_iter(hir_id) {
|
||||
for (hir_id, node) in cx.tcx.hir_parent_iter(hir_id) {
|
||||
let init = match node {
|
||||
Node::Arm(_) | Node::Pat(_) | Node::PatField(_) | Node::Param(_) => continue,
|
||||
Node::Expr(expr) => match expr.kind {
|
||||
ExprKind::Match(e, _, _) | ExprKind::Let(&LetExpr { init: e, .. }) => Some((e, None)),
|
||||
// If we're a closure argument, then a parent call is also an associated item.
|
||||
ExprKind::Closure(_) => {
|
||||
if let Some((_, node)) = cx.tcx.hir().parent_iter(hir_id).next() {
|
||||
if let Some((_, node)) = cx.tcx.hir_parent_iter(hir_id).next() {
|
||||
match node {
|
||||
Node::Expr(expr) => match expr.kind {
|
||||
ExprKind::MethodCall(_, _, _, _) | ExprKind::Call(_, _) => Some((expr, Some(hir_id))),
|
||||
|
|
|
|||
|
|
@ -232,8 +232,7 @@ impl<'ap, 'lc, 'others, 'stmt, 'tcx> StmtsChecker<'ap, 'lc, 'others, 'stmt, 'tcx
|
|||
let block_is_ancestor = self
|
||||
.cx
|
||||
.tcx
|
||||
.hir()
|
||||
.parent_iter(self.ap.curr_block_hir_id)
|
||||
.hir_parent_iter(self.ap.curr_block_hir_id)
|
||||
.any(|(id, _)| id == apa.first_block_hir_id);
|
||||
if last_stmt_is_not_dummy && last_stmt_is_not_curr && (block_equals_curr || block_is_ancestor) {
|
||||
apa.has_expensive_expr_after_last_attr = true;
|
||||
|
|
|
|||
|
|
@ -63,11 +63,11 @@ impl<'tcx> LateLintPass<'tcx> for SuspiciousImpl {
|
|||
|
||||
// Check for more than one binary operation in the implemented function
|
||||
// Linting when multiple operations are involved can result in false positives
|
||||
&& let parent_fn = cx.tcx.hir().get_parent_item(expr.hir_id).def_id
|
||||
&& 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 parent_fn = cx.tcx.hir().get_parent_item(expr.hir_id).def_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()
|
||||
&& ![binop_trait_id, op_assign_trait_id].contains(&trait_id)
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ use rustc_middle::ty::Ty;
|
|||
use super::EAGER_TRANSMUTE;
|
||||
|
||||
fn peel_parent_unsafe_blocks<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Option<&'tcx Expr<'tcx>> {
|
||||
for (_, parent) in cx.tcx.hir().parent_iter(expr.hir_id) {
|
||||
for (_, parent) in cx.tcx.hir_parent_iter(expr.hir_id) {
|
||||
match parent {
|
||||
Node::Block(_) => {},
|
||||
Node::Expr(e) if let ExprKind::Block(..) = e.kind => {},
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use rustc_middle::ty::Ty;
|
|||
use crate::transmute::MISSING_TRANSMUTE_ANNOTATIONS;
|
||||
|
||||
fn get_parent_local_binding_ty<'tcx>(cx: &LateContext<'tcx>, expr_hir_id: HirId) -> Option<LetStmt<'tcx>> {
|
||||
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)) = parent_iter.next() {
|
||||
match node {
|
||||
Node::LetStmt(local) => Some(*local),
|
||||
|
|
|
|||
|
|
@ -375,8 +375,7 @@ impl<'tcx> LateLintPass<'tcx> for Types {
|
|||
) {
|
||||
let is_in_trait_impl = if let hir::Node::Item(item) = cx.tcx.hir_node_by_def_id(
|
||||
cx.tcx
|
||||
.hir()
|
||||
.get_parent_item(cx.tcx.local_def_id_to_hir_id(def_id))
|
||||
.hir_get_parent_item(cx.tcx.local_def_id_to_hir_id(def_id))
|
||||
.def_id,
|
||||
) {
|
||||
matches!(item.kind, ItemKind::Impl(hir::Impl { of_trait: Some(_), .. }))
|
||||
|
|
@ -420,7 +419,7 @@ impl<'tcx> LateLintPass<'tcx> for Types {
|
|||
ImplItemKind::Const(ty, _) => {
|
||||
let is_in_trait_impl = if let hir::Node::Item(item) = cx
|
||||
.tcx
|
||||
.hir_node_by_def_id(cx.tcx.hir().get_parent_item(item.hir_id()).def_id)
|
||||
.hir_node_by_def_id(cx.tcx.hir_get_parent_item(item.hir_id()).def_id)
|
||||
{
|
||||
matches!(item.kind, ItemKind::Impl(hir::Impl { of_trait: Some(_), .. }))
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ fn get_impl_trait_def_id(cx: &LateContext<'_>, method_def_id: LocalDefId) -> Opt
|
|||
owner_id,
|
||||
..
|
||||
}),
|
||||
)) = cx.tcx.hir().parent_iter(hir_id).next()
|
||||
)) = cx.tcx.hir_parent_iter(hir_id).next()
|
||||
// We exclude `impl` blocks generated from rustc's proc macros.
|
||||
&& !cx.tcx.has_attr(*owner_id, sym::automatically_derived)
|
||||
// It is a implementation of a trait.
|
||||
|
|
@ -216,7 +216,7 @@ fn check_to_string(cx: &LateContext<'_>, method_span: Span, method_def_id: Local
|
|||
owner_id,
|
||||
..
|
||||
}),
|
||||
)) = cx.tcx.hir().parent_iter(hir_id).next()
|
||||
)) = cx.tcx.hir_parent_iter(hir_id).next()
|
||||
// We exclude `impl` blocks generated from rustc's proc macros.
|
||||
&& !cx.tcx.has_attr(*owner_id, sym::automatically_derived)
|
||||
// It is a implementation of a trait.
|
||||
|
|
@ -367,7 +367,7 @@ impl UnconditionalRecursion {
|
|||
kind: ItemKind::Impl(impl_),
|
||||
..
|
||||
}),
|
||||
)) = cx.tcx.hir().parent_iter(hir_id).next()
|
||||
)) = cx.tcx.hir_parent_iter(hir_id).next()
|
||||
&& let Some(implemented_ty_id) = get_hir_ty_def_id(cx.tcx, *impl_.self_ty)
|
||||
&& {
|
||||
self.init_default_impl_for_type_if_needed(cx);
|
||||
|
|
|
|||
|
|
@ -291,7 +291,7 @@ fn expr_has_unnecessary_safety_comment<'tcx>(
|
|||
expr: &'tcx hir::Expr<'tcx>,
|
||||
comment_pos: BytePos,
|
||||
) -> Option<Span> {
|
||||
if cx.tcx.hir().parent_iter(expr.hir_id).any(|(_, ref node)| {
|
||||
if cx.tcx.hir_parent_iter(expr.hir_id).any(|(_, ref node)| {
|
||||
matches!(
|
||||
node,
|
||||
Node::Block(Block {
|
||||
|
|
@ -604,10 +604,9 @@ 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 = cx.tcx.hir_body(body).value.span;
|
||||
let mut maybe_global_var = false;
|
||||
for (_, node) in map.parent_iter(body.hir_id) {
|
||||
for (_, node) in cx.tcx.hir_parent_iter(body.hir_id) {
|
||||
match node {
|
||||
Node::Expr(e) => span = e.span,
|
||||
Node::Block(_) | Node::Arm(_) | Node::Stmt(_) | Node::LetStmt(_) => (),
|
||||
|
|
|
|||
|
|
@ -224,7 +224,7 @@ fn is_unreachable_or_panic(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> bool {
|
|||
return false;
|
||||
};
|
||||
if is_panic(cx, macro_call.def_id) {
|
||||
return !cx.tcx.hir().is_inside_const_context(expr.hir_id);
|
||||
return !cx.tcx.hir_is_inside_const_context(expr.hir_id);
|
||||
}
|
||||
matches!(cx.tcx.item_name(macro_call.def_id).as_str(), "unreachable")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@ impl<'tcx> Visitor<'tcx> for PeekableVisitor<'_, 'tcx> {
|
|||
|
||||
fn visit_expr(&mut self, ex: &'tcx Expr<'tcx>) -> ControlFlow<()> {
|
||||
if path_to_local_id(ex, self.expected_hir_id) {
|
||||
for (_, node) in self.cx.tcx.hir().parent_iter(ex.hir_id) {
|
||||
for (_, node) in self.cx.tcx.hir_parent_iter(ex.hir_id) {
|
||||
match node {
|
||||
Node::Expr(expr) => {
|
||||
match expr.kind {
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedSelf {
|
|||
if impl_item.span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
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 parent_item = cx.tcx.hir().expect_item(parent);
|
||||
let assoc_item = cx.tcx.associated_item(impl_item.owner_id);
|
||||
let contains_todo = |cx, body: &'_ Body<'_>| -> bool {
|
||||
|
|
|
|||
|
|
@ -73,8 +73,8 @@ impl LateLintPass<'_> for ZeroSizedMapValues {
|
|||
}
|
||||
|
||||
fn in_trait_impl(cx: &LateContext<'_>, hir_id: HirId) -> bool {
|
||||
let parent_id = cx.tcx.hir().get_parent_item(hir_id);
|
||||
let second_parent_id = cx.tcx.hir().get_parent_item(parent_id.into()).def_id;
|
||||
let parent_id = cx.tcx.hir_get_parent_item(hir_id);
|
||||
let second_parent_id = cx.tcx.hir_get_parent_item(parent_id.into()).def_id;
|
||||
if let Node::Item(item) = cx.tcx.hir_node_by_def_id(second_parent_id) {
|
||||
if let ItemKind::Impl(hir::Impl { of_trait: Some(_), .. }) = item.kind {
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ impl<'hir> IfLet<'hir> {
|
|||
if_else,
|
||||
) = expr.kind
|
||||
{
|
||||
let mut iter = cx.tcx.hir().parent_iter(expr.hir_id);
|
||||
let mut iter = cx.tcx.hir_parent_iter(expr.hir_id);
|
||||
if let Some((_, Node::Block(Block { stmts: [], .. }))) = iter.next() {
|
||||
if let Some((
|
||||
_,
|
||||
|
|
|
|||
|
|
@ -212,7 +212,7 @@ pub fn find_binding_init<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option<
|
|||
///
|
||||
/// e.g. returns true for `x` in `fn f(x: usize) { .. }` and `let x = 1;` but false for `let x;`
|
||||
pub fn local_is_initialized(cx: &LateContext<'_>, local: HirId) -> bool {
|
||||
for (_, node) in cx.tcx.hir().parent_iter(local) {
|
||||
for (_, node) in cx.tcx.hir_parent_iter(local) {
|
||||
match node {
|
||||
Node::Pat(..) | Node::PatField(..) => {},
|
||||
Node::LetStmt(let_stmt) => return let_stmt.init.is_some(),
|
||||
|
|
@ -227,7 +227,7 @@ pub fn local_is_initialized(cx: &LateContext<'_>, local: HirId) -> bool {
|
|||
///
|
||||
/// The current context is determined based on the current body which is set before calling a lint's
|
||||
/// entry point (any function on `LateLintPass`). If you need to check in a different context use
|
||||
/// `tcx.hir().is_inside_const_context(_)`.
|
||||
/// `tcx.hir_is_inside_const_context(_)`.
|
||||
///
|
||||
/// Do not call this unless the `LateContext` has an enclosing body. For release build this case
|
||||
/// will safely return `false`, but debug builds will ICE. Note that `check_expr`, `check_block`,
|
||||
|
|
@ -806,7 +806,7 @@ pub fn get_trait_def_id(tcx: TyCtxt<'_>, path: &[&str]) -> Option<DefId> {
|
|||
pub fn trait_ref_of_method<'tcx>(cx: &LateContext<'tcx>, def_id: LocalDefId) -> Option<&'tcx TraitRef<'tcx>> {
|
||||
// Get the implemented trait for the current function
|
||||
let hir_id = cx.tcx.local_def_id_to_hir_id(def_id);
|
||||
let parent_impl = cx.tcx.hir().get_parent_item(hir_id);
|
||||
let parent_impl = cx.tcx.hir_get_parent_item(hir_id);
|
||||
if parent_impl != hir::CRATE_OWNER_ID
|
||||
&& let Node::Item(item) = cx.tcx.hir_node_by_def_id(parent_impl.def_id)
|
||||
&& let ItemKind::Impl(impl_) = &item.kind
|
||||
|
|
@ -1117,7 +1117,7 @@ pub fn capture_local_usage(cx: &LateContext<'_>, e: &Expr<'_>) -> CaptureKind {
|
|||
let mut capture = CaptureKind::Value;
|
||||
let mut capture_expr_ty = e;
|
||||
|
||||
for (parent_id, parent) in cx.tcx.hir().parent_iter(e.hir_id) {
|
||||
for (parent_id, parent) in cx.tcx.hir_parent_iter(e.hir_id) {
|
||||
if let [
|
||||
Adjustment {
|
||||
kind: Adjust::Deref(_) | Adjust::Borrow(AutoBorrow::Ref(..)),
|
||||
|
|
@ -1336,13 +1336,13 @@ pub fn is_entrypoint_fn(cx: &LateContext<'_>, def_id: DefId) -> bool {
|
|||
|
||||
/// Returns `true` if the expression is in the program's `#[panic_handler]`.
|
||||
pub fn is_in_panic_handler(cx: &LateContext<'_>, e: &Expr<'_>) -> bool {
|
||||
let parent = cx.tcx.hir().get_parent_item(e.hir_id);
|
||||
let parent = cx.tcx.hir_get_parent_item(e.hir_id);
|
||||
Some(parent.to_def_id()) == cx.tcx.lang_items().panic_impl()
|
||||
}
|
||||
|
||||
/// Gets the name of the item the expression is in, if available.
|
||||
pub fn get_item_name(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<Symbol> {
|
||||
let parent_id = cx.tcx.hir().get_parent_item(expr.hir_id).def_id;
|
||||
let parent_id = cx.tcx.hir_get_parent_item(expr.hir_id).def_id;
|
||||
match cx.tcx.hir_node_by_def_id(parent_id) {
|
||||
Node::Item(Item { ident, .. })
|
||||
| Node::TraitItem(TraitItem { ident, .. })
|
||||
|
|
@ -1407,9 +1407,9 @@ pub fn get_parent_expr_for_hir<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> O
|
|||
|
||||
/// Gets the enclosing block, if any.
|
||||
pub fn get_enclosing_block<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option<&'tcx Block<'tcx>> {
|
||||
let map = &cx.tcx.hir();
|
||||
let enclosing_node = map
|
||||
.get_enclosing_scope(hir_id)
|
||||
let enclosing_node = cx
|
||||
.tcx
|
||||
.hir_get_enclosing_scope(hir_id)
|
||||
.map(|enclosing_id| cx.tcx.hir_node(enclosing_id));
|
||||
enclosing_node.and_then(|node| match node {
|
||||
Node::Block(block) => Some(block),
|
||||
|
|
@ -1433,7 +1433,7 @@ pub fn get_enclosing_loop_or_multi_call_closure<'tcx>(
|
|||
cx: &LateContext<'tcx>,
|
||||
expr: &Expr<'_>,
|
||||
) -> Option<&'tcx Expr<'tcx>> {
|
||||
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::Expr(e) => match e.kind {
|
||||
ExprKind::Closure { .. }
|
||||
|
|
@ -1453,7 +1453,7 @@ pub fn get_enclosing_loop_or_multi_call_closure<'tcx>(
|
|||
|
||||
/// Gets the parent node if it's an impl block.
|
||||
pub fn get_parent_as_impl(tcx: TyCtxt<'_>, id: HirId) -> Option<&Impl<'_>> {
|
||||
match tcx.hir().parent_iter(id).next() {
|
||||
match tcx.hir_parent_iter(id).next() {
|
||||
Some((
|
||||
_,
|
||||
Node::Item(Item {
|
||||
|
|
@ -1531,7 +1531,7 @@ pub fn peel_blocks_with_stmt<'a>(mut expr: &'a Expr<'a>) -> &'a Expr<'a> {
|
|||
|
||||
/// Checks if the given expression is the else clause of either an `if` or `if let` expression.
|
||||
pub fn is_else_clause(tcx: TyCtxt<'_>, expr: &Expr<'_>) -> bool {
|
||||
let mut iter = tcx.hir().parent_iter(expr.hir_id);
|
||||
let mut iter = tcx.hir_parent_iter(expr.hir_id);
|
||||
match iter.next() {
|
||||
Some((
|
||||
_,
|
||||
|
|
@ -1548,7 +1548,7 @@ pub fn is_else_clause(tcx: TyCtxt<'_>, expr: &Expr<'_>) -> bool {
|
|||
/// returns `true` for both the `init` and the `else` part
|
||||
pub fn is_inside_let_else(tcx: TyCtxt<'_>, expr: &Expr<'_>) -> bool {
|
||||
let mut child_id = expr.hir_id;
|
||||
for (parent_id, node) in tcx.hir().parent_iter(child_id) {
|
||||
for (parent_id, node) in tcx.hir_parent_iter(child_id) {
|
||||
if let Node::LetStmt(LetStmt {
|
||||
init: Some(init),
|
||||
els: Some(els),
|
||||
|
|
@ -1568,7 +1568,7 @@ pub fn is_inside_let_else(tcx: TyCtxt<'_>, expr: &Expr<'_>) -> bool {
|
|||
/// Checks if the given expression is the else clause of a `let else` expression
|
||||
pub fn is_else_clause_in_let_else(tcx: TyCtxt<'_>, expr: &Expr<'_>) -> bool {
|
||||
let mut child_id = expr.hir_id;
|
||||
for (parent_id, node) in tcx.hir().parent_iter(child_id) {
|
||||
for (parent_id, node) in tcx.hir_parent_iter(child_id) {
|
||||
if let Node::LetStmt(LetStmt { els: Some(els), .. }) = node
|
||||
&& els.hir_id == child_id
|
||||
{
|
||||
|
|
@ -1961,7 +1961,7 @@ pub fn any_parent_has_attr(tcx: TyCtxt<'_>, node: HirId, symbol: Symbol) -> bool
|
|||
return true;
|
||||
}
|
||||
prev_enclosing_node = Some(enclosing_node);
|
||||
enclosing_node = map.get_parent_item(enclosing_node).into();
|
||||
enclosing_node = tcx.hir_get_parent_item(enclosing_node).into();
|
||||
}
|
||||
|
||||
false
|
||||
|
|
@ -1970,8 +1970,8 @@ pub fn any_parent_has_attr(tcx: TyCtxt<'_>, node: HirId, symbol: Symbol) -> bool
|
|||
/// Checks if the given HIR node is inside an `impl` block with the `automatically_derived`
|
||||
/// attribute.
|
||||
pub fn in_automatically_derived(tcx: TyCtxt<'_>, id: HirId) -> bool {
|
||||
tcx.hir()
|
||||
.parent_owner_iter(id)
|
||||
tcx
|
||||
.hir_parent_owner_iter(id)
|
||||
.filter(|(_, node)| matches!(node, OwnerNode::Item(item) if matches!(item.kind, ItemKind::Impl(_))))
|
||||
.any(|(id, _)| {
|
||||
has_attr(
|
||||
|
|
@ -2202,7 +2202,7 @@ pub fn is_expr_identity_function(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool
|
|||
/// Returns both the node and the `HirId` of the closest child node.
|
||||
pub fn get_expr_use_or_unification_node<'tcx>(tcx: TyCtxt<'tcx>, expr: &Expr<'_>) -> Option<(Node<'tcx>, HirId)> {
|
||||
let mut child_id = expr.hir_id;
|
||||
let mut iter = tcx.hir().parent_iter(child_id);
|
||||
let mut iter = tcx.hir_parent_iter(child_id);
|
||||
loop {
|
||||
match iter.next() {
|
||||
None => break None,
|
||||
|
|
@ -2581,7 +2581,7 @@ pub fn is_in_test_function(tcx: TyCtxt<'_>, id: HirId) -> bool {
|
|||
with_test_item_names(tcx, tcx.parent_module(id), |names| {
|
||||
let node = tcx.hir_node(id);
|
||||
once((id, node))
|
||||
.chain(tcx.hir().parent_iter(id))
|
||||
.chain(tcx.hir_parent_iter(id))
|
||||
// Since you can nest functions we need to collect all until we leave
|
||||
// function scope
|
||||
.any(|(_id, node)| {
|
||||
|
|
@ -2617,8 +2617,8 @@ pub fn is_cfg_test(tcx: TyCtxt<'_>, id: HirId) -> bool {
|
|||
|
||||
/// Checks if any parent node of `HirId` has `#[cfg(test)]` attribute applied
|
||||
pub fn is_in_cfg_test(tcx: TyCtxt<'_>, id: HirId) -> bool {
|
||||
tcx.hir()
|
||||
.parent_id_iter(id)
|
||||
tcx
|
||||
.hir_parent_id_iter(id)
|
||||
.any(|parent_id| is_cfg_test(tcx, parent_id))
|
||||
}
|
||||
|
||||
|
|
@ -2632,8 +2632,8 @@ pub fn inherits_cfg(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
|
|||
let hir = tcx.hir();
|
||||
|
||||
tcx.has_attr(def_id, sym::cfg)
|
||||
|| hir
|
||||
.parent_iter(tcx.local_def_id_to_hir_id(def_id))
|
||||
|| tcx
|
||||
.hir_parent_iter(tcx.local_def_id_to_hir_id(def_id))
|
||||
.flat_map(|(parent_id, _)| hir.attrs(parent_id))
|
||||
.any(|attr| attr.has_name(sym::cfg))
|
||||
}
|
||||
|
|
@ -2653,8 +2653,7 @@ pub fn walk_to_expr_usage<'tcx, T>(
|
|||
e: &Expr<'tcx>,
|
||||
mut f: impl FnMut(HirId, Node<'tcx>, HirId) -> ControlFlow<T>,
|
||||
) -> Option<ControlFlow<T, (Node<'tcx>, HirId)>> {
|
||||
let map = cx.tcx.hir();
|
||||
let mut iter = map.parent_iter(e.hir_id);
|
||||
let mut iter = cx.tcx.hir_parent_iter(e.hir_id);
|
||||
let mut child_id = e.hir_id;
|
||||
|
||||
while let Some((parent_id, parent)) = iter.next() {
|
||||
|
|
@ -2677,7 +2676,7 @@ pub fn walk_to_expr_usage<'tcx, T>(
|
|||
ExprKind::If(child, ..) | ExprKind::Match(child, ..) if child.hir_id != child_id => child_id = parent_id,
|
||||
ExprKind::Break(Destination { target_id: Ok(id), .. }, _) => {
|
||||
child_id = id;
|
||||
iter = map.parent_iter(id);
|
||||
iter = cx.tcx.hir_parent_iter(id);
|
||||
},
|
||||
ExprKind::Block(..) | ExprKind::DropTemps(_) => child_id = parent_id,
|
||||
_ => return Some(ControlFlow::Continue((parent, child_id))),
|
||||
|
|
|
|||
|
|
@ -178,7 +178,7 @@ pub fn first_node_in_macro(cx: &LateContext<'_>, node: &impl HirNode) -> Option<
|
|||
// get the parent node, possibly skipping over a statement
|
||||
// if the parent is not found, it is sensible to return `Some(root)`
|
||||
let hir = cx.tcx.hir();
|
||||
let mut parent_iter = hir.parent_iter(node.hir_id());
|
||||
let mut parent_iter = cx.tcx.hir_parent_iter(node.hir_id());
|
||||
let (parent_id, _) = match parent_iter.next() {
|
||||
None => return Some(ExpnId::root()),
|
||||
Some((_, Node::Stmt(_))) => match parent_iter.next() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue