Skip to content

Commit f80bb4f

Browse files
committed
Eliminate PatKind::Path
1 parent 37cf874 commit f80bb4f

File tree

24 files changed

+116
-102
lines changed

24 files changed

+116
-102
lines changed

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1384,7 +1384,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
13841384
None,
13851385
);
13861386
// Destructure like a unit struct.
1387-
let unit_struct_pat = hir::PatKind::Path(qpath);
1387+
let unit_struct_pat = hir::PatKind::Lit(self.arena.alloc(hir::PatLit {
1388+
hir_id: self.lower_node_id(lhs.id),
1389+
span: lhs.span,
1390+
kind: hir::PatLitKind::Path(qpath),
1391+
}));
13881392
return self.pat_without_dbm(lhs.span, unit_struct_pat);
13891393
}
13901394
}

compiler/rustc_ast_lowering/src/pat.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
7070
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
7171
None,
7272
);
73-
break hir::PatKind::Path(qpath);
73+
let kind = hir::PatLitKind::Path(qpath);
74+
let lit = hir::PatLit { hir_id: pat_hir_id, span: pattern.span, kind };
75+
let lit = self.arena.alloc(lit);
76+
return hir::Pat {
77+
hir_id: self.next_id(),
78+
kind: hir::PatKind::Lit(lit),
79+
span: pattern.span,
80+
default_binding_modes: true,
81+
};
7482
}
7583
PatKind::Struct(qself, path, fields, etc) => {
7684
let qpath = self.lower_qpath(
@@ -299,14 +307,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
299307
Some(res) => {
300308
let hir_id = self.next_id();
301309
let res = self.lower_res(res);
302-
hir::PatKind::Path(hir::QPath::Resolved(
310+
let kind = hir::PatLitKind::Path(hir::QPath::Resolved(
303311
None,
304312
self.arena.alloc(hir::Path {
305313
span: self.lower_span(ident.span),
306314
res,
307315
segments: arena_vec![self; hir::PathSegment::new(self.lower_ident(ident), hir_id, res)],
308316
}),
309-
))
317+
));
318+
let lit = hir::PatLit { kind, hir_id: self.next_id(), span: ident.span };
319+
let lit = self.arena.alloc(lit);
320+
hir::PatKind::Lit(lit)
310321
}
311322
}
312323
}

compiler/rustc_hir/src/hir.rs

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

11381138
use PatKind::*;
11391139
match self.kind {
1140-
Wild | Never | Lit(_) | Range(..) | Binding(.., None) | Path(_) | Err(_) => true,
1140+
Wild | Never | Lit(_) | Range(..) | Binding(.., None) | Err(_) => true,
11411141
Box(s) | Deref(s) | Ref(s, _) | Binding(.., Some(s)) => s.walk_short_(it),
11421142
Struct(_, fields, _) => fields.iter().all(|field| field.pat.walk_short_(it)),
11431143
TupleStruct(_, s, _) | Tuple(s, _) | Or(s) => s.iter().all(|p| p.walk_short_(it)),
@@ -1164,7 +1164,7 @@ impl<'hir> Pat<'hir> {
11641164

11651165
use PatKind::*;
11661166
match self.kind {
1167-
Wild | Never | Lit(_) | Range(..) | Binding(.., None) | Path(_) | Err(_) => {}
1167+
Wild | Never | Lit(_) | Range(..) | Binding(.., None) | Err(_) => {}
11681168
Box(s) | Deref(s) | Ref(s, _) | Binding(.., Some(s)) => s.walk_(it),
11691169
Struct(_, fields, _) => fields.iter().for_each(|field| field.pat.walk_(it)),
11701170
TupleStruct(_, s, _) | Tuple(s, _) | Or(s) => s.iter().for_each(|p| p.walk_(it)),
@@ -1317,9 +1317,6 @@ pub enum PatKind<'hir> {
13171317
/// A never pattern `!`.
13181318
Never,
13191319

1320-
/// A path pattern for a unit struct/variant or a (maybe-associated) constant.
1321-
Path(QPath<'hir>),
1322-
13231320
/// A tuple pattern (e.g., `(a, b)`).
13241321
/// If the `..` pattern fragment is present, then `Option<usize>` denotes its position.
13251322
/// `0 <= position <= subpats.len()`

compiler/rustc_hir/src/intravisit.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -669,9 +669,6 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat<'v>) -> V:
669669
try_visit!(visitor.visit_qpath(qpath, pattern.hir_id, pattern.span));
670670
walk_list!(visitor, visit_pat, children);
671671
}
672-
PatKind::Path(ref qpath) => {
673-
try_visit!(visitor.visit_qpath(qpath, pattern.hir_id, pattern.span));
674-
}
675672
PatKind::Struct(ref qpath, fields, _) => {
676673
try_visit!(visitor.visit_qpath(qpath, pattern.hir_id, pattern.span));
677674
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
@@ -106,7 +106,10 @@ impl hir::Pat<'_> {
106106
let mut variants = vec![];
107107
self.walk(|p| match &p.kind {
108108
PatKind::Or(_) => false,
109-
PatKind::Path(hir::QPath::Resolved(_, path))
109+
PatKind::Lit(hir::PatLit {
110+
kind: hir::PatLitKind::Path(hir::QPath::Resolved(_, path)),
111+
..
112+
})
110113
| PatKind::TupleStruct(hir::QPath::Resolved(_, path), ..)
111114
| PatKind::Struct(hir::QPath::Resolved(_, path), ..) => {
112115
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
@@ -700,7 +700,6 @@ fn resolve_local<'tcx>(
700700
| PatKind::Binding(hir::BindingMode(hir::ByRef::No, _), ..)
701701
| PatKind::Wild
702702
| PatKind::Never
703-
| PatKind::Path(_)
704703
| PatKind::Lit(_)
705704
| PatKind::Range(_, _, _)
706705
| PatKind::Err(_) => false,

compiler/rustc_hir_analysis/src/hir_ty_lowering/lint.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
3737
..
3838
})
3939
| hir::Node::Pat(hir::Pat {
40-
kind: hir::PatKind::Path(hir::QPath::TypeRelative(qself, _)),
40+
kind:
41+
hir::PatKind::Lit(hir::PatLit {
42+
kind: hir::PatLitKind::Path(hir::QPath::TypeRelative(qself, _)),
43+
..
44+
}),
4145
..
4246
}) if qself.hir_id == self_ty.hir_id => true,
4347
_ => false,

compiler/rustc_hir_pretty/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1771,9 +1771,6 @@ impl<'a> State<'a> {
17711771
}
17721772
self.pclose();
17731773
}
1774-
PatKind::Path(ref qpath) => {
1775-
self.print_qpath(qpath, true);
1776-
}
17771774
PatKind::Struct(ref qpath, fields, etc) => {
17781775
self.print_qpath(qpath, true);
17791776
self.nbsp();

compiler/rustc_hir_typeck/src/expr.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
468468
hir::PatKind::Binding(_, _, _, _)
469469
| hir::PatKind::Struct(_, _, _)
470470
| hir::PatKind::TupleStruct(_, _, _)
471-
| hir::PatKind::Path(_)
472471
| hir::PatKind::Tuple(_, _)
473472
| hir::PatKind::Box(_)
474473
| hir::PatKind::Ref(_, _)

compiler/rustc_hir_typeck/src/expr_use_visitor.rs

Lines changed: 4 additions & 6 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, PatKind, PatLit, PatLitKind};
1817
use rustc_lint::LateContext;
1918
use rustc_middle::hir::place::ProjectionKind;
2019
// Export these here so that Clippy can use them.
@@ -560,11 +559,11 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
560559
// FIXME(never_patterns): does this do what I expect?
561560
needs_to_be_read = true;
562561
}
563-
PatKind::Path(qpath) => {
562+
PatKind::Lit(PatLit { kind: PatLitKind::Path(qpath), hir_id, .. }) => {
564563
// A `Path` pattern is just a name like `Foo`. This is either a
565564
// named constant or else it refers to an ADT variant
566565

567-
let res = self.cx.typeck_results().qpath_res(qpath, pat.hir_id);
566+
let res = self.cx.typeck_results().qpath_res(qpath, *hir_id);
568567
match res {
569568
Res::Def(DefKind::Const, _) | Res::Def(DefKind::AssocConst, _) => {
570569
// Named constants have to be equated with the value
@@ -1793,8 +1792,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
17931792
}
17941793
}
17951794

1796-
PatKind::Path(_)
1797-
| PatKind::Binding(.., None)
1795+
PatKind::Binding(.., None)
17981796
| PatKind::Lit(..)
17991797
| PatKind::Range(..)
18001798
| PatKind::Never

0 commit comments

Comments
 (0)