get_parent_node_by_hir_id -> get_parent_node
This commit is contained in:
parent
f0edfab44c
commit
c47a7e4ef2
12 changed files with 17 additions and 17 deletions
|
@ -115,7 +115,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
|
||||||
let map = &self.cx.tcx.hir();
|
let map = &self.cx.tcx.hir();
|
||||||
if map.is_argument(map.hir_to_node_id(consume_pat.hir_id)) {
|
if map.is_argument(map.hir_to_node_id(consume_pat.hir_id)) {
|
||||||
// Skip closure arguments
|
// Skip closure arguments
|
||||||
if let Some(Node::Expr(..)) = map.find_by_hir_id(map.get_parent_node_by_hir_id(consume_pat.hir_id)) {
|
if let Some(Node::Expr(..)) = map.find_by_hir_id(map.get_parent_node(consume_pat.hir_id)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if is_non_trait_box(cmt.ty) && !self.is_large_box(cmt.ty) {
|
if is_non_trait_box(cmt.ty) && !self.is_large_box(cmt.ty) {
|
||||||
|
@ -124,7 +124,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if let Categorization::Rvalue(..) = cmt.cat {
|
if let Categorization::Rvalue(..) = cmt.cat {
|
||||||
if let Some(Node::Stmt(st)) = map.find_by_hir_id(map.get_parent_node_by_hir_id(cmt.hir_id)) {
|
if let Some(Node::Stmt(st)) = map.find_by_hir_id(map.get_parent_node(cmt.hir_id)) {
|
||||||
if let StmtKind::Local(ref loc) = st.node {
|
if let StmtKind::Local(ref loc) = st.node {
|
||||||
if let Some(ref ex) = loc.init {
|
if let Some(ref ex) = loc.init {
|
||||||
if let ExprKind::Box(..) = ex.node {
|
if let ExprKind::Box(..) = ex.node {
|
||||||
|
|
|
@ -176,7 +176,7 @@ fn check_for_unsequenced_reads(vis: &mut ReadVisitor<'_, '_>) {
|
||||||
let map = &vis.cx.tcx.hir();
|
let map = &vis.cx.tcx.hir();
|
||||||
let mut cur_id = vis.write_expr.hir_id;
|
let mut cur_id = vis.write_expr.hir_id;
|
||||||
loop {
|
loop {
|
||||||
let parent_id = map.get_parent_node_by_hir_id(cur_id);
|
let parent_id = map.get_parent_node(cur_id);
|
||||||
if parent_id == cur_id {
|
if parent_id == cur_id {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,7 +110,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Functions {
|
||||||
let is_impl = if let Some(hir::Node::Item(item)) = cx
|
let is_impl = if let Some(hir::Node::Item(item)) = cx
|
||||||
.tcx
|
.tcx
|
||||||
.hir()
|
.hir()
|
||||||
.find_by_hir_id(cx.tcx.hir().get_parent_node_by_hir_id(hir_id))
|
.find_by_hir_id(cx.tcx.hir().get_parent_node(hir_id))
|
||||||
{
|
{
|
||||||
matches!(item.node, hir::ItemKind::Impl(_, _, _, _, Some(_), _, _))
|
matches!(item.node, hir::ItemKind::Impl(_, _, _, _, Some(_), _, _))
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -2218,7 +2218,7 @@ fn is_conditional(expr: &Expr) -> bool {
|
||||||
fn is_nested(cx: &LateContext<'_, '_>, match_expr: &Expr, iter_expr: &Expr) -> bool {
|
fn is_nested(cx: &LateContext<'_, '_>, match_expr: &Expr, iter_expr: &Expr) -> bool {
|
||||||
if_chain! {
|
if_chain! {
|
||||||
if let Some(loop_block) = get_enclosing_block(cx, match_expr.hir_id);
|
if let Some(loop_block) = get_enclosing_block(cx, match_expr.hir_id);
|
||||||
let parent_node = cx.tcx.hir().get_parent_node_by_hir_id(loop_block.hir_id);
|
let parent_node = cx.tcx.hir().get_parent_node(loop_block.hir_id);
|
||||||
if let Some(Node::Expr(loop_expr)) = cx.tcx.hir().find_by_hir_id(parent_node);
|
if let Some(Node::Expr(loop_expr)) = cx.tcx.hir().find_by_hir_id(parent_node);
|
||||||
then {
|
then {
|
||||||
return is_loop_nested(cx, loop_expr, iter_expr)
|
return is_loop_nested(cx, loop_expr, iter_expr)
|
||||||
|
@ -2235,7 +2235,7 @@ fn is_loop_nested(cx: &LateContext<'_, '_>, loop_expr: &Expr, iter_expr: &Expr)
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
loop {
|
loop {
|
||||||
let parent = cx.tcx.hir().get_parent_node_by_hir_id(id);
|
let parent = cx.tcx.hir().get_parent_node(id);
|
||||||
if parent == id {
|
if parent == id {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1423,7 +1423,7 @@ fn lint_clone_on_copy(cx: &LateContext<'_, '_>, expr: &hir::Expr, arg: &hir::Exp
|
||||||
if cx.tables.expr_ty(arg) == ty {
|
if cx.tables.expr_ty(arg) == ty {
|
||||||
snip = Some(("try removing the `clone` call", format!("{}", snippet)));
|
snip = Some(("try removing the `clone` call", format!("{}", snippet)));
|
||||||
} else {
|
} else {
|
||||||
let parent = cx.tcx.hir().get_parent_node_by_hir_id(expr.hir_id);
|
let parent = cx.tcx.hir().get_parent_node(expr.hir_id);
|
||||||
match cx.tcx.hir().get(parent) {
|
match cx.tcx.hir().get(parent) {
|
||||||
hir::Node::Expr(parent) => match parent.node {
|
hir::Node::Expr(parent) => match parent.node {
|
||||||
// &*x is a nop, &x.clone() is not
|
// &*x is a nop, &x.clone() is not
|
||||||
|
|
|
@ -115,7 +115,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBool {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parent_node_is_if_expr<'a, 'b>(expr: &Expr, cx: &LateContext<'a, 'b>) -> bool {
|
fn parent_node_is_if_expr<'a, 'b>(expr: &Expr, cx: &LateContext<'a, 'b>) -> bool {
|
||||||
let parent_id = cx.tcx.hir().get_parent_node_by_hir_id(expr.hir_id);
|
let parent_id = cx.tcx.hir().get_parent_node(expr.hir_id);
|
||||||
let parent_node = cx.tcx.hir().get(parent_id);
|
let parent_node = cx.tcx.hir().get(parent_id);
|
||||||
|
|
||||||
if let rustc::hir::Node::Expr(e) = parent_node {
|
if let rustc::hir::Node::Expr(e) = parent_node {
|
||||||
|
|
|
@ -91,7 +91,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
|
||||||
if let Some(Node::Item(item)) = cx
|
if let Some(Node::Item(item)) = cx
|
||||||
.tcx
|
.tcx
|
||||||
.hir()
|
.hir()
|
||||||
.find_by_hir_id(cx.tcx.hir().get_parent_node_by_hir_id(hir_id))
|
.find_by_hir_id(cx.tcx.hir().get_parent_node(hir_id))
|
||||||
{
|
{
|
||||||
if matches!(item.node, ItemKind::Impl(_, _, _, _, Some(_), _, _) |
|
if matches!(item.node, ItemKind::Impl(_, _, _, _, Some(_), _, _) |
|
||||||
ItemKind::Trait(..))
|
ItemKind::Trait(..))
|
||||||
|
@ -357,7 +357,7 @@ impl<'a, 'tcx> MovedVariablesCtxt<'a, 'tcx> {
|
||||||
if let mc::Categorization::Local(vid) = cmt.cat {
|
if let mc::Categorization::Local(vid) = cmt.cat {
|
||||||
let mut id = matched_pat.hir_id;
|
let mut id = matched_pat.hir_id;
|
||||||
loop {
|
loop {
|
||||||
let parent = self.cx.tcx.hir().get_parent_node_by_hir_id(id);
|
let parent = self.cx.tcx.hir().get_parent_node(id);
|
||||||
if id == parent {
|
if id == parent {
|
||||||
// no parent
|
// no parent
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -169,7 +169,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonCopyConst {
|
||||||
|
|
||||||
fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, impl_item: &'tcx ImplItem) {
|
fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, impl_item: &'tcx ImplItem) {
|
||||||
if let ImplItemKind::Const(hir_ty, ..) = &impl_item.node {
|
if let ImplItemKind::Const(hir_ty, ..) = &impl_item.node {
|
||||||
let item_hir_id = cx.tcx.hir().get_parent_node_by_hir_id(impl_item.hir_id);
|
let item_hir_id = cx.tcx.hir().get_parent_node(impl_item.hir_id);
|
||||||
let item = cx.tcx.hir().expect_item(item_hir_id);
|
let item = cx.tcx.hir().expect_item(item_hir_id);
|
||||||
// Ensure the impl is an inherent impl.
|
// Ensure the impl is an inherent impl.
|
||||||
if let ItemKind::Impl(_, _, _, _, None, _, _) = item.node {
|
if let ItemKind::Impl(_, _, _, _, None, _, _) = item.node {
|
||||||
|
@ -204,7 +204,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonCopyConst {
|
||||||
let mut dereferenced_expr = expr;
|
let mut dereferenced_expr = expr;
|
||||||
let mut needs_check_adjustment = true;
|
let mut needs_check_adjustment = true;
|
||||||
loop {
|
loop {
|
||||||
let parent_id = cx.tcx.hir().get_parent_node_by_hir_id(cur_expr.hir_id);
|
let parent_id = cx.tcx.hir().get_parent_node(cur_expr.hir_id);
|
||||||
if parent_id == cur_expr.hir_id {
|
if parent_id == cur_expr.hir_id {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for SuspiciousImpl {
|
||||||
}
|
}
|
||||||
// Check if the binary expression is part of another bi/unary expression
|
// Check if the binary expression is part of another bi/unary expression
|
||||||
// as a child node
|
// as a child node
|
||||||
let mut parent_expr = cx.tcx.hir().get_parent_node_by_hir_id(expr.hir_id);
|
let mut parent_expr = cx.tcx.hir().get_parent_node(expr.hir_id);
|
||||||
while parent_expr != hir::CRATE_HIR_ID {
|
while parent_expr != hir::CRATE_HIR_ID {
|
||||||
if let hir::Node::Expr(e) = cx.tcx.hir().get(parent_expr) {
|
if let hir::Node::Expr(e) = cx.tcx.hir().get(parent_expr) {
|
||||||
match e.node {
|
match e.node {
|
||||||
|
@ -75,7 +75,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for SuspiciousImpl {
|
||||||
_ => {},
|
_ => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
parent_expr = cx.tcx.hir().get_parent_node_by_hir_id(parent_expr);
|
parent_expr = cx.tcx.hir().get_parent_node(parent_expr);
|
||||||
}
|
}
|
||||||
// as a parent node
|
// as a parent node
|
||||||
let mut visitor = BinaryExprVisitor { in_binary_expr: false };
|
let mut visitor = BinaryExprVisitor { in_binary_expr: false };
|
||||||
|
|
|
@ -182,7 +182,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TriviallyCopyPassByRef {
|
||||||
if let Some(Node::Item(item)) = cx
|
if let Some(Node::Item(item)) = cx
|
||||||
.tcx
|
.tcx
|
||||||
.hir()
|
.hir()
|
||||||
.find_by_hir_id(cx.tcx.hir().get_parent_node_by_hir_id(hir_id))
|
.find_by_hir_id(cx.tcx.hir().get_parent_node(hir_id))
|
||||||
{
|
{
|
||||||
if matches!(item.node, ItemKind::Impl(_, _, _, _, Some(_), _, _) |
|
if matches!(item.node, ItemKind::Impl(_, _, _, _, Some(_), _, _) |
|
||||||
ItemKind::Trait(..))
|
ItemKind::Trait(..))
|
||||||
|
|
|
@ -585,7 +585,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnitArg {
|
||||||
}
|
}
|
||||||
if_chain! {
|
if_chain! {
|
||||||
let map = &cx.tcx.hir();
|
let map = &cx.tcx.hir();
|
||||||
let opt_parent_node = map.find_by_hir_id(map.get_parent_node_by_hir_id(expr.hir_id));
|
let opt_parent_node = map.find_by_hir_id(map.get_parent_node(expr.hir_id));
|
||||||
if let Some(hir::Node::Expr(parent_expr)) = opt_parent_node;
|
if let Some(hir::Node::Expr(parent_expr)) = opt_parent_node;
|
||||||
if is_questionmark_desugar_marked_call(parent_expr);
|
if is_questionmark_desugar_marked_call(parent_expr);
|
||||||
then {
|
then {
|
||||||
|
|
|
@ -592,7 +592,7 @@ fn trim_multiline_inner(s: Cow<'_, str>, ignore_first: bool, ch: char) -> Cow<'_
|
||||||
pub fn get_parent_expr<'c>(cx: &'c LateContext<'_, '_>, e: &Expr) -> Option<&'c Expr> {
|
pub fn get_parent_expr<'c>(cx: &'c LateContext<'_, '_>, e: &Expr) -> Option<&'c Expr> {
|
||||||
let map = &cx.tcx.hir();
|
let map = &cx.tcx.hir();
|
||||||
let hir_id = e.hir_id;
|
let hir_id = e.hir_id;
|
||||||
let parent_id = map.get_parent_node_by_hir_id(hir_id);
|
let parent_id = map.get_parent_node(hir_id);
|
||||||
if hir_id == parent_id {
|
if hir_id == parent_id {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue