Skip to content

Commit 7eefa76

Browse files
committed
Eliminate PatKind::Path
1 parent a4eff9d commit 7eefa76

18 files changed

+135
-57
lines changed

clippy_lints/src/equatable_if_let.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ fn unary_pattern(pat: &Pat<'_>) -> bool {
5656
PatKind::Struct(_, a, etc) => !etc && a.iter().all(|x| unary_pattern(x.pat)),
5757
PatKind::Tuple(a, etc) | PatKind::TupleStruct(_, a, etc) => etc.as_opt_usize().is_none() && array_rec(a),
5858
PatKind::Ref(x, _) | PatKind::Box(x) | PatKind::Deref(x) | PatKind::Guard(x, _) => unary_pattern(x),
59-
PatKind::Path(_) | PatKind::Expr(_) => true,
59+
PatKind::Expr(_) => true,
6060
}
6161
}
6262

clippy_lints/src/manual_let_else.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use clippy_utils::ty::is_type_diagnostic_item;
77
use clippy_utils::{is_lint_allowed, is_never_expr, msrvs, pat_and_expr_can_be_question_mark, peel_blocks};
88
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
99
use rustc_errors::Applicability;
10-
use rustc_hir::{Expr, ExprKind, MatchSource, Pat, PatKind, QPath, Stmt, StmtKind};
10+
use rustc_hir::{Expr, ExprKind, MatchSource, Pat, PatExpr, PatExprKind, PatKind, QPath, Stmt, StmtKind};
1111
use rustc_lint::{LateContext, LintContext};
1212
use rustc_middle::lint::in_external_macro;
1313

@@ -292,7 +292,12 @@ fn pat_allowed_for_else(cx: &LateContext<'_>, pat: &'_ Pat<'_>, check_types: boo
292292
// Only do the check if the type is "spelled out" in the pattern
293293
if !matches!(
294294
pat.kind,
295-
PatKind::Struct(..) | PatKind::TupleStruct(..) | PatKind::Path(..)
295+
PatKind::Struct(..)
296+
| PatKind::TupleStruct(..)
297+
| PatKind::Expr(PatExpr {
298+
kind: PatExprKind::Path(..),
299+
..
300+
},)
296301
) {
297302
return;
298303
}

clippy_lints/src/manual_unwrap_or_default.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc_errors::Applicability;
22
use rustc_hir::def::Res;
3-
use rustc_hir::{Arm, Expr, ExprKind, HirId, LangItem, MatchSource, Pat, PatKind, QPath};
3+
use rustc_hir::{Arm, Expr, ExprKind, HirId, LangItem, MatchSource, Pat, PatExpr, PatExprKind, PatKind, QPath};
44
use rustc_lint::{LateContext, LateLintPass, LintContext};
55
use rustc_middle::ty::GenericArgKind;
66
use rustc_session::declare_lint_pass;
@@ -68,7 +68,7 @@ fn get_some<'tcx>(cx: &LateContext<'tcx>, pat: &Pat<'tcx>) -> Option<HirId> {
6868
}
6969

7070
fn get_none<'tcx>(cx: &LateContext<'tcx>, arm: &Arm<'tcx>) -> Option<&'tcx Expr<'tcx>> {
71-
if let PatKind::Path(QPath::Resolved(_, path)) = arm.pat.kind
71+
if let PatKind::Expr(PatExpr { kind: PatExprKind::Path(QPath::Resolved(_, path)), .. }) = arm.pat.kind
7272
&& let Some(def_id) = path.res.opt_def_id()
7373
// Since it comes from a pattern binding, we need to get the parent to actually match
7474
// against it.

clippy_lints/src/matches/collapsible_match.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use clippy_utils::{
88
};
99
use rustc_errors::MultiSpan;
1010
use rustc_hir::LangItem::OptionNone;
11-
use rustc_hir::{Arm, Expr, HirId, Pat, PatKind};
11+
use rustc_hir::{Arm, Expr, HirId, Pat, PatExpr, PatExprKind, PatKind};
1212
use rustc_lint::LateContext;
1313
use rustc_span::Span;
1414

@@ -119,7 +119,11 @@ fn arm_is_wild_like(cx: &LateContext<'_>, arm: &Arm<'_>) -> bool {
119119
}
120120
match arm.pat.kind {
121121
PatKind::Binding(..) | PatKind::Wild => true,
122-
PatKind::Path(ref qpath) => is_res_lang_ctor(cx, cx.qpath_res(qpath, arm.pat.hir_id), OptionNone),
122+
PatKind::Expr(PatExpr {
123+
kind: PatExprKind::Path(qpath),
124+
hir_id,
125+
..
126+
}) => is_res_lang_ctor(cx, cx.qpath_res(qpath, *hir_id), OptionNone),
123127
_ => false,
124128
}
125129
}

clippy_lints/src/matches/manual_ok_err.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_ast::BindingMode;
66
use rustc_errors::Applicability;
77
use rustc_hir::LangItem::{OptionNone, OptionSome, ResultErr};
88
use rustc_hir::def::{DefKind, Res};
9-
use rustc_hir::{Arm, Expr, ExprKind, Pat, PatKind, Path, QPath};
9+
use rustc_hir::{Arm, Expr, ExprKind, Pat, PatExpr, PatExprKind, PatKind, Path, QPath};
1010
use rustc_lint::{LateContext, LintContext};
1111
use rustc_middle::ty::Ty;
1212
use rustc_span::symbol::Ident;
@@ -60,7 +60,16 @@ pub(crate) fn check_match(cx: &LateContext<'_>, expr: &Expr<'_>, scrutinee: &Exp
6060
/// accepted.
6161
fn is_variant_or_wildcard(cx: &LateContext<'_>, pat: &Pat<'_>, can_be_wild: bool, must_match_err: bool) -> bool {
6262
match pat.kind {
63-
PatKind::Wild | PatKind::Path(..) | PatKind::Binding(_, _, _, None) if can_be_wild => true,
63+
PatKind::Wild
64+
| PatKind::Expr(PatExpr {
65+
kind: PatExprKind::Path(_),
66+
..
67+
})
68+
| PatKind::Binding(_, _, _, None)
69+
if can_be_wild =>
70+
{
71+
true
72+
},
6473
PatKind::TupleStruct(qpath, ..) => {
6574
is_res_lang_ctor(cx, cx.qpath_res(&qpath, pat.hir_id), ResultErr) == must_match_err
6675
},

clippy_lints/src/matches/manual_unwrap_or.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use clippy_utils::{is_res_lang_ctor, path_to_local_id, peel_blocks, sugg};
77
use rustc_errors::Applicability;
88
use rustc_hir::LangItem::{OptionNone, ResultErr};
99
use rustc_hir::def::{DefKind, Res};
10-
use rustc_hir::{Arm, Expr, Pat, PatKind};
10+
use rustc_hir::{Arm, Expr, Pat, PatExpr, PatExprKind, PatKind};
1111
use rustc_lint::LateContext;
1212
use rustc_middle::ty::Ty;
1313
use rustc_span::sym;
@@ -89,7 +89,11 @@ fn applicable_or_arm<'a>(cx: &LateContext<'_>, arms: &'a [Arm<'a>]) -> Option<(&
8989
if arms.len() == 2
9090
&& arms.iter().all(|arm| arm.guard.is_none())
9191
&& let Some((idx, or_arm)) = arms.iter().enumerate().find(|(_, arm)| match arm.pat.kind {
92-
PatKind::Path(ref qpath) => is_res_lang_ctor(cx, cx.qpath_res(qpath, arm.pat.hir_id), OptionNone),
92+
PatKind::Expr(PatExpr {
93+
hir_id,
94+
kind: PatExprKind::Path(qpath),
95+
..
96+
}) => is_res_lang_ctor(cx, cx.qpath_res(qpath, *hir_id), OptionNone),
9397
PatKind::TupleStruct(ref qpath, [pat], _) => {
9498
matches!(pat.kind, PatKind::Wild)
9599
&& is_res_lang_ctor(cx, cx.qpath_res(qpath, arm.pat.hir_id), ResultErr)

clippy_lints/src/matches/manual_utils.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_ast::util::parser::ExprPrecedence;
1111
use rustc_errors::Applicability;
1212
use rustc_hir::LangItem::{OptionNone, OptionSome};
1313
use rustc_hir::def::Res;
14-
use rustc_hir::{BindingMode, Expr, ExprKind, HirId, Mutability, Pat, PatKind, Path, QPath};
14+
use rustc_hir::{BindingMode, Expr, ExprKind, HirId, Mutability, Pat, PatExpr, PatExprKind, PatKind, Path, QPath};
1515
use rustc_lint::LateContext;
1616
use rustc_span::{SyntaxContext, sym};
1717

@@ -256,9 +256,11 @@ pub(super) fn try_parse_pattern<'tcx>(
256256
match pat.kind {
257257
PatKind::Wild => Some(OptionPat::Wild),
258258
PatKind::Ref(pat, _) => f(cx, pat, ref_count + 1, ctxt),
259-
PatKind::Path(ref qpath) if is_res_lang_ctor(cx, cx.qpath_res(qpath, pat.hir_id), OptionNone) => {
260-
Some(OptionPat::None)
261-
},
259+
PatKind::Expr(PatExpr {
260+
kind: PatExprKind::Path(qpath),
261+
hir_id,
262+
..
263+
}) if is_res_lang_ctor(cx, cx.qpath_res(qpath, *hir_id), OptionNone) => Some(OptionPat::None),
262264
PatKind::TupleStruct(ref qpath, [pattern], _)
263265
if is_res_lang_ctor(cx, cx.qpath_res(qpath, pat.hir_id), OptionSome) && pat.span.ctxt() == ctxt =>
264266
{

clippy_lints/src/matches/match_as_ref.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_sugg;
22
use clippy_utils::source::snippet_with_applicability;
33
use clippy_utils::{is_res_lang_ctor, path_res, peel_blocks};
44
use rustc_errors::Applicability;
5-
use rustc_hir::{Arm, BindingMode, ByRef, Expr, ExprKind, LangItem, Mutability, PatKind, QPath};
5+
use rustc_hir::{Arm, BindingMode, ByRef, Expr, ExprKind, LangItem, Mutability, PatExpr, PatExprKind, PatKind, QPath};
66
use rustc_lint::LateContext;
77
use rustc_middle::ty;
88

@@ -59,7 +59,7 @@ pub(crate) fn check(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr:
5959
fn is_none_arm(cx: &LateContext<'_>, arm: &Arm<'_>) -> bool {
6060
matches!(
6161
arm.pat.kind,
62-
PatKind::Path(ref qpath) if is_res_lang_ctor(cx, cx.qpath_res(qpath, arm.pat.hir_id), LangItem::OptionNone)
62+
PatKind::Expr(PatExpr { kind: PatExprKind::Path(qpath), .. }) if is_res_lang_ctor(cx, cx.qpath_res(qpath, arm.pat.hir_id), LangItem::OptionNone)
6363
)
6464
}
6565

clippy_lints/src/matches/match_same_arms.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_arena::DroplessArena;
77
use rustc_ast::ast::LitKind;
88
use rustc_errors::Applicability;
99
use rustc_hir::def_id::DefId;
10-
use rustc_hir::{Arm, Expr, HirId, HirIdMap, HirIdMapEntry, HirIdSet, Pat, PatExprKind, PatKind, RangeEnd};
10+
use rustc_hir::{Arm, Expr, HirId, HirIdMap, HirIdMapEntry, HirIdSet, Pat, PatExpr, PatExprKind, PatKind, RangeEnd};
1111
use rustc_lint::builtin::NON_EXHAUSTIVE_OMITTED_PATTERNS;
1212
use rustc_lint::{LateContext, LintContext};
1313
use rustc_middle::ty;
@@ -292,7 +292,11 @@ impl<'a> NormalizedPat<'a> {
292292
Self::Tuple(var_id, pats)
293293
},
294294
PatKind::Or(pats) => Self::Or(arena.alloc_from_iter(pats.iter().map(|pat| Self::from_pat(cx, arena, pat)))),
295-
PatKind::Path(ref path) => Self::Path(cx.qpath_res(path, pat.hir_id).opt_def_id()),
295+
PatKind::Expr(PatExpr {
296+
kind: PatExprKind::Path(path),
297+
hir_id,
298+
..
299+
}) => Self::Path(cx.qpath_res(path, *hir_id).opt_def_id()),
296300
PatKind::Tuple(pats, wild_idx) => {
297301
let field_count = match cx.typeck_results().pat_ty(pat).kind() {
298302
ty::Tuple(subs) => subs.len(),

clippy_lints/src/matches/match_wild_enum.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use clippy_utils::ty::is_type_diagnostic_item;
33
use clippy_utils::{is_refutable, peel_hir_pat_refs, recurse_or_patterns};
44
use rustc_errors::Applicability;
55
use rustc_hir::def::{CtorKind, DefKind, Res};
6-
use rustc_hir::{Arm, Expr, PatKind, PathSegment, QPath, Ty, TyKind};
6+
use rustc_hir::{Arm, Expr, PatExpr, PatExprKind, PatKind, PathSegment, QPath, Ty, TyKind};
77
use rustc_lint::LateContext;
88
use rustc_middle::ty::{self, VariantDef};
99
use rustc_span::sym;
@@ -60,8 +60,13 @@ pub(crate) fn check(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>]) {
6060
// covered by the set of guards that cover it, but that's really hard to do.
6161
recurse_or_patterns(arm.pat, |pat| {
6262
let path = match &peel_hir_pat_refs(pat).0.kind {
63-
PatKind::Path(path) => {
64-
let id = match cx.qpath_res(path, pat.hir_id) {
63+
PatKind::Expr(PatExpr {
64+
hir_id,
65+
kind: PatExprKind::Path(path),
66+
..
67+
}) => {
68+
// FIXME(clippy): don't you want to use the hir id of the peeled pat?
69+
let id = match cx.qpath_res(path, *hir_id) {
6570
Res::Def(
6671
DefKind::Const | DefKind::ConstParam | DefKind::AnonConst | DefKind::InlineConst,
6772
_,

0 commit comments

Comments
 (0)