Skip to content

Commit 5bedfdc

Browse files
committed
Remove now-obsolete visit_pattern_type_pattern
1 parent 7d5c407 commit 5bedfdc

File tree

8 files changed

+12
-142
lines changed

8 files changed

+12
-142
lines changed

compiler/rustc_ast_lowering/src/index.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -393,10 +393,6 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
393393
});
394394
}
395395

396-
fn visit_pattern_type_pattern(&mut self, p: &'hir hir::Pat<'hir>) {
397-
self.visit_pat(p)
398-
}
399-
400396
fn visit_precise_capturing_arg(
401397
&mut self,
402398
arg: &'hir PreciseCapturingArg<'hir>,

compiler/rustc_hir/src/intravisit.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -363,11 +363,6 @@ pub trait Visitor<'v>: Sized {
363363
fn visit_ty(&mut self, t: &'v Ty<'v>) -> Self::Result {
364364
walk_ty(self, t)
365365
}
366-
fn visit_pattern_type_pattern(&mut self, _p: &'v Pat<'v>) {
367-
// Do nothing. Only a few visitors need to know the details of the pattern type,
368-
// and they opt into it. All other visitors will just choke on our fake patterns
369-
// because they aren't in a body.
370-
}
371366
fn visit_generic_param(&mut self, p: &'v GenericParam<'v>) -> Self::Result {
372367
walk_generic_param(self, p)
373368
}
@@ -929,7 +924,7 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty<'v>) -> V::Resul
929924
TyKind::Infer | TyKind::InferDelegation(..) | TyKind::Err(_) => {}
930925
TyKind::Pat(ty, pat) => {
931926
try_visit!(visitor.visit_ty(ty));
932-
try_visit!(visitor.visit_pattern_type_pattern(pat));
927+
try_visit!(visitor.visit_pat(pat));
933928
}
934929
}
935930
V::Result::output()

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -870,11 +870,6 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
870870
}
871871
}
872872

873-
#[instrument(level = "debug", skip(self))]
874-
fn visit_pattern_type_pattern(&mut self, p: &'tcx hir::Pat<'tcx>) {
875-
intravisit::walk_pat(self, p)
876-
}
877-
878873
#[instrument(level = "debug", skip(self))]
879874
fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) {
880875
use self::hir::TraitItemKind::*;

compiler/rustc_lint/src/internal.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use rustc_ast as ast;
55
use rustc_hir::def::Res;
66
use rustc_hir::def_id::DefId;
77
use rustc_hir::{
8-
BinOp, BinOpKind, Expr, ExprKind, GenericArg, HirId, Impl, Item, ItemKind, Node, Pat, PatKind,
9-
PatExpr, PatExprKind, Path, PathSegment, QPath, Ty, TyKind,
8+
BinOp, BinOpKind, Expr, ExprKind, GenericArg, HirId, Impl, Item, ItemKind, Node, Pat, PatExpr,
9+
PatExprKind, PatKind, Path, PathSegment, QPath, Ty, TyKind,
1010
};
1111
use rustc_middle::ty::{self, GenericArgsRef, Ty as MiddleTy};
1212
use rustc_session::{declare_lint_pass, declare_tool_lint};

compiler/rustc_passes/src/hir_id_validator.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,4 @@ impl<'a, 'hir> intravisit::Visitor<'hir> for HirIdValidator<'a, 'hir> {
161161
let mut inner_visitor = self.new_visitor(self.tcx);
162162
inner_visitor.check(i.owner_id, |this| intravisit::walk_impl_item(this, i));
163163
}
164-
165-
fn visit_pattern_type_pattern(&mut self, p: &'hir hir::Pat<'hir>) {
166-
self.visit_pat(p)
167-
}
168164
}
Lines changed: 0 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -1,120 +1 @@
1-
use clippy_utils::diagnostics::span_lint_and_sugg;
2-
use clippy_utils::source::snippet_with_context;
3-
use clippy_utils::ty::implements_trait;
4-
use rustc_errors::Applicability;
5-
use rustc_hir::{Expr, ExprKind, Pat, PatKind};
6-
use rustc_lint::{LateContext, LateLintPass, LintContext};
7-
use rustc_middle::lint::in_external_macro;
8-
use rustc_middle::ty::Ty;
9-
use rustc_session::declare_lint_pass;
101

11-
declare_clippy_lint! {
12-
/// ### What it does
13-
/// Checks for pattern matchings that can be expressed using equality.
14-
///
15-
/// ### Why is this bad?
16-
///
17-
/// * It reads better and has less cognitive load because equality won't cause binding.
18-
/// * It is a [Yoda condition](https://en.wikipedia.org/wiki/Yoda_conditions). Yoda conditions are widely
19-
/// criticized for increasing the cognitive load of reading the code.
20-
/// * Equality is a simple bool expression and can be merged with `&&` and `||` and
21-
/// reuse if blocks
22-
///
23-
/// ### Example
24-
/// ```rust,ignore
25-
/// if let Some(2) = x {
26-
/// do_thing();
27-
/// }
28-
/// ```
29-
/// Use instead:
30-
/// ```rust,ignore
31-
/// if x == Some(2) {
32-
/// do_thing();
33-
/// }
34-
/// ```
35-
#[clippy::version = "1.57.0"]
36-
pub EQUATABLE_IF_LET,
37-
nursery,
38-
"using pattern matching instead of equality"
39-
}
40-
41-
declare_lint_pass!(PatternEquality => [EQUATABLE_IF_LET]);
42-
43-
/// detects if pattern matches just one thing
44-
fn unary_pattern(pat: &Pat<'_>) -> bool {
45-
fn array_rec(pats: &[Pat<'_>]) -> bool {
46-
pats.iter().all(unary_pattern)
47-
}
48-
match &pat.kind {
49-
PatKind::Slice(_, _, _)
50-
| PatKind::Range(_, _, _)
51-
| PatKind::Binding(..)
52-
| PatKind::Wild
53-
| PatKind::Never
54-
| PatKind::Or(_)
55-
| PatKind::Err(_) => false,
56-
PatKind::Struct(_, a, etc) => !etc && a.iter().all(|x| unary_pattern(x.pat)),
57-
PatKind::Tuple(a, etc) | PatKind::TupleStruct(_, a, etc) => etc.as_opt_usize().is_none() && array_rec(a),
58-
PatKind::Ref(x, _) | PatKind::Box(x) | PatKind::Deref(x) | PatKind::Guard(x, _) => unary_pattern(x),
59-
PatKind::Expr(_) => true,
60-
}
61-
}
62-
63-
fn is_structural_partial_eq<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, other: Ty<'tcx>) -> bool {
64-
if let Some(def_id) = cx.tcx.lang_items().eq_trait() {
65-
implements_trait(cx, ty, def_id, &[other.into()])
66-
} else {
67-
false
68-
}
69-
}
70-
71-
impl<'tcx> LateLintPass<'tcx> for PatternEquality {
72-
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
73-
if let ExprKind::Let(let_expr) = expr.kind
74-
&& unary_pattern(let_expr.pat)
75-
&& !in_external_macro(cx.sess(), expr.span)
76-
{
77-
let exp_ty = cx.typeck_results().expr_ty(let_expr.init);
78-
let pat_ty = cx.typeck_results().pat_ty(let_expr.pat);
79-
let mut applicability = Applicability::MachineApplicable;
80-
81-
if is_structural_partial_eq(cx, exp_ty, pat_ty) {
82-
let pat_str = match let_expr.pat.kind {
83-
PatKind::Struct(..) => format!(
84-
"({})",
85-
snippet_with_context(cx, let_expr.pat.span, expr.span.ctxt(), "..", &mut applicability).0,
86-
),
87-
_ => snippet_with_context(cx, let_expr.pat.span, expr.span.ctxt(), "..", &mut applicability)
88-
.0
89-
.to_string(),
90-
};
91-
span_lint_and_sugg(
92-
cx,
93-
EQUATABLE_IF_LET,
94-
expr.span,
95-
"this pattern matching can be expressed using equality",
96-
"try",
97-
format!(
98-
"{} == {pat_str}",
99-
snippet_with_context(cx, let_expr.init.span, expr.span.ctxt(), "..", &mut applicability).0,
100-
),
101-
applicability,
102-
);
103-
} else {
104-
span_lint_and_sugg(
105-
cx,
106-
EQUATABLE_IF_LET,
107-
expr.span,
108-
"this pattern matching can be expressed using `matches!`",
109-
"try",
110-
format!(
111-
"matches!({}, {})",
112-
snippet_with_context(cx, let_expr.init.span, expr.span.ctxt(), "..", &mut applicability).0,
113-
snippet_with_context(cx, let_expr.pat.span, expr.span.ctxt(), "..", &mut applicability).0,
114-
),
115-
applicability,
116-
);
117-
}
118-
}
119-
}
120-
}

tests/ui/type/pattern_types/bad_const_generics_args_on_const_param.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ type Pat<const START: u32, const END: u32> =
66
//~^ ERROR type and const arguments are not allowed on const parameter `START`
77
//~| ERROR type arguments are not allowed on const parameter `END`
88
//~| ERROR associated item constraints are not allowed here
9+
//~| ERROR the placeholder `_` is not allowed within types on item signatures
910

1011
fn main() {}

tests/ui/type/pattern_types/bad_const_generics_args_on_const_param.stderr

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,13 @@ error[E0229]: associated item constraints are not allowed here
3232
LL | std::pat::pattern_type!(u32 is START::<(), i32, 2>..=END::<_, Assoc = ()>);
3333
| ^^^^^^^^^^ associated item constraint not allowed here
3434

35-
error: aborting due to 3 previous errors
35+
error[E0121]: the placeholder `_` is not allowed within types on item signatures for type aliases
36+
--> $DIR/bad_const_generics_args_on_const_param.rs:5:64
37+
|
38+
LL | std::pat::pattern_type!(u32 is START::<(), i32, 2>..=END::<_, Assoc = ()>);
39+
| ^ not allowed in type signatures
40+
41+
error: aborting due to 4 previous errors
3642

37-
Some errors have detailed explanations: E0109, E0229.
43+
Some errors have detailed explanations: E0109, E0121, E0229.
3844
For more information about an error, try `rustc --explain E0109`.

0 commit comments

Comments
 (0)