Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a5bd41a

Browse files
committedJan 23, 2025·
Auto merge of rust-lang#134248 - oli-obk:patkind-path-removal, r=<try>
Merge `PatKind::Path` into `PatKind::Expr` Follow-up to rust-lang#134228 We always had a duplication where `Path`s could be represented as `PatKind::Path` or `PatKind::Lit(ExprKind::Path)`. We had to handle both everywhere, and still do after rust-lang#134228, so I'm removing it now.
2 parents fc0094f + dbf867b commit a5bd41a

File tree

38 files changed

+261
-171
lines changed

38 files changed

+261
-171
lines changed
 

‎compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1391,7 +1391,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
13911391
None,
13921392
);
13931393
// Destructure like a unit struct.
1394-
let unit_struct_pat = hir::PatKind::Path(qpath);
1394+
let unit_struct_pat = hir::PatKind::Expr(self.arena.alloc(hir::PatExpr {
1395+
kind: hir::PatExprKind::Path(qpath),
1396+
hir_id: self.next_id(),
1397+
span: self.lower_span(lhs.span),
1398+
}));
13951399
return self.pat_without_dbm(lhs.span, unit_struct_pat);
13961400
}
13971401
}

‎compiler/rustc_ast_lowering/src/pat.rs

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
6969
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
7070
None,
7171
);
72-
break hir::PatKind::Path(qpath);
72+
let kind = hir::PatExprKind::Path(qpath);
73+
let span = self.lower_span(pattern.span);
74+
let expr = hir::PatExpr { hir_id: pat_hir_id, span, kind };
75+
let expr = self.arena.alloc(expr);
76+
return hir::Pat {
77+
hir_id: self.next_id(),
78+
kind: hir::PatKind::Expr(expr),
79+
span,
80+
default_binding_modes: true,
81+
};
7382
}
7483
PatKind::Struct(qself, path, fields, etc) => {
7584
let qpath = self.lower_qpath(
@@ -304,16 +313,20 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
304313
)
305314
}
306315
Some(res) => {
307-
let hir_id = self.next_id();
308316
let res = self.lower_res(res);
309-
hir::PatKind::Path(hir::QPath::Resolved(
310-
None,
311-
self.arena.alloc(hir::Path {
312-
span: self.lower_span(ident.span),
313-
res,
314-
segments: arena_vec![self; hir::PathSegment::new(self.lower_ident(ident), hir_id, res)],
315-
}),
316-
))
317+
let span = self.lower_span(ident.span);
318+
hir::PatKind::Expr(self.arena.alloc(hir::PatExpr {
319+
kind: hir::PatExprKind::Path(hir::QPath::Resolved(
320+
None,
321+
self.arena.alloc(hir::Path {
322+
span,
323+
res,
324+
segments: arena_vec![self; hir::PathSegment::new(self.lower_ident(ident), self.next_id(), res)],
325+
}),
326+
)),
327+
hir_id: self.next_id(),
328+
span,
329+
}))
317330
}
318331
}
319332
}

‎compiler/rustc_hir/src/hir.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,7 +1391,7 @@ impl<'hir> Pat<'hir> {
13911391

13921392
use PatKind::*;
13931393
match self.kind {
1394-
Wild | Never | Expr(_) | Range(..) | Binding(.., None) | Path(_) | Err(_) => true,
1394+
Wild | Never | Expr(_) | Range(..) | Binding(.., None) | Err(_) => true,
13951395
Box(s) | Deref(s) | Ref(s, _) | Binding(.., Some(s)) | Guard(s, _) => s.walk_short_(it),
13961396
Struct(_, fields, _) => fields.iter().all(|field| field.pat.walk_short_(it)),
13971397
TupleStruct(_, s, _) | Tuple(s, _) | Or(s) => s.iter().all(|p| p.walk_short_(it)),
@@ -1418,7 +1418,7 @@ impl<'hir> Pat<'hir> {
14181418

14191419
use PatKind::*;
14201420
match self.kind {
1421-
Wild | Never | Expr(_) | Range(..) | Binding(.., None) | Path(_) | Err(_) => {}
1421+
Wild | Never | Expr(_) | Range(..) | Binding(.., None) | Err(_) => {}
14221422
Box(s) | Deref(s) | Ref(s, _) | Binding(.., Some(s)) | Guard(s, _) => s.walk_(it),
14231423
Struct(_, fields, _) => fields.iter().for_each(|field| field.pat.walk_(it)),
14241424
TupleStruct(_, s, _) | Tuple(s, _) | Or(s) => s.iter().for_each(|p| p.walk_(it)),
@@ -1572,9 +1572,6 @@ pub enum PatKind<'hir> {
15721572
/// A never pattern `!`.
15731573
Never,
15741574

1575-
/// A path pattern for a unit struct/variant or a (maybe-associated) constant.
1576-
Path(QPath<'hir>),
1577-
15781575
/// A tuple pattern (e.g., `(a, b)`).
15791576
/// If the `..` pattern fragment is present, then `Option<usize>` denotes its position.
15801577
/// `0 <= position <= subpats.len()`

‎compiler/rustc_hir/src/intravisit.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -668,9 +668,6 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat<'v>) -> V:
668668
try_visit!(visitor.visit_qpath(qpath, pattern.hir_id, pattern.span));
669669
walk_list!(visitor, visit_pat, children);
670670
}
671-
PatKind::Path(ref qpath) => {
672-
try_visit!(visitor.visit_qpath(qpath, pattern.hir_id, pattern.span));
673-
}
674671
PatKind::Struct(ref qpath, fields, _) => {
675672
try_visit!(visitor.visit_qpath(qpath, pattern.hir_id, pattern.span));
676673
walk_list!(visitor, visit_pat_field, fields);

‎compiler/rustc_hir/src/pat_util.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,10 @@ impl hir::Pat<'_> {
105105
let mut variants = vec![];
106106
self.walk(|p| match &p.kind {
107107
PatKind::Or(_) => false,
108-
PatKind::Path(hir::QPath::Resolved(_, path))
108+
PatKind::Expr(hir::PatExpr {
109+
kind: hir::PatExprKind::Path(hir::QPath::Resolved(_, path)),
110+
..
111+
})
109112
| PatKind::TupleStruct(hir::QPath::Resolved(_, path), ..)
110113
| PatKind::Struct(hir::QPath::Resolved(_, path), ..) => {
111114
if let Res::Def(DefKind::Variant | DefKind::Ctor(CtorOf::Variant, ..), id) =

‎compiler/rustc_hir_analysis/src/check/region.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,6 @@ fn resolve_local<'tcx>(
703703
| PatKind::Binding(hir::BindingMode(hir::ByRef::No, _), ..)
704704
| PatKind::Wild
705705
| PatKind::Never
706-
| PatKind::Path(_)
707706
| PatKind::Expr(_)
708707
| PatKind::Range(_, _, _)
709708
| PatKind::Err(_) => false,

‎compiler/rustc_hir_analysis/src/hir_ty_lowering/lint.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
3838
kind: hir::ExprKind::Path(hir::QPath::TypeRelative(qself, _)),
3939
..
4040
})
41-
| hir::Node::Pat(hir::Pat {
42-
kind: hir::PatKind::Path(hir::QPath::TypeRelative(qself, _)),
41+
| hir::Node::PatExpr(hir::PatExpr {
42+
kind: hir::PatExprKind::Path(hir::QPath::TypeRelative(qself, _)),
4343
..
4444
}) if qself.hir_id == self_ty.hir_id => true,
4545
_ => false,

‎compiler/rustc_hir_pretty/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1905,9 +1905,6 @@ impl<'a> State<'a> {
19051905
}
19061906
self.pclose();
19071907
}
1908-
PatKind::Path(ref qpath) => {
1909-
self.print_qpath(qpath, true);
1910-
}
19111908
PatKind::Struct(ref qpath, fields, etc) => {
19121909
self.print_qpath(qpath, true);
19131910
self.nbsp();

‎compiler/rustc_hir_typeck/src/expr.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
480480
hir::PatKind::Binding(_, _, _, _)
481481
| hir::PatKind::Struct(_, _, _)
482482
| hir::PatKind::TupleStruct(_, _, _)
483-
| hir::PatKind::Path(_)
484483
| hir::PatKind::Tuple(_, _)
485484
| hir::PatKind::Box(_)
486485
| hir::PatKind::Ref(_, _)

‎compiler/rustc_hir_typeck/src/expr_use_visitor.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ use hir::def::DefKind;
1111
use hir::pat_util::EnumerateAndAdjustIterator as _;
1212
use rustc_abi::{FIRST_VARIANT, FieldIdx, VariantIdx};
1313
use rustc_data_structures::fx::FxIndexMap;
14-
use rustc_hir as hir;
1514
use rustc_hir::def::{CtorOf, Res};
1615
use rustc_hir::def_id::LocalDefId;
17-
use rustc_hir::{HirId, PatKind};
16+
use rustc_hir::{self as hir, HirId, PatExpr, PatExprKind, PatKind};
1817
use rustc_lint::LateContext;
1918
use rustc_middle::hir::place::ProjectionKind;
2019
// Export these here so that Clippy can use them.
@@ -564,11 +563,11 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
564563
// FIXME(never_patterns): does this do what I expect?
565564
needs_to_be_read = true;
566565
}
567-
PatKind::Path(qpath) => {
566+
PatKind::Expr(PatExpr { kind: PatExprKind::Path(qpath), hir_id, span }) => {
568567
// A `Path` pattern is just a name like `Foo`. This is either a
569568
// named constant or else it refers to an ADT variant
570569

571-
let res = self.cx.typeck_results().qpath_res(qpath, pat.hir_id);
570+
let res = self.cx.typeck_results().qpath_res(qpath, *hir_id);
572571
match res {
573572
Res::Def(DefKind::Const, _) | Res::Def(DefKind::AssocConst, _) => {
574573
// Named constants have to be equated with the value
@@ -581,7 +580,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
581580
// Otherwise, this is a struct/enum variant, and so it's
582581
// only a read if we need to read the discriminant.
583582
needs_to_be_read |=
584-
self.is_multivariant_adt(place.place.ty(), pat.span);
583+
self.is_multivariant_adt(place.place.ty(), *span);
585584
}
586585
}
587586
}
@@ -1801,8 +1800,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
18011800
}
18021801
}
18031802

1804-
PatKind::Path(_)
1805-
| PatKind::Binding(.., None)
1803+
PatKind::Binding(.., None)
18061804
| PatKind::Expr(..)
18071805
| PatKind::Range(..)
18081806
| PatKind::Never

‎compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ use hir::def_id::LocalDefId;
55
use rustc_ast::util::parser::ExprPrecedence;
66
use rustc_data_structures::packed::Pu128;
77
use rustc_errors::{Applicability, Diag, MultiSpan};
8-
use rustc_hir as hir;
98
use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res};
109
use rustc_hir::lang_items::LangItem;
1110
use rustc_hir::{
12-
Arm, CoroutineDesugaring, CoroutineKind, CoroutineSource, Expr, ExprKind, GenericBound, HirId,
13-
Node, Path, QPath, Stmt, StmtKind, TyKind, WherePredicateKind, expr_needs_parens,
11+
self as hir, Arm, CoroutineDesugaring, CoroutineKind, CoroutineSource, Expr, ExprKind,
12+
GenericBound, HirId, Node, PatExpr, PatExprKind, Path, QPath, Stmt, StmtKind, TyKind,
13+
WherePredicateKind, expr_needs_parens,
1414
};
1515
use rustc_hir_analysis::collect::suggest_impl_trait;
1616
use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer;
@@ -1419,8 +1419,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14191419
// since the user probably just misunderstood how `let else`
14201420
// and `&&` work together.
14211421
if let Some((_, hir::Node::LetStmt(local))) = cond_parent
1422-
&& let hir::PatKind::Path(qpath) | hir::PatKind::TupleStruct(qpath, _, _) =
1423-
&local.pat.kind
1422+
&& let hir::PatKind::Expr(PatExpr { kind: PatExprKind::Path(qpath), .. })
1423+
| hir::PatKind::TupleStruct(qpath, _, _) = &local.pat.kind
14241424
&& let hir::QPath::Resolved(None, path) = qpath
14251425
&& let Some(did) = path
14261426
.res

‎compiler/rustc_hir_typeck/src/method/suggest.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
177177
})
178178
| hir::Node::Pat(&hir::Pat {
179179
kind:
180-
hir::PatKind::Path(QPath::TypeRelative(rcvr, segment))
181-
| hir::PatKind::Struct(QPath::TypeRelative(rcvr, segment), ..)
180+
hir::PatKind::Struct(QPath::TypeRelative(rcvr, segment), ..)
182181
| hir::PatKind::TupleStruct(QPath::TypeRelative(rcvr, segment), ..),
183182
span,
184183
..

‎compiler/rustc_hir_typeck/src/pat.rs

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use rustc_errors::{
1111
use rustc_hir::def::{CtorKind, DefKind, Res};
1212
use rustc_hir::pat_util::EnumerateAndAdjustIterator;
1313
use rustc_hir::{
14-
self as hir, BindingMode, ByRef, ExprKind, HirId, LangItem, Mutability, Pat, PatKind,
15-
expr_needs_parens,
14+
self as hir, BindingMode, ByRef, ExprKind, HirId, LangItem, Mutability, Pat, PatExpr,
15+
PatExprKind, PatKind, expr_needs_parens,
1616
};
1717
use rustc_infer::infer;
1818
use rustc_middle::traits::PatternOriginExpr;
@@ -312,9 +312,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
312312
fn check_pat(&self, pat: &'tcx Pat<'tcx>, expected: Ty<'tcx>, pat_info: PatInfo<'_, 'tcx>) {
313313
let PatInfo { binding_mode, max_ref_mutbl, top_info: ti, current_depth, .. } = pat_info;
314314

315-
let path_res = match &pat.kind {
316-
PatKind::Path(qpath) => {
317-
Some(self.resolve_ty_and_res_fully_qualified_call(qpath, pat.hir_id, pat.span))
315+
let path_res = match pat.kind {
316+
PatKind::Expr(PatExpr { kind: PatExprKind::Path(ref qpath), hir_id, span }) => {
317+
Some(self.resolve_ty_and_res_fully_qualified_call(qpath, *hir_id, *span))
318318
}
319319
_ => None,
320320
};
@@ -333,6 +333,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
333333
PatKind::Wild | PatKind::Err(_) => expected,
334334
// We allow any type here; we ensure that the type is uninhabited during match checking.
335335
PatKind::Never => expected,
336+
PatKind::Expr(PatExpr { kind: PatExprKind::Path(ref qpath), hir_id, span }) => {
337+
let ty = self.check_pat_path(
338+
*hir_id,
339+
pat.hir_id,
340+
*span,
341+
qpath,
342+
path_res.unwrap(),
343+
expected,
344+
ti,
345+
);
346+
self.write_ty(*hir_id, ty);
347+
ty
348+
}
336349
PatKind::Expr(lt) => self.check_pat_lit(pat.span, lt, expected, ti),
337350
PatKind::Range(lhs, rhs, _) => self.check_pat_range(pat.span, lhs, rhs, expected, ti),
338351
PatKind::Binding(ba, var_id, ident, sub) => {
@@ -341,9 +354,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
341354
PatKind::TupleStruct(ref qpath, subpats, ddpos) => {
342355
self.check_pat_tuple_struct(pat, qpath, subpats, ddpos, expected, pat_info)
343356
}
344-
PatKind::Path(ref qpath) => {
345-
self.check_pat_path(pat.hir_id, pat.span, qpath, path_res.unwrap(), expected, ti)
346-
}
347357
PatKind::Struct(ref qpath, fields, has_rest_pat) => {
348358
self.check_pat_struct(pat, qpath, fields, has_rest_pat, expected, pat_info)
349359
}
@@ -456,16 +466,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
456466
| PatKind::Slice(..) => AdjustMode::Peel,
457467
// A never pattern behaves somewhat like a literal or unit variant.
458468
PatKind::Never => AdjustMode::Peel,
459-
// String and byte-string literals result in types `&str` and `&[u8]` respectively.
460-
// All other literals result in non-reference types.
461-
// As a result, we allow `if let 0 = &&0 {}` but not `if let "foo" = &&"foo" {}`.
462-
//
463-
// Call `resolve_vars_if_possible` here for inline const blocks.
464-
PatKind::Expr(lt) => match self.resolve_vars_if_possible(self.check_pat_expr_unadjusted(lt)).kind() {
465-
ty::Ref(..) => AdjustMode::Pass,
466-
_ => AdjustMode::Peel,
467-
},
468-
PatKind::Path(_) => match opt_path_res.unwrap() {
469+
PatKind::Expr(PatExpr { kind: PatExprKind::Path(_), .. }) => match opt_path_res.unwrap() {
469470
// These constants can be of a reference type, e.g. `const X: &u8 = &0;`.
470471
// Peeling the reference types too early will cause type checking failures.
471472
// Although it would be possible to *also* peel the types of the constants too.
@@ -476,6 +477,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
476477
// a reference type wherefore peeling doesn't give up any expressiveness.
477478
_ => AdjustMode::Peel,
478479
},
480+
481+
// String and byte-string literals result in types `&str` and `&[u8]` respectively.
482+
// All other literals result in non-reference types.
483+
// As a result, we allow `if let 0 = &&0 {}` but not `if let "foo" = &&"foo" {}`.
484+
//
485+
// Call `resolve_vars_if_possible` here for inline const blocks.
486+
PatKind::Expr(lt) => match self.resolve_vars_if_possible(self.check_pat_expr_unadjusted(lt)).kind() {
487+
ty::Ref(..) => AdjustMode::Pass,
488+
_ => AdjustMode::Peel,
489+
},
490+
479491
// Ref patterns are complicated, we handle them in `check_pat_ref`.
480492
PatKind::Ref(..) => AdjustMode::Pass,
481493
// A `_` pattern works with any expected type, so there's no need to do anything.
@@ -1001,7 +1013,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10011013
PatKind::Wild
10021014
| PatKind::Never
10031015
| PatKind::Binding(..)
1004-
| PatKind::Path(..)
10051016
| PatKind::Box(..)
10061017
| PatKind::Deref(_)
10071018
| PatKind::Ref(..)
@@ -1140,6 +1151,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11401151
fn check_pat_path(
11411152
&self,
11421153
hir_id: HirId,
1154+
pat_id: HirId,
11431155
span: Span,
11441156
qpath: &hir::QPath<'_>,
11451157
path_resolution: (Res, Option<LoweredTy<'tcx>>, &'tcx [hir::PathSegment<'tcx>]),
@@ -1197,7 +1209,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11971209
if let Err(err) =
11981210
self.demand_suptype_with_origin(&self.pattern_cause(ti, span), expected, pat_ty)
11991211
{
1200-
self.emit_bad_pat_path(err, hir_id, span, res, pat_res, pat_ty, segments);
1212+
self.emit_bad_pat_path(err, pat_id, span, res, pat_res, pat_ty, segments);
12011213
}
12021214
pat_ty
12031215
}

‎compiler/rustc_lint/src/internal.rs

Lines changed: 5 additions & 7 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-
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};
@@ -164,11 +164,9 @@ impl<'tcx> LateLintPass<'tcx> for TyTyKind {
164164
TyKind::Path(QPath::Resolved(_, path)) => {
165165
if lint_ty_kind_usage(cx, &path.res) {
166166
let span = match cx.tcx.parent_hir_node(ty.hir_id) {
167-
Node::Pat(Pat {
168-
kind:
169-
PatKind::Path(qpath)
170-
| PatKind::TupleStruct(qpath, ..)
171-
| PatKind::Struct(qpath, ..),
167+
Node::PatExpr(PatExpr { kind: PatExprKind::Path(qpath), .. })
168+
| Node::Pat(Pat {
169+
kind: PatKind::TupleStruct(qpath, ..) | PatKind::Struct(qpath, ..),
172170
..
173171
})
174172
| Node::Expr(

‎compiler/rustc_lint/src/nonstandard_style.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc_abi::ExternAbi;
22
use rustc_hir::def::{DefKind, Res};
33
use rustc_hir::intravisit::FnKind;
4-
use rustc_hir::{AttrArgs, AttrItem, AttrKind, GenericParamKind, PatKind};
4+
use rustc_hir::{AttrArgs, AttrItem, AttrKind, GenericParamKind, PatExprKind, PatKind};
55
use rustc_middle::ty;
66
use rustc_session::config::CrateType;
77
use rustc_session::{declare_lint, declare_lint_pass};
@@ -527,7 +527,11 @@ impl<'tcx> LateLintPass<'tcx> for NonUpperCaseGlobals {
527527

528528
fn check_pat(&mut self, cx: &LateContext<'_>, p: &hir::Pat<'_>) {
529529
// Lint for constants that look like binding identifiers (#7526)
530-
if let PatKind::Path(hir::QPath::Resolved(None, path)) = p.kind {
530+
if let PatKind::Expr(hir::PatExpr {
531+
kind: PatExprKind::Path(hir::QPath::Resolved(None, path)),
532+
..
533+
}) = p.kind
534+
{
531535
if let Res::Def(DefKind::Const, _) = path.res {
532536
if let [segment] = path.segments {
533537
NonUpperCaseGlobals::check_upper_case(

‎compiler/rustc_mir_build/src/thir/pattern/mod.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,6 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
332332
.unwrap_or_else(PatKind::Error)
333333
}
334334

335-
hir::PatKind::Path(ref qpath) => {
336-
return self.lower_path(qpath, pat.hir_id, pat.span);
337-
}
338-
339335
hir::PatKind::Deref(subpattern) => {
340336
let mutable = self.typeck_results.pat_has_ref_mut_binding(subpattern);
341337
let mutability = if mutable { hir::Mutability::Mut } else { hir::Mutability::Not };

‎compiler/rustc_passes/src/dead.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ use hir::def_id::{LocalDefIdMap, LocalDefIdSet};
1010
use rustc_abi::FieldIdx;
1111
use rustc_data_structures::unord::UnordSet;
1212
use rustc_errors::MultiSpan;
13-
use rustc_hir as hir;
1413
use rustc_hir::def::{CtorOf, DefKind, Res};
1514
use rustc_hir::def_id::{DefId, LocalDefId, LocalModDefId};
1615
use rustc_hir::intravisit::{self, Visitor};
17-
use rustc_hir::{Node, PatKind, TyKind};
16+
use rustc_hir::{self as hir, Node, PatExpr, PatExprKind, PatKind, TyKind};
1817
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
1918
use rustc_middle::middle::privacy::Level;
2019
use rustc_middle::query::Providers;
@@ -637,8 +636,8 @@ impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> {
637636
let res = self.typeck_results().qpath_res(path, pat.hir_id);
638637
self.handle_field_pattern_match(pat, res, fields);
639638
}
640-
PatKind::Path(ref qpath) => {
641-
let res = self.typeck_results().qpath_res(qpath, pat.hir_id);
639+
PatKind::Expr(PatExpr { kind: PatExprKind::Path(ref qpath), hir_id, .. }) => {
640+
let res = self.typeck_results().qpath_res(qpath, *hir_id);
642641
self.handle_res(res);
643642
}
644643
PatKind::TupleStruct(ref qpath, fields, dotdot) => {

‎compiler/rustc_passes/src/input_stats.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,6 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
299299
TupleStruct,
300300
Or,
301301
Never,
302-
Path,
303302
Tuple,
304303
Box,
305304
Deref,

‎src/librustdoc/clean/utils.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,8 @@ pub(crate) fn name_from_pat(p: &hir::Pat<'_>) -> Symbol {
303303
return kw::Underscore;
304304
}
305305
PatKind::Binding(_, _, ident, _) => return ident.name,
306-
PatKind::TupleStruct(ref p, ..) | PatKind::Path(ref p) => qpath_to_string(p),
306+
PatKind::TupleStruct(ref p, ..)
307+
| PatKind::Expr(PatExpr { kind: PatExprKind::Path(ref p), .. }) => qpath_to_string(p),
307308
PatKind::Or(pats) => {
308309
pats.iter().map(|p| name_from_pat(p).to_string()).collect::<Vec<String>>().join(" | ")
309310
}

‎src/librustdoc/html/render/span_map.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
44
use rustc_hir::def::{DefKind, Res};
55
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
66
use rustc_hir::intravisit::{self, Visitor};
7-
use rustc_hir::{ExprKind, HirId, Item, ItemKind, Mod, Node, Pat, PatKind, QPath};
7+
use rustc_hir::{
8+
ExprKind, HirId, Item, ItemKind, Mod, Node, Pat, PatExpr, PatExprKind, PatKind, QPath,
9+
};
810
use rustc_middle::hir::nested_filter;
911
use rustc_middle::ty::TyCtxt;
1012
use rustc_span::hygiene::MacroKind;
@@ -191,17 +193,21 @@ impl SpanMapVisitor<'_> {
191193
}
192194

193195
fn handle_pat(&mut self, p: &Pat<'_>) {
196+
let mut check_qpath = |qpath, hir_id| match qpath {
197+
QPath::TypeRelative(_, path) if matches!(path.res, Res::Err) => {
198+
self.infer_id(path.hir_id, Some(hir_id), qpath.span());
199+
}
200+
QPath::Resolved(_, path) => self.handle_path(path),
201+
_ => {}
202+
};
194203
match p.kind {
195204
PatKind::Binding(_, _, _, Some(p)) => self.handle_pat(p),
196-
PatKind::Struct(qpath, _, _)
197-
| PatKind::TupleStruct(qpath, _, _)
198-
| PatKind::Path(qpath) => match qpath {
199-
QPath::TypeRelative(_, path) if matches!(path.res, Res::Err) => {
200-
self.infer_id(path.hir_id, Some(p.hir_id), qpath.span());
201-
}
202-
QPath::Resolved(_, path) => self.handle_path(path),
203-
_ => {}
204-
},
205+
PatKind::Struct(qpath, _, _) | PatKind::TupleStruct(qpath, _, _) => {
206+
check_qpath(qpath, p.hir_id)
207+
}
208+
PatKind::Expr(PatExpr { kind: PatExprKind::Path(qpath), hir_id, .. }) => {
209+
check_qpath(*qpath, *hir_id)
210+
}
205211
PatKind::Or(pats) => {
206212
for pat in pats {
207213
self.handle_pat(pat);

‎src/tools/clippy/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

‎src/tools/clippy/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
};

‎src/tools/clippy/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.

‎src/tools/clippy/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(ref qpath),
124+
hir_id,
125+
..
126+
}) => is_res_lang_ctor(cx, cx.qpath_res(qpath, *hir_id), OptionNone),
123127
_ => false,
124128
}
125129
}

‎src/tools/clippy/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(ref 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)

‎src/tools/clippy/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(ref 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
{

‎src/tools/clippy/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(ref qpath), .. }) if is_res_lang_ctor(cx, cx.qpath_res(qpath, arm.pat.hir_id), LangItem::OptionNone)
6363
)
6464
}
6565

‎src/tools/clippy/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(ref 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(),

‎src/tools/clippy/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(ref 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
_,

‎src/tools/clippy/clippy_lints/src/matches/needless_match.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ use clippy_utils::{
88
};
99
use rustc_errors::Applicability;
1010
use rustc_hir::LangItem::OptionNone;
11-
use rustc_hir::{Arm, BindingMode, ByRef, Expr, ExprKind, ItemKind, Node, Pat, PatExprKind, PatKind, Path, QPath};
11+
use rustc_hir::{
12+
Arm, BindingMode, ByRef, Expr, ExprKind, ItemKind, Node, Pat, PatExpr, PatExprKind, PatKind, Path, QPath,
13+
};
1214
use rustc_lint::LateContext;
1315
use rustc_span::sym;
1416

@@ -183,7 +185,13 @@ fn pat_same_as_expr(pat: &Pat<'_>, expr: &Expr<'_>) -> bool {
183185
return !matches!(annot, BindingMode(ByRef::Yes(_), _)) && pat_ident.name == first_seg.ident.name;
184186
},
185187
// Example: `Custom::TypeA => Custom::TypeB`, or `None => None`
186-
(PatKind::Path(QPath::Resolved(_, p_path)), ExprKind::Path(QPath::Resolved(_, e_path))) => {
188+
(
189+
PatKind::Expr(PatExpr {
190+
kind: PatExprKind::Path(QPath::Resolved(_, p_path)),
191+
..
192+
}),
193+
ExprKind::Path(QPath::Resolved(_, e_path)),
194+
) => {
187195
return over(p_path.segments, e_path.segments, |p_seg, e_seg| {
188196
p_seg.ident.name == e_seg.ident.name
189197
});

‎src/tools/clippy/clippy_lints/src/matches/redundant_pattern_match.rs

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_ast::ast::LitKind;
99
use rustc_errors::Applicability;
1010
use rustc_hir::LangItem::{self, OptionNone, OptionSome, PollPending, PollReady, ResultErr, ResultOk};
1111
use rustc_hir::def::{DefKind, Res};
12-
use rustc_hir::{Arm, Expr, ExprKind, Node, Pat, PatExprKind, PatKind, QPath, UnOp};
12+
use rustc_hir::{Arm, Expr, ExprKind, Node, Pat, PatExpr, PatExprKind, PatKind, QPath, UnOp};
1313
use rustc_lint::LateContext;
1414
use rustc_middle::ty::{self, GenericArgKind, Ty};
1515
use rustc_span::{Span, Symbol, sym};
@@ -149,8 +149,12 @@ fn find_method_and_type<'tcx>(
149149
None
150150
}
151151
},
152-
PatKind::Path(ref path) => {
153-
if let Res::Def(DefKind::Ctor(..), ctor_id) = cx.qpath_res(path, check_pat.hir_id)
152+
PatKind::Expr(PatExpr {
153+
kind: PatExprKind::Path(ref path),
154+
hir_id,
155+
..
156+
}) => {
157+
if let Res::Def(DefKind::Ctor(..), ctor_id) = cx.qpath_res(path, *hir_id)
154158
&& let Some(variant_id) = cx.tcx.opt_parent(ctor_id)
155159
{
156160
let method = if cx.tcx.lang_items().option_none_variant() == Some(variant_id) {
@@ -351,10 +355,20 @@ fn found_good_method<'tcx>(
351355
None
352356
}
353357
},
354-
(PatKind::TupleStruct(path_left, patterns, _), PatKind::Path(path_right))
355-
| (PatKind::Path(path_left), PatKind::TupleStruct(path_right, patterns, _))
356-
if patterns.len() == 1 =>
357-
{
358+
(
359+
PatKind::TupleStruct(path_left, patterns, _),
360+
PatKind::Expr(PatExpr {
361+
kind: PatExprKind::Path(path_right),
362+
..
363+
}),
364+
)
365+
| (
366+
PatKind::Expr(PatExpr {
367+
kind: PatExprKind::Path(path_left),
368+
..
369+
}),
370+
PatKind::TupleStruct(path_right, patterns, _),
371+
) if patterns.len() == 1 => {
358372
if let PatKind::Wild = patterns[0].kind {
359373
find_good_method_for_match(
360374
cx,
@@ -389,7 +403,13 @@ fn found_good_method<'tcx>(
389403
None
390404
}
391405
},
392-
(PatKind::Path(path_left), PatKind::Wild) => get_good_method(cx, arms, path_left),
406+
(
407+
PatKind::Expr(PatExpr {
408+
kind: PatExprKind::Path(path_left),
409+
..
410+
}),
411+
PatKind::Wild,
412+
) => get_good_method(cx, arms, path_left),
393413
_ => None,
394414
}
395415
}

‎src/tools/clippy/clippy_lints/src/matches/single_match.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ fn report_single_pattern(cx: &LateContext<'_>, ex: &Expr<'_>, arm: &Arm<'_>, exp
114114
}
115115

116116
let (pat, pat_ref_count) = peel_hir_pat_refs(arm.pat);
117-
let (msg, sugg) = if let PatKind::Path(_) | PatKind::Expr(_) = pat.kind
117+
let (msg, sugg) = if let PatKind::Expr(_) = pat.kind
118118
&& let (ty, ty_ref_count) = peel_middle_ty_refs(cx.typeck_results().expr_ty(ex))
119119
&& let Some(spe_trait_id) = cx.tcx.lang_items().structural_peq_trait()
120120
&& let Some(pe_trait_id) = cx.tcx.lang_items().eq_trait()
@@ -331,14 +331,16 @@ impl<'a> PatState<'a> {
331331
#[expect(clippy::similar_names)]
332332
fn add_pat<'tcx>(&mut self, cx: &'a PatCtxt<'tcx>, pat: &'tcx Pat<'_>) -> bool {
333333
match pat.kind {
334-
PatKind::Path(_)
335-
if match *cx.typeck.pat_ty(pat).peel_refs().kind() {
336-
ty::Adt(adt, _) => adt.is_enum() || (adt.is_struct() && !adt.non_enum_variant().fields.is_empty()),
337-
ty::Tuple(tys) => !tys.is_empty(),
338-
ty::Array(_, len) => len.try_to_target_usize(cx.tcx) != Some(1),
339-
ty::Slice(..) => true,
340-
_ => false,
341-
} =>
334+
PatKind::Expr(PatExpr {
335+
kind: PatExprKind::Path(_),
336+
..
337+
}) if match *cx.typeck.pat_ty(pat).peel_refs().kind() {
338+
ty::Adt(adt, _) => adt.is_enum() || (adt.is_struct() && !adt.non_enum_variant().fields.is_empty()),
339+
ty::Tuple(tys) => !tys.is_empty(),
340+
ty::Array(_, len) => len.try_to_target_usize(cx.tcx) != Some(1),
341+
ty::Slice(..) => true,
342+
_ => false,
343+
} =>
342344
{
343345
matches!(self, Self::Wild)
344346
},
@@ -386,7 +388,6 @@ impl<'a> PatState<'a> {
386388
| PatKind::Binding(_, _, _, None)
387389
| PatKind::Expr(_)
388390
| PatKind::Range(..)
389-
| PatKind::Path(_)
390391
| PatKind::Never
391392
| PatKind::Err(_) => {
392393
*self = PatState::Wild;

‎src/tools/clippy/clippy_lints/src/option_if_let_else.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ use clippy_utils::{
77
use rustc_errors::Applicability;
88
use rustc_hir::LangItem::{OptionNone, OptionSome, ResultErr, ResultOk};
99
use rustc_hir::def::Res;
10-
use rustc_hir::{Arm, BindingMode, Expr, ExprKind, MatchSource, Mutability, Pat, PatKind, Path, QPath, UnOp};
10+
use rustc_hir::{
11+
Arm, BindingMode, Expr, ExprKind, MatchSource, Mutability, Pat, PatExpr, PatExprKind, PatKind, Path, QPath, UnOp,
12+
};
1113
use rustc_lint::{LateContext, LateLintPass};
1214
use rustc_session::declare_lint_pass;
1315
use rustc_span::SyntaxContext;
@@ -281,7 +283,11 @@ fn try_convert_match<'tcx>(
281283

282284
fn is_none_or_err_arm(cx: &LateContext<'_>, arm: &Arm<'_>) -> bool {
283285
match arm.pat.kind {
284-
PatKind::Path(ref qpath) => is_res_lang_ctor(cx, cx.qpath_res(qpath, arm.pat.hir_id), OptionNone),
286+
PatKind::Expr(PatExpr {
287+
kind: PatExprKind::Path(ref qpath),
288+
hir_id,
289+
..
290+
}) => is_res_lang_ctor(cx, cx.qpath_res(qpath, *hir_id), OptionNone),
285291
PatKind::TupleStruct(ref qpath, [first_pat], _) => {
286292
is_res_lang_ctor(cx, cx.qpath_res(qpath, arm.pat.hir_id), ResultErr)
287293
&& matches!(first_pat.kind, PatKind::Wild)

‎src/tools/clippy/clippy_lints/src/use_self.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_hir::def_id::LocalDefId;
1010
use rustc_hir::intravisit::{Visitor, walk_inf, walk_ty};
1111
use rustc_hir::{
1212
self as hir, Expr, ExprKind, FnRetTy, FnSig, GenericArgsParentheses, GenericParam, GenericParamKind, HirId, Impl,
13-
ImplItemKind, Item, ItemKind, Pat, PatKind, Path, QPath, Ty, TyKind,
13+
ImplItemKind, Item, ItemKind, Pat, PatExpr, PatExprKind, PatKind, Path, QPath, Ty, TyKind,
1414
};
1515
use rustc_hir_analysis::lower_ty;
1616
use rustc_lint::{LateContext, LateLintPass};
@@ -257,7 +257,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
257257
&& self.msrv.meets(msrvs::TYPE_ALIAS_ENUM_VARIANTS)
258258
&& let Some(&StackItem::Check { impl_id, .. }) = self.stack.last()
259259
// get the path from the pattern
260-
&& let PatKind::Path(QPath::Resolved(_, path))
260+
&& let PatKind::Expr(&PatExpr { kind: PatExprKind::Path(QPath::Resolved(_, path)), .. })
261261
| PatKind::TupleStruct(QPath::Resolved(_, path), _, _)
262262
| PatKind::Struct(QPath::Resolved(_, path), _, _) = pat.kind
263263
&& cx.typeck_results().pat_ty(pat) == cx.tcx.type_of(impl_id).instantiate_identity()

‎src/tools/clippy/clippy_lints/src/utils/author.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -708,11 +708,6 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
708708
self.qpath(qpath);
709709
self.slice(fields, |pat| self.pat(pat));
710710
},
711-
PatKind::Path(ref qpath) => {
712-
bind!(self, qpath);
713-
kind!("Path(ref {qpath})");
714-
self.qpath(qpath);
715-
},
716711
PatKind::Tuple(fields, skip_pos) => {
717712
bind!(self, fields);
718713
kind!("Tuple({fields}, {skip_pos:?})");

‎src/tools/clippy/clippy_utils/src/hir_utils.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,6 @@ impl HirEqInterExpr<'_, '_, '_> {
524524
}
525525
eq
526526
},
527-
(PatKind::Path(l), PatKind::Path(r)) => self.eq_qpath(l, r),
528527
(&PatKind::Expr(l), &PatKind::Expr(r)) => self.eq_pat_expr(l, r),
529528
(&PatKind::Tuple(l, ls), &PatKind::Tuple(r, rs)) => ls == rs && over(l, r, |l, r| self.eq_pat(l, r)),
530529
(&PatKind::Range(ref ls, ref le, li), &PatKind::Range(ref rs, ref re, ri)) => {
@@ -1120,7 +1119,6 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
11201119
self.hash_pat(pat);
11211120
}
11221121
},
1123-
PatKind::Path(ref qpath) => self.hash_qpath(qpath),
11241122
PatKind::Range(s, e, i) => {
11251123
if let Some(s) = s {
11261124
self.hash_pat_expr(s);

‎src/tools/clippy/clippy_utils/src/lib.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ use rustc_hir::{
106106
self as hir, Arm, BindingMode, Block, BlockCheckMode, Body, ByRef, Closure, ConstArgKind, ConstContext,
107107
Destination, Expr, ExprField, ExprKind, FnDecl, FnRetTy, GenericArgs, HirId, Impl, ImplItem, ImplItemKind,
108108
ImplItemRef, Item, ItemKind, LangItem, LetStmt, MatchSource, Mutability, Node, OwnerId, OwnerNode, Param, Pat,
109-
PatKind, Path, PathSegment, PrimTy, QPath, Stmt, StmtKind, TraitItem, TraitItemKind, TraitItemRef, TraitRef,
110-
TyKind, UnOp, def,
109+
PatExpr, PatExprKind, PatKind, Path, PathSegment, PrimTy, QPath, Stmt, StmtKind, TraitItem, TraitItemKind,
110+
TraitItemRef, TraitRef, TyKind, UnOp, def,
111111
};
112112
use rustc_lexer::{TokenKind, tokenize};
113113
use rustc_lint::{LateContext, Level, Lint, LintContext};
@@ -561,7 +561,20 @@ macro_rules! maybe_path {
561561
};
562562
}
563563
maybe_path!(Expr, ExprKind);
564-
maybe_path!(Pat, PatKind);
564+
impl<'hir> MaybePath<'hir> for Pat<'hir> {
565+
fn hir_id(&self) -> HirId {
566+
self.hir_id
567+
}
568+
fn qpath_opt(&self) -> Option<&QPath<'hir>> {
569+
match &self.kind {
570+
PatKind::Expr(PatExpr {
571+
kind: PatExprKind::Path(qpath),
572+
..
573+
}) => Some(qpath),
574+
_ => None,
575+
}
576+
}
577+
}
565578
maybe_path!(Ty, TyKind);
566579

567580
/// If `maybe_path` is a path node, resolves it, otherwise returns `Res::Err`
@@ -1754,7 +1767,11 @@ pub fn is_refutable(cx: &LateContext<'_>, pat: &Pat<'_>) -> bool {
17541767
PatKind::Wild | PatKind::Never => false, // If `!` typechecked then the type is empty, so not refutable.
17551768
PatKind::Binding(_, _, _, pat) => pat.is_some_and(|pat| is_refutable(cx, pat)),
17561769
PatKind::Box(pat) | PatKind::Ref(pat, _) => is_refutable(cx, pat),
1757-
PatKind::Path(ref qpath) => is_enum_variant(cx, qpath, pat.hir_id),
1770+
PatKind::Expr(PatExpr {
1771+
kind: PatExprKind::Path(ref qpath),
1772+
hir_id,
1773+
..
1774+
}) => is_enum_variant(cx, qpath, *hir_id),
17581775
PatKind::Or(pats) => {
17591776
// TODO: should be the honest check, that pats is exhaustive set
17601777
are_refutable(cx, pats)

‎tests/ui/thir-print/thir-tree-match.stdout

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ params: [
2626
body:
2727
Expr {
2828
ty: bool
29-
temp_lifetime: TempLifetime { temp_lifetime: Some(Node(26)), backwards_incompatible: None }
29+
temp_lifetime: TempLifetime { temp_lifetime: Some(Node(28)), backwards_incompatible: None }
3030
span: $DIR/thir-tree-match.rs:15:32: 21:2 (#0)
3131
kind:
3232
Scope {
33-
region_scope: Node(26)
34-
lint_level: Explicit(HirId(DefId(0:16 ~ thir_tree_match[fcf8]::has_match).26))
33+
region_scope: Node(28)
34+
lint_level: Explicit(HirId(DefId(0:16 ~ thir_tree_match[fcf8]::has_match).28))
3535
value:
3636
Expr {
3737
ty: bool
38-
temp_lifetime: TempLifetime { temp_lifetime: Some(Node(26)), backwards_incompatible: None }
38+
temp_lifetime: TempLifetime { temp_lifetime: Some(Node(28)), backwards_incompatible: None }
3939
span: $DIR/thir-tree-match.rs:15:32: 21:2 (#0)
4040
kind:
4141
Block {
@@ -47,7 +47,7 @@ body:
4747
expr:
4848
Expr {
4949
ty: bool
50-
temp_lifetime: TempLifetime { temp_lifetime: Some(Node(26)), backwards_incompatible: None }
50+
temp_lifetime: TempLifetime { temp_lifetime: Some(Node(28)), backwards_incompatible: None }
5151
span: $DIR/thir-tree-match.rs:16:5: 20:6 (#0)
5252
kind:
5353
Scope {
@@ -56,14 +56,14 @@ body:
5656
value:
5757
Expr {
5858
ty: bool
59-
temp_lifetime: TempLifetime { temp_lifetime: Some(Node(26)), backwards_incompatible: None }
59+
temp_lifetime: TempLifetime { temp_lifetime: Some(Node(28)), backwards_incompatible: None }
6060
span: $DIR/thir-tree-match.rs:16:5: 20:6 (#0)
6161
kind:
6262
Match {
6363
scrutinee:
6464
Expr {
6565
ty: Foo
66-
temp_lifetime: TempLifetime { temp_lifetime: Some(Node(26)), backwards_incompatible: None }
66+
temp_lifetime: TempLifetime { temp_lifetime: Some(Node(28)), backwards_incompatible: None }
6767
span: $DIR/thir-tree-match.rs:16:11: 16:14 (#0)
6868
kind:
6969
Scope {
@@ -72,7 +72,7 @@ body:
7272
value:
7373
Expr {
7474
ty: Foo
75-
temp_lifetime: TempLifetime { temp_lifetime: Some(Node(26)), backwards_incompatible: None }
75+
temp_lifetime: TempLifetime { temp_lifetime: Some(Node(28)), backwards_incompatible: None }
7676
span: $DIR/thir-tree-match.rs:16:11: 16:14 (#0)
7777
kind:
7878
VarRef {
@@ -123,25 +123,25 @@ body:
123123
body:
124124
Expr {
125125
ty: bool
126-
temp_lifetime: TempLifetime { temp_lifetime: Some(Node(13)), backwards_incompatible: None }
126+
temp_lifetime: TempLifetime { temp_lifetime: Some(Node(14)), backwards_incompatible: None }
127127
span: $DIR/thir-tree-match.rs:17:36: 17:40 (#0)
128128
kind:
129129
Scope {
130-
region_scope: Node(14)
131-
lint_level: Explicit(HirId(DefId(0:16 ~ thir_tree_match[fcf8]::has_match).14))
130+
region_scope: Node(15)
131+
lint_level: Explicit(HirId(DefId(0:16 ~ thir_tree_match[fcf8]::has_match).15))
132132
value:
133133
Expr {
134134
ty: bool
135-
temp_lifetime: TempLifetime { temp_lifetime: Some(Node(13)), backwards_incompatible: None }
135+
temp_lifetime: TempLifetime { temp_lifetime: Some(Node(14)), backwards_incompatible: None }
136136
span: $DIR/thir-tree-match.rs:17:36: 17:40 (#0)
137137
kind:
138138
Literal( lit: Spanned { node: Bool(true), span: $DIR/thir-tree-match.rs:17:36: 17:40 (#0) }, neg: false)
139139

140140
}
141141
}
142142
}
143-
lint_level: Explicit(HirId(DefId(0:16 ~ thir_tree_match[fcf8]::has_match).13))
144-
scope: Node(13)
143+
lint_level: Explicit(HirId(DefId(0:16 ~ thir_tree_match[fcf8]::has_match).14))
144+
scope: Node(14)
145145
span: $DIR/thir-tree-match.rs:17:9: 17:40 (#0)
146146
}
147147
Arm {
@@ -175,25 +175,25 @@ body:
175175
body:
176176
Expr {
177177
ty: bool
178-
temp_lifetime: TempLifetime { temp_lifetime: Some(Node(19)), backwards_incompatible: None }
178+
temp_lifetime: TempLifetime { temp_lifetime: Some(Node(20)), backwards_incompatible: None }
179179
span: $DIR/thir-tree-match.rs:18:27: 18:32 (#0)
180180
kind:
181181
Scope {
182-
region_scope: Node(20)
183-
lint_level: Explicit(HirId(DefId(0:16 ~ thir_tree_match[fcf8]::has_match).20))
182+
region_scope: Node(21)
183+
lint_level: Explicit(HirId(DefId(0:16 ~ thir_tree_match[fcf8]::has_match).21))
184184
value:
185185
Expr {
186186
ty: bool
187-
temp_lifetime: TempLifetime { temp_lifetime: Some(Node(19)), backwards_incompatible: None }
187+
temp_lifetime: TempLifetime { temp_lifetime: Some(Node(20)), backwards_incompatible: None }
188188
span: $DIR/thir-tree-match.rs:18:27: 18:32 (#0)
189189
kind:
190190
Literal( lit: Spanned { node: Bool(false), span: $DIR/thir-tree-match.rs:18:27: 18:32 (#0) }, neg: false)
191191

192192
}
193193
}
194194
}
195-
lint_level: Explicit(HirId(DefId(0:16 ~ thir_tree_match[fcf8]::has_match).19))
196-
scope: Node(19)
195+
lint_level: Explicit(HirId(DefId(0:16 ~ thir_tree_match[fcf8]::has_match).20))
196+
scope: Node(20)
197197
span: $DIR/thir-tree-match.rs:18:9: 18:32 (#0)
198198
}
199199
Arm {
@@ -219,25 +219,25 @@ body:
219219
body:
220220
Expr {
221221
ty: bool
222-
temp_lifetime: TempLifetime { temp_lifetime: Some(Node(24)), backwards_incompatible: None }
222+
temp_lifetime: TempLifetime { temp_lifetime: Some(Node(26)), backwards_incompatible: None }
223223
span: $DIR/thir-tree-match.rs:19:24: 19:28 (#0)
224224
kind:
225225
Scope {
226-
region_scope: Node(25)
227-
lint_level: Explicit(HirId(DefId(0:16 ~ thir_tree_match[fcf8]::has_match).25))
226+
region_scope: Node(27)
227+
lint_level: Explicit(HirId(DefId(0:16 ~ thir_tree_match[fcf8]::has_match).27))
228228
value:
229229
Expr {
230230
ty: bool
231-
temp_lifetime: TempLifetime { temp_lifetime: Some(Node(24)), backwards_incompatible: None }
231+
temp_lifetime: TempLifetime { temp_lifetime: Some(Node(26)), backwards_incompatible: None }
232232
span: $DIR/thir-tree-match.rs:19:24: 19:28 (#0)
233233
kind:
234234
Literal( lit: Spanned { node: Bool(true), span: $DIR/thir-tree-match.rs:19:24: 19:28 (#0) }, neg: false)
235235

236236
}
237237
}
238238
}
239-
lint_level: Explicit(HirId(DefId(0:16 ~ thir_tree_match[fcf8]::has_match).24))
240-
scope: Node(24)
239+
lint_level: Explicit(HirId(DefId(0:16 ~ thir_tree_match[fcf8]::has_match).26))
240+
scope: Node(26)
241241
span: $DIR/thir-tree-match.rs:19:9: 19:28 (#0)
242242
}
243243
]

0 commit comments

Comments
 (0)
This repository has been archived.