about summary refs log tree commit diff
path: root/clippy_utils/src
diff options
context:
space:
mode:
authorxFrednet <xFrednet@gmail.com>2021-02-20 13:50:09 +0100
committerxFrednet <xFrednet@gmail.com>2021-05-05 18:35:33 +0200
commitee8a99a1140880e10677fa0b03167cd364fece3f (patch)
tree3ad62201e77316e719ced5086d158ec080b7d868 /clippy_utils/src
parenta39912cfbbd682270b5f3d534bc69eedfaa73a7b (diff)
downloadrust-ee8a99a1140880e10677fa0b03167cd364fece3f.tar.gz
rust-ee8a99a1140880e10677fa0b03167cd364fece3f.zip
Metadata collection: Collecting Applicability assign values
Diffstat (limited to 'clippy_utils/src')
-rw-r--r--clippy_utils/src/lib.rs8
1 files changed, 7 insertions, 1 deletions
diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs
index 94eade0c932..d4bc42657f4 100644
--- a/clippy_utils/src/lib.rs
+++ b/clippy_utils/src/lib.rs
@@ -821,7 +821,13 @@ pub fn get_parent_node(tcx: TyCtxt<'_>, id: HirId) -> Option<Node<'_>> {
 
 /// Gets the parent expression, if any –- this is useful to constrain a lint.
 pub fn get_parent_expr<'tcx>(cx: &LateContext<'tcx>, e: &Expr<'_>) -> Option<&'tcx Expr<'tcx>> {
-    match get_parent_node(cx.tcx, e.hir_id) {
+    get_parent_expr_for_hir(cx, e.hir_id)
+}
+
+/// This retrieves the parent for the given `HirId` if it's an expression. This is useful for
+/// constraint lints
+pub fn get_parent_expr_for_hir<'tcx>(cx: &LateContext<'tcx>, hir_id: hir::HirId) -> Option<&'tcx Expr<'tcx>> {
+    match get_parent_node(cx.tcx, hir_id) {
         Some(Node::Expr(parent)) => Some(parent),
         _ => None,
     }