diff options
| author | bors <bors@rust-lang.org> | 2022-04-08 00:37:56 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-04-08 00:37:56 +0000 |
| commit | a63308be0a66fe34aa1ccefef76fa6a0bc50d2a3 (patch) | |
| tree | 66359167138505b8217830b22ffb05bfef103f11 /clippy_lints | |
| parent | 984330a6ee3c4d15626685d6dc8b7b759ff630bd (diff) | |
| parent | c70f1e0f8f3419f67dc31b5bbbc47db1e829128c (diff) | |
| download | rust-a63308be0a66fe34aa1ccefef76fa6a0bc50d2a3.tar.gz rust-a63308be0a66fe34aa1ccefef76fa6a0bc50d2a3.zip | |
Auto merge of #8619 - pitaj:fix-6973, r=giraffate
ignore `&x | &y` in unnested_or_patterns replacing it with `&(x | y)` is actually more characters Fixes #6973 changelog: [`unnested_or_patterns`] ignore `&x | &y`, nesting would result in more characters
Diffstat (limited to 'clippy_lints')
| -rw-r--r-- | clippy_lints/src/unnested_or_patterns.rs | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/clippy_lints/src/unnested_or_patterns.rs b/clippy_lints/src/unnested_or_patterns.rs index 1d4fe9cfd3c..790ffe618d7 100644 --- a/clippy_lints/src/unnested_or_patterns.rs +++ b/clippy_lints/src/unnested_or_patterns.rs @@ -5,7 +5,7 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::{meets_msrv, msrvs, over}; use rustc_ast::mut_visit::*; use rustc_ast::ptr::P; -use rustc_ast::{self as ast, Pat, PatKind, PatKind::*, DUMMY_NODE_ID}; +use rustc_ast::{self as ast, Mutability, Pat, PatKind, PatKind::*, DUMMY_NODE_ID}; use rustc_ast_pretty::pprust; use rustc_errors::Applicability; use rustc_lint::{EarlyContext, EarlyLintPass}; @@ -230,6 +230,10 @@ fn transform_with_focus_on_idx(alternatives: &mut Vec<P<Pat>>, focus_idx: usize) // with which a pattern `C(p_0)` may be formed, // which we would want to join with other `C(p_j)`s. Ident(.., None) | Lit(_) | Wild | Path(..) | Range(..) | Rest | MacCall(_) + // Skip immutable refs, as grouping them saves few characters, + // and almost always requires adding parens (increasing noisiness). + // In the case of only two patterns, replacement adds net characters. + | Ref(_, Mutability::Not) // Dealt with elsewhere. | Or(_) | Paren(_) => false, // Transform `box x | ... | box y` into `box (x | y)`. @@ -241,10 +245,10 @@ fn transform_with_focus_on_idx(alternatives: &mut Vec<P<Pat>>, focus_idx: usize) |k| matches!(k, Box(_)), |k| always_pat!(k, Box(p) => p), ), - // Transform `&m x | ... | &m y` into `&m (x | y)`. - Ref(target, m1) => extend_with_matching( + // Transform `&mut x | ... | &mut y` into `&mut (x | y)`. + Ref(target, Mutability::Mut) => extend_with_matching( target, start, alternatives, - |k| matches!(k, Ref(_, m2) if m1 == m2), // Mutabilities must match. + |k| matches!(k, Ref(_, Mutability::Mut)), |k| always_pat!(k, Ref(p, _) => p), ), // Transform `b @ p0 | ... b @ p1` into `b @ (p0 | p1)`. |
