Skip to content

Commit

Permalink
deps: apply rustc-ap-* v712 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
calebcartwright committed Apr 3, 2021
1 parent ef57c5b commit 4948911
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 30 deletions.
29 changes: 16 additions & 13 deletions src/expr.rs
Expand Up @@ -106,15 +106,18 @@ pub(crate) fn format_expr(
})
}
ast::ExprKind::Unary(op, ref subexpr) => rewrite_unary_op(context, op, subexpr, shape),
ast::ExprKind::Struct(ref path, ref fields, ref struct_rest) => rewrite_struct_lit(
context,
path,
fields,
struct_rest,
&expr.attrs,
expr.span,
shape,
),
ast::ExprKind::Struct(ref struct_expr) => {
let ast::StructExpr { ref fields, ref path, ref rest } = **struct_expr;
rewrite_struct_lit(
context,
path,
fields,
rest,
&expr.attrs,
expr.span,
shape,
)
}
ast::ExprKind::Tup(ref items) => {
rewrite_tuple(context, items.iter(), expr.span, shape, items.len() == 1)
}
Expand Down Expand Up @@ -1496,14 +1499,14 @@ fn rewrite_index(
}
}

fn struct_lit_can_be_aligned(fields: &[ast::Field], has_base: bool) -> bool {
fn struct_lit_can_be_aligned(fields: &[ast::ExprField], has_base: bool) -> bool {
!has_base && fields.iter().all(|field| !field.is_shorthand)
}

fn rewrite_struct_lit<'a>(
context: &RewriteContext<'_>,
path: &ast::Path,
fields: &'a [ast::Field],
fields: &'a [ast::ExprField],
struct_rest: &ast::StructRest,
attrs: &[ast::Attribute],
span: Span,
Expand All @@ -1512,7 +1515,7 @@ fn rewrite_struct_lit<'a>(
debug!("rewrite_struct_lit: shape {:?}", shape);

enum StructLitField<'a> {
Regular(&'a ast::Field),
Regular(&'a ast::ExprField),
Base(&'a ast::Expr),
Rest(&'a Span),
}
Expand Down Expand Up @@ -1668,7 +1671,7 @@ pub(crate) fn struct_lit_field_separator(config: &Config) -> &str {

pub(crate) fn rewrite_field(
context: &RewriteContext<'_>,
field: &ast::Field,
field: &ast::ExprField,
shape: Shape,
prefix_max_width: usize,
) -> Option<String> {
Expand Down
12 changes: 6 additions & 6 deletions src/items.rs
Expand Up @@ -158,7 +158,7 @@ impl<'a> Item<'a> {
#[derive(Debug)]
enum BodyElement<'a> {
// Stmt(&'a ast::Stmt),
// Field(&'a ast::Field),
// Field(&'a ast::ExprField),
// Variant(&'a ast::Variant),
// Item(&'a ast::Item),
ForeignItem(&'a ast::ForeignItem),
Expand Down Expand Up @@ -1274,7 +1274,7 @@ fn format_unit_struct(
pub(crate) fn format_struct_struct(
context: &RewriteContext<'_>,
struct_parts: &StructParts<'_>,
fields: &[ast::StructField],
fields: &[ast::FieldDef],
offset: Indent,
one_line_width: Option<usize>,
) -> Option<String> {
Expand Down Expand Up @@ -1411,7 +1411,7 @@ fn format_empty_struct_or_tuple(
fn format_tuple_struct(
context: &RewriteContext<'_>,
struct_parts: &StructParts<'_>,
fields: &[ast::StructField],
fields: &[ast::FieldDef],
offset: Indent,
) -> Option<String> {
let mut result = String::with_capacity(1024);
Expand Down Expand Up @@ -1631,7 +1631,7 @@ fn type_annotation_spacing(config: &Config) -> (&str, &str) {

pub(crate) fn rewrite_struct_field_prefix(
context: &RewriteContext<'_>,
field: &ast::StructField,
field: &ast::FieldDef,
) -> Option<String> {
let vis = format_visibility(context, &field.vis);
let type_annotation_spacing = type_annotation_spacing(context.config);
Expand All @@ -1646,15 +1646,15 @@ pub(crate) fn rewrite_struct_field_prefix(
})
}

impl Rewrite for ast::StructField {
impl Rewrite for ast::FieldDef {
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
rewrite_struct_field(context, self, shape, 0)
}
}

pub(crate) fn rewrite_struct_field(
context: &RewriteContext<'_>,
field: &ast::StructField,
field: &ast::FieldDef,
shape: Shape,
lhs_max_width: usize,
) -> Option<String> {
Expand Down
8 changes: 4 additions & 4 deletions src/overflow.rs
Expand Up @@ -74,7 +74,7 @@ pub(crate) enum OverflowableItem<'a> {
MacroArg(&'a MacroArg),
NestedMetaItem(&'a ast::NestedMetaItem),
SegmentParam(&'a SegmentParam<'a>),
StructField(&'a ast::StructField),
FieldDef(&'a ast::FieldDef),
TuplePatField(&'a TuplePatField<'a>),
Ty(&'a ast::Ty),
}
Expand All @@ -96,7 +96,7 @@ impl<'a> OverflowableItem<'a> {
match self {
OverflowableItem::Expr(ast::Expr { attrs, .. })
| OverflowableItem::GenericParam(ast::GenericParam { attrs, .. }) => !attrs.is_empty(),
OverflowableItem::StructField(ast::StructField { attrs, .. }) => !attrs.is_empty(),
OverflowableItem::FieldDef(ast::FieldDef { attrs, .. }) => !attrs.is_empty(),
OverflowableItem::MacroArg(MacroArg::Expr(expr)) => !expr.attrs.is_empty(),
OverflowableItem::MacroArg(MacroArg::Item(item)) => !item.attrs.is_empty(),
_ => false,
Expand All @@ -113,7 +113,7 @@ impl<'a> OverflowableItem<'a> {
OverflowableItem::MacroArg(macro_arg) => f(*macro_arg),
OverflowableItem::NestedMetaItem(nmi) => f(*nmi),
OverflowableItem::SegmentParam(sp) => f(*sp),
OverflowableItem::StructField(sf) => f(*sf),
OverflowableItem::FieldDef(sf) => f(*sf),
OverflowableItem::TuplePatField(pat) => f(*pat),
OverflowableItem::Ty(ty) => f(*ty),
}
Expand Down Expand Up @@ -238,7 +238,7 @@ macro_rules! impl_into_overflowable_item_for_rustfmt_types {
}
}

impl_into_overflowable_item_for_ast_node!(Expr, GenericParam, NestedMetaItem, StructField, Ty);
impl_into_overflowable_item_for_ast_node!(Expr, GenericParam, NestedMetaItem, FieldDef, Ty);
impl_into_overflowable_item_for_rustfmt_types!([MacroArg], [SegmentParam, TuplePatField]);

pub(crate) fn into_overflowable_list<'a, T>(
Expand Down
6 changes: 3 additions & 3 deletions src/patterns.rs
@@ -1,4 +1,4 @@
use rustc_ast::ast::{self, BindingMode, FieldPat, Pat, PatKind, RangeEnd, RangeSyntax};
use rustc_ast::ast::{self, BindingMode, PatField, Pat, PatKind, RangeEnd, RangeSyntax};
use rustc_ast::ptr;
use rustc_span::{BytePos, Span};

Expand Down Expand Up @@ -259,7 +259,7 @@ impl Rewrite for Pat {

fn rewrite_struct_pat(
path: &ast::Path,
fields: &[ast::FieldPat],
fields: &[ast::PatField],
ellipsis: bool,
span: Span,
context: &RewriteContext<'_>,
Expand Down Expand Up @@ -334,7 +334,7 @@ fn rewrite_struct_pat(
Some(format!("{} {{{}}}", path_str, fields_str))
}

impl Rewrite for FieldPat {
impl Rewrite for PatField {
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
let hi_pos = if let Some(last) = self.attrs.last() {
last.span.hi()
Expand Down
4 changes: 2 additions & 2 deletions src/spanned.rs
Expand Up @@ -53,7 +53,7 @@ macro_rules! implement_spanned {
// Implement `Spanned` for structs with `attrs` field.
implement_spanned!(ast::AssocItem);
implement_spanned!(ast::Expr);
implement_spanned!(ast::Field);
implement_spanned!(ast::ExprField);
implement_spanned!(ast::ForeignItem);
implement_spanned!(ast::Item);
implement_spanned!(ast::Local);
Expand Down Expand Up @@ -143,7 +143,7 @@ impl Spanned for ast::GenericParam {
}
}

impl Spanned for ast::StructField {
impl Spanned for ast::FieldDef {
fn span(&self) -> Span {
span_with_attrs_lo_hi!(self, self.span.lo(), self.ty.span.hi())
}
Expand Down
4 changes: 2 additions & 2 deletions src/vertical.rs
Expand Up @@ -33,7 +33,7 @@ pub(crate) trait AlignedItem {
) -> Option<String>;
}

impl AlignedItem for ast::StructField {
impl AlignedItem for ast::FieldDef {
fn skip(&self) -> bool {
contains_skip(&self.attrs)
}
Expand Down Expand Up @@ -72,7 +72,7 @@ impl AlignedItem for ast::StructField {
}
}

impl AlignedItem for ast::Field {
impl AlignedItem for ast::ExprField {
fn skip(&self) -> bool {
contains_skip(&self.attrs)
}
Expand Down

0 comments on commit 4948911

Please sign in to comment.