diff options
| author | bors <bors@rust-lang.org> | 2022-06-14 08:59:40 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-06-14 08:59:40 +0000 |
| commit | c07cbb9ea65bb4ed4c78fa4b664474ea234bbc46 (patch) | |
| tree | 7c8f2f3206d3f48b446daea2b5c46e45d7caa6c6 /clippy_utils | |
| parent | c80ca2c1d6c798334807b610a58d0dbfd95c6a75 (diff) | |
| parent | 7975d41a915b7e2c0b5ce2e2ca47ab31b96d978a (diff) | |
| download | rust-c07cbb9ea65bb4ed4c78fa4b664474ea234bbc46.tar.gz rust-c07cbb9ea65bb4ed4c78fa4b664474ea234bbc46.zip | |
Auto merge of #8901 - Jarcho:sharing_code, r=dswij
Rework `branches_sharing_code` fixes #7378 This changes the lint from checking pairs of blocks, to checking all the blocks at the same time. As such there's almost none of the original code left. changelog: Don't lint `branches_sharing_code` when using different binding names
Diffstat (limited to 'clippy_utils')
| -rw-r--r-- | clippy_utils/src/hir_utils.rs | 14 | ||||
| -rw-r--r-- | clippy_utils/src/lib.rs | 4 |
2 files changed, 16 insertions, 2 deletions
diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index 0603471c343..39f970dc420 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<'_, '_, '_> { @@ -996,3 +996,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 5f051e3f444..0a95809381b 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; |
