Skip to content

Commit d9df9c5

Browse files
committed
Auto merge of #120525 - klensy:FieldDef-span, r=<try>
rustc_ast: FieldDef: remove span it can be calculated from Visibility + Ty, at least tests passed? perf me, please
2 parents cdaa12e + bf5d6ae commit d9df9c5

File tree

17 files changed

+41
-46
lines changed

17 files changed

+41
-46
lines changed

‎compiler/rustc_ast/src/ast.rs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2794,14 +2794,19 @@ impl VisibilityKind {
27942794
pub struct FieldDef {
27952795
pub attrs: AttrVec,
27962796
pub id: NodeId,
2797-
pub span: Span,
27982797
pub vis: Visibility,
27992798
pub ident: Option<Ident>,
28002799

28012800
pub ty: P<Ty>,
28022801
pub is_placeholder: bool,
28032802
}
28042803

2804+
impl FieldDef {
2805+
pub fn span(&self) -> Span {
2806+
self.vis.span.to(self.ty.span)
2807+
}
2808+
}
2809+
28052810
/// Fields and constructor ids of enum variants and structs.
28062811
#[derive(Clone, Encodable, Decodable, Debug)]
28072812
pub enum VariantData {

‎compiler/rustc_ast/src/mut_visit.rs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,8 +1003,7 @@ pub fn noop_flat_map_field_def<T: MutVisitor>(
10031003
mut fd: FieldDef,
10041004
visitor: &mut T,
10051005
) -> SmallVec<[FieldDef; 1]> {
1006-
let FieldDef { span, ident, vis, id, ty, attrs, is_placeholder: _ } = &mut fd;
1007-
visitor.visit_span(span);
1006+
let FieldDef { ident, vis, id, ty, attrs, is_placeholder: _ } = &mut fd;
10081007
visit_opt(ident, |ident| visitor.visit_ident(ident));
10091008
visitor.visit_vis(vis);
10101009
visitor.visit_id(id);

‎compiler/rustc_ast_lowering/src/item.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -722,13 +722,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
722722
let hir_id = self.lower_node_id(f.id);
723723
self.lower_attrs(hir_id, &f.attrs);
724724
hir::FieldDef {
725-
span: self.lower_span(f.span),
725+
span: self.lower_span(f.span()),
726726
hir_id,
727727
def_id: self.local_def_id(f.id),
728728
ident: match f.ident {
729729
Some(ident) => self.lower_ident(ident),
730730
// FIXME(jseyfried): positional field hygiene.
731-
None => Ident::new(sym::integer(index), self.lower_span(f.span)),
731+
None => Ident::new(sym::integer(index), self.lower_span(f.span())),
732732
},
733733
vis_span: self.lower_span(f.vis.span),
734734
ty,

‎compiler/rustc_ast_passes/src/ast_validation.rs‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,10 @@ impl<'a> AstValidator<'a> {
306306
if let Some(ident) = field.ident
307307
&& ident.name == kw::Underscore
308308
{
309-
self.dcx()
310-
.emit_err(errors::InvalidUnnamedField { span: field.span, ident_span: ident.span });
309+
self.dcx().emit_err(errors::InvalidUnnamedField {
310+
span: field.span(),
311+
ident_span: ident.span,
312+
});
311313
}
312314
}
313315

‎compiler/rustc_ast_pretty/src/pprust/state/item.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ impl<'a> State<'a> {
450450

451451
for field in fields {
452452
self.hardbreak_if_not_bol();
453-
self.maybe_print_comment(field.span.lo());
453+
self.maybe_print_comment(field.span().lo());
454454
self.print_outer_attributes(&field.attrs);
455455
self.print_visibility(&field.vis);
456456
self.print_ident(field.ident.unwrap());
@@ -478,7 +478,7 @@ impl<'a> State<'a> {
478478
if let ast::VariantData::Tuple(..) = struct_def {
479479
self.popen();
480480
self.commasep(Inconsistent, struct_def.fields(), |s, field| {
481-
s.maybe_print_comment(field.span.lo());
481+
s.maybe_print_comment(field.span().lo());
482482
s.print_outer_attributes(&field.attrs);
483483
s.print_visibility(&field.vis);
484484
s.print_type(&field.ty)

‎compiler/rustc_builtin_macros/src/deriving/clone.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ fn cs_clone_simple(
116116
cx,
117117
&mut stmts,
118118
field.ty.clone(),
119-
field.span,
119+
field.span(),
120120
&[sym::clone, sym::AssertParamIsClone],
121121
);
122122
}

‎compiler/rustc_builtin_macros/src/deriving/cmp/eq.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ fn cs_total_eq_assert(
7070
cx,
7171
&mut stmts,
7272
field.ty.clone(),
73-
field.span,
73+
field.span(),
7474
&[sym::cmp, sym::AssertParamIsEq],
7575
);
7676
}

‎compiler/rustc_builtin_macros/src/deriving/generic/mod.rs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,7 +1432,7 @@ impl<'a> TraitDef<'a> {
14321432
let mut named_idents = Vec::new();
14331433
let mut just_spans = Vec::new();
14341434
for field in struct_def.fields() {
1435-
let sp = field.span.with_ctxt(self.span.ctxt());
1435+
let sp = field.span().with_ctxt(self.span.ctxt());
14361436
match field.ident {
14371437
Some(ident) => named_idents.push((ident, sp)),
14381438
_ => just_spans.push(sp),
@@ -1466,7 +1466,7 @@ impl<'a> TraitDef<'a> {
14661466
.map(|prefix| {
14671467
let pieces_iter =
14681468
struct_def.fields().iter().enumerate().map(|(i, struct_field)| {
1469-
let sp = struct_field.span.with_ctxt(self.span.ctxt());
1469+
let sp = struct_field.span().with_ctxt(self.span.ctxt());
14701470
let ident = self.mk_pattern_ident(prefix, i);
14711471
let path = ident.with_span_pos(sp);
14721472
(
@@ -1528,7 +1528,7 @@ impl<'a> TraitDef<'a> {
15281528
.map(|(i, struct_field)| {
15291529
// For this field, get an expr for each selflike_arg. E.g. for
15301530
// `PartialEq::eq`, one for each of `&self` and `other`.
1531-
let sp = struct_field.span.with_ctxt(self.span.ctxt());
1531+
let sp = struct_field.span().with_ctxt(self.span.ctxt());
15321532
let mut exprs: Vec<_> = mk_exprs(i, struct_field, sp);
15331533
let self_expr = exprs.remove(0);
15341534
let other_selflike_exprs = exprs;
@@ -1583,7 +1583,7 @@ impl<'a> TraitDef<'a> {
15831583
ast::ExprKind::Field(
15841584
selflike_arg.clone(),
15851585
struct_field.ident.unwrap_or_else(|| {
1586-
Ident::from_str_and_span(&i.to_string(), struct_field.span)
1586+
Ident::from_str_and_span(&i.to_string(), struct_field.span())
15871587
}),
15881588
),
15891589
);
@@ -1631,7 +1631,7 @@ impl<'a> TraitDef<'a> {
16311631
} else {
16321632
// Wrap the expression in `{...}`, causing a copy.
16331633
field_expr = cx.expr_block(
1634-
cx.block(struct_field.span, thin_vec![cx.stmt_expr(field_expr)]),
1634+
cx.block(struct_field.span(), thin_vec![cx.stmt_expr(field_expr)]),
16351635
);
16361636
}
16371637
}

‎compiler/rustc_expand/src/base.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl Annotatable {
7373
Annotatable::PatField(fp) => fp.pat.span,
7474
Annotatable::GenericParam(gp) => gp.ident.span,
7575
Annotatable::Param(p) => p.span,
76-
Annotatable::FieldDef(sf) => sf.span,
76+
Annotatable::FieldDef(sf) => sf.span(),
7777
Annotatable::Variant(v) => v.span,
7878
Annotatable::Crate(c) => c.spans.inner_span,
7979
}

‎compiler/rustc_expand/src/placeholders.rs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ pub fn placeholder(
167167
attrs: Default::default(),
168168
id,
169169
ident: None,
170-
span,
171170
ty: ty(),
172171
vis,
173172
is_placeholder: true,

0 commit comments

Comments
 (0)