Skip to content

Commit 2a6b3b6

Browse files
Rollup merge of rust-lang#145783 - Erk-:et-cetera-span, r=compiler-errors
add span to struct pattern rest (..) Struct pattern rest (`..`) did not retain span information compared to normal fields. This patch adds span information for it. The motivation of this patch comes from when I implemented this PR for Clippy: rust-lang/rust-clippy#15000 (comment) It is possible to get the span of the Et cetera in a bit roundabout way, but I thought this would be nicer.
2 parents 951e64f + 01fefaa commit 2a6b3b6

File tree

5 files changed

+7
-6
lines changed

5 files changed

+7
-6
lines changed

clippy_lints/src/equatable_if_let.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ fn unary_pattern(pat: &Pat<'_>) -> bool {
5353
| PatKind::Never
5454
| PatKind::Or(_)
5555
| PatKind::Err(_) => false,
56-
PatKind::Struct(_, a, etc) => !etc && a.iter().all(|x| unary_pattern(x.pat)),
56+
PatKind::Struct(_, a, etc) => etc.is_none() && 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),
5959
PatKind::Expr(_) => true,

clippy_lints/src/manual_let_else.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ fn replace_in_pattern(
287287
}
288288
return or_pat;
289289
},
290-
PatKind::Struct(path, fields, has_dot_dot) => {
290+
PatKind::Struct(path, fields, dot_dot) => {
291291
let fields = fields
292292
.iter()
293293
.map(|fld| {
@@ -311,7 +311,7 @@ fn replace_in_pattern(
311311
.collect::<Vec<_>>();
312312
let fields_string = fields.join(", ");
313313

314-
let dot_dot_str = if has_dot_dot { " .." } else { "" };
314+
let dot_dot_str = if dot_dot.is_some() { " .." } else { "" };
315315
let (sn_pth, _) = snippet_with_context(cx, path.span(), span.ctxt(), "", app);
316316
return format!("{sn_pth} {{ {fields_string}{dot_dot_str} }}");
317317
},

clippy_lints/src/matches/rest_pat_in_fully_bound_struct.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use super::REST_PAT_IN_FULLY_BOUND_STRUCTS;
77

88
pub(crate) fn check(cx: &LateContext<'_>, pat: &Pat<'_>) {
99
if !pat.span.from_expansion()
10-
&& let PatKind::Struct(QPath::Resolved(_, path), fields, true) = pat.kind
10+
&& let PatKind::Struct(QPath::Resolved(_, path), fields, Some(_)) = pat.kind
1111
&& let Some(def_id) = path.res.opt_def_id()
1212
&& let ty = cx.tcx.type_of(def_id).instantiate_identity()
1313
&& let ty::Adt(def, _) = ty.kind()

clippy_lints/src/utils/author.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,8 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
754754
self.ident(name);
755755
sub.if_some(|p| self.pat(p));
756756
},
757-
PatKind::Struct(ref qpath, fields, ignore) => {
757+
PatKind::Struct(ref qpath, fields, etc) => {
758+
let ignore = etc.is_some();
758759
bind!(self, qpath, fields);
759760
kind!("Struct(ref {qpath}, {fields}, {ignore})");
760761
self.qpath(qpath, pat);

clippy_utils/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2011,7 +2011,7 @@ pub fn is_expr_identity_of_pat(cx: &LateContext<'_>, pat: &Pat<'_>, expr: &Expr<
20112011
false
20122012
}
20132013
},
2014-
(PatKind::Struct(pat_ident, field_pats, false), ExprKind::Struct(ident, fields, hir::StructTailExpr::None))
2014+
(PatKind::Struct(pat_ident, field_pats, None), ExprKind::Struct(ident, fields, hir::StructTailExpr::None))
20152015
if field_pats.len() == fields.len() =>
20162016
{
20172017
// check ident

0 commit comments

Comments
 (0)