Skip to content

Commit bb08434

Browse files
Auto merge of #145783 - Erk-:et-cetera-span, r=<try>
add span to struct pattern rest (..)
2 parents 6d6a08c + 82c472a commit bb08434

File tree

17 files changed

+40
-30
lines changed

17 files changed

+40
-30
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ pub enum PatKind {
937937
#[derive(Clone, Copy, Encodable, Decodable, Debug, PartialEq, Walkable)]
938938
pub enum PatFieldsRest {
939939
/// `module::StructName { field, ..}`
940-
Rest,
940+
Rest(Span),
941941
/// `module::StructName { field, syntax error }`
942942
Recovered(ErrorGuaranteed),
943943
/// `module::StructName { field }`
@@ -4051,8 +4051,8 @@ mod size_asserts {
40514051
static_assert_size!(Local, 96);
40524052
static_assert_size!(MetaItemLit, 40);
40534053
static_assert_size!(Param, 40);
4054-
static_assert_size!(Pat, 72);
4055-
static_assert_size!(PatKind, 48);
4054+
static_assert_size!(Pat, 80);
4055+
static_assert_size!(PatKind, 56);
40564056
static_assert_size!(Path, 24);
40574057
static_assert_size!(PathSegment, 24);
40584058
static_assert_size!(Stmt, 32);

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,10 +1434,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
14341434
self.dcx().emit_err(FunctionalRecordUpdateDestructuringAssignment {
14351435
span: e.span,
14361436
});
1437-
true
1437+
Some(e.span)
14381438
}
1439-
StructRest::Rest(_) => true,
1440-
StructRest::None => false,
1439+
StructRest::Rest(span) => Some(*span),
1440+
StructRest::None => None,
14411441
};
14421442
let struct_pat = hir::PatKind::Struct(qpath, field_pats, fields_omitted);
14431443
return self.pat_without_dbm(lhs.span, struct_pat);

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2508,7 +2508,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
25082508
fields: &'hir [hir::PatField<'hir>],
25092509
) -> &'hir hir::Pat<'hir> {
25102510
let qpath = hir::QPath::LangItem(lang_item, self.lower_span(span));
2511-
self.pat(span, hir::PatKind::Struct(qpath, fields, false))
2511+
self.pat(span, hir::PatKind::Struct(qpath, fields, None))
25122512
}
25132513

25142514
fn pat_ident(&mut self, span: Span, ident: Ident) -> (&'hir hir::Pat<'hir>, HirId) {

compiler/rustc_ast_lowering/src/pat.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
106106
break hir::PatKind::Struct(
107107
qpath,
108108
fs,
109-
matches!(
110-
etc,
111-
ast::PatFieldsRest::Rest | ast::PatFieldsRest::Recovered(_)
112-
),
109+
match etc {
110+
ast::PatFieldsRest::Rest(sp) => Some(*sp),
111+
ast::PatFieldsRest::Recovered(_) => Some(Span::default()),
112+
_ => None,
113+
},
113114
);
114115
}
115116
PatKind::Tuple(pats) => {

compiler/rustc_ast_pretty/src/pprust/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1769,7 +1769,7 @@ impl<'a> State<'a> {
17691769
},
17701770
|f| f.pat.span,
17711771
);
1772-
if let ast::PatFieldsRest::Rest | ast::PatFieldsRest::Recovered(_) = etc {
1772+
if let ast::PatFieldsRest::Rest(_) | ast::PatFieldsRest::Recovered(_) = etc {
17731773
if !fields.is_empty() {
17741774
self.word_space(",");
17751775
}

compiler/rustc_hir/src/hir.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1884,8 +1884,8 @@ pub enum PatKind<'hir> {
18841884
Binding(BindingMode, HirId, Ident, Option<&'hir Pat<'hir>>),
18851885

18861886
/// A struct or struct variant pattern (e.g., `Variant {x, y, ..}`).
1887-
/// The `bool` is `true` in the presence of a `..`.
1888-
Struct(QPath<'hir>, &'hir [PatField<'hir>], bool),
1887+
/// The `Option` contains the span a possible `..`.
1888+
Struct(QPath<'hir>, &'hir [PatField<'hir>], Option<Span>),
18891889

18901890
/// A tuple struct/variant pattern `Variant(x, y, .., z)`.
18911891
/// If the `..` pattern fragment is present, then `DotDotPos` denotes its position.
@@ -4979,8 +4979,8 @@ mod size_asserts {
49794979
static_assert_size!(ItemKind<'_>, 64);
49804980
static_assert_size!(LetStmt<'_>, 72);
49814981
static_assert_size!(Param<'_>, 32);
4982-
static_assert_size!(Pat<'_>, 72);
4983-
static_assert_size!(PatKind<'_>, 48);
4982+
static_assert_size!(Pat<'_>, 80);
4983+
static_assert_size!(PatKind<'_>, 56);
49844984
static_assert_size!(Path<'_>, 40);
49854985
static_assert_size!(PathSegment<'_>, 48);
49864986
static_assert_size!(QPath<'_>, 24);

compiler/rustc_hir_pretty/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1958,12 +1958,12 @@ impl<'a> State<'a> {
19581958
self.print_qpath(qpath, true);
19591959
self.nbsp();
19601960
self.word("{");
1961-
let empty = fields.is_empty() && !etc;
1961+
let empty = fields.is_empty() && etc.is_none();
19621962
if !empty {
19631963
self.space();
19641964
}
19651965
self.commasep_cmnt(Consistent, fields, |s, f| s.print_patfield(f), |f| f.pat.span);
1966-
if etc {
1966+
if etc.is_some() {
19671967
if !fields.is_empty() {
19681968
self.word_space(",");
19691969
}

compiler/rustc_hir_typeck/src/pat.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
605605
},
606606
PatKind::Struct(_, fields, has_rest_pat) => match opt_path_res.unwrap() {
607607
Ok(ResolvedPat { ty, kind: ResolvedPatKind::Struct { variant } }) => self
608-
.check_pat_struct(pat, fields, has_rest_pat, ty, variant, expected, pat_info),
608+
.check_pat_struct(
609+
pat,
610+
fields,
611+
has_rest_pat.is_some(),
612+
ty,
613+
variant,
614+
expected,
615+
pat_info,
616+
),
609617
Err(guar) => {
610618
let ty_err = Ty::new_error(self.tcx, guar);
611619
for field in fields {
@@ -2428,7 +2436,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
24282436
let len = unmentioned_fields.len();
24292437
let (prefix, postfix, sp) = match fields {
24302438
[] => match &pat.kind {
2431-
PatKind::Struct(path, [], false) => {
2439+
PatKind::Struct(path, [], None) => {
24322440
(" { ", " }", path.span().shrink_to_hi().until(pat.span.shrink_to_hi()))
24332441
}
24342442
_ => return err,

compiler/rustc_parse/src/parser/pat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1516,7 +1516,7 @@ impl<'a> Parser<'a> {
15161516
|| self.check_noexpect(&token::DotDotDot)
15171517
|| self.check_keyword(exp!(Underscore))
15181518
{
1519-
etc = PatFieldsRest::Rest;
1519+
etc = PatFieldsRest::Rest(self.token.span);
15201520
let mut etc_sp = self.token.span;
15211521
if first_etc_and_maybe_comma_span.is_none() {
15221522
if let Some(comma_tok) =

compiler/rustc_passes/src/liveness.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1583,7 +1583,7 @@ impl<'tcx> Liveness<'_, 'tcx> {
15831583
});
15841584

15851585
let can_remove = match pat.kind {
1586-
hir::PatKind::Struct(_, fields, true) => {
1586+
hir::PatKind::Struct(_, fields, Some(_)) => {
15871587
// if all fields are shorthand, remove the struct field, otherwise, mark with _ as prefix
15881588
fields.iter().all(|f| f.is_shorthand)
15891589
}

0 commit comments

Comments
 (0)