about summary refs log tree commit diff
path: root/clippy_utils/src
diff options
context:
space:
mode:
authorJason Newcomb <jsnewcomb@pm.me>2022-05-26 13:57:05 -0400
committerJason Newcomb <jsnewcomb@pm.me>2022-05-26 14:43:33 -0400
commit7975d41a915b7e2c0b5ce2e2ca47ab31b96d978a (patch)
tree5fec793147b96430b7ff541cce724fb8c563534d /clippy_utils/src
parent91644d1f1d1a8029830d7c17595ec8c32b8ccde6 (diff)
downloadrust-7975d41a915b7e2c0b5ce2e2ca47ab31b96d978a.tar.gz
rust-7975d41a915b7e2c0b5ce2e2ca47ab31b96d978a.zip
Rework `branches_sharing_code`
Diffstat (limited to 'clippy_utils/src')
-rw-r--r--clippy_utils/src/hir_utils.rs14
-rw-r--r--clippy_utils/src/lib.rs4
2 files changed, 16 insertions, 2 deletions
diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs
index c440793b90e..16c5c728dba 100644
--- a/clippy_utils/src/hir_utils.rs
+++ b/clippy_utils/src/hir_utils.rs
@@ -91,7 +91,7 @@ pub struct HirEqInterExpr<'a, 'b, 'tcx> {
     // When binding are declared, the binding ID in the left expression is mapped to the one on the
     // right. For example, when comparing `{ let x = 1; x + 2 }` and `{ let y = 1; y + 2 }`,
     // these blocks are considered equal since `x` is mapped to `y`.
-    locals: HirIdMap<HirId>,
+    pub locals: HirIdMap<HirId>,
 }
 
 impl HirEqInterExpr<'_, '_, '_> {
@@ -998,3 +998,15 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
         }
     }
 }
+
+pub fn hash_stmt(cx: &LateContext<'_>, s: &Stmt<'_>) -> u64 {
+    let mut h = SpanlessHash::new(cx);
+    h.hash_stmt(s);
+    h.finish()
+}
+
+pub fn hash_expr(cx: &LateContext<'_>, e: &Expr<'_>) -> u64 {
+    let mut h = SpanlessHash::new(cx);
+    h.hash_expr(e);
+    h.finish()
+}
diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs
index adb37cc9d75..bcaa9571a05 100644
--- a/clippy_utils/src/lib.rs
+++ b/clippy_utils/src/lib.rs
@@ -58,7 +58,9 @@ pub mod usage;
 pub mod visitors;
 
 pub use self::attrs::*;
-pub use self::hir_utils::{both, count_eq, eq_expr_value, over, SpanlessEq, SpanlessHash};
+pub use self::hir_utils::{
+    both, count_eq, eq_expr_value, hash_expr, hash_stmt, over, HirEqInterExpr, SpanlessEq, SpanlessHash,
+};
 
 use std::collections::hash_map::Entry;
 use std::hash::BuildHasherDefault;