Skip to content

Commit ea199ba

Browse files
Merge pull request #5070 from calebcartwright/rustup-2021-11-s1
subtree sync
2 parents e4472d3 + 31bc54a commit ea199ba

File tree

3 files changed

+71
-58
lines changed

3 files changed

+71
-58
lines changed

rust-toolchain

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly-2021-10-20"
2+
channel = "nightly-2021-11-08"
33
components = ["rustc-dev"]

src/items.rs

+47-32
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ impl<'a> FmtVisitor<'a> {
622622
fn need_empty_line(a: &ast::AssocItemKind, b: &ast::AssocItemKind) -> bool {
623623
match (a, b) {
624624
(TyAlias(lty), TyAlias(rty))
625-
if both_type(&lty.3, &rty.3) || both_opaque(&lty.3, &rty.3) =>
625+
if both_type(&lty.ty, &rty.ty) || both_opaque(&lty.ty, &rty.ty) =>
626626
{
627627
false
628628
}
@@ -633,16 +633,16 @@ impl<'a> FmtVisitor<'a> {
633633

634634
buffer.sort_by(|(_, a), (_, b)| match (&a.kind, &b.kind) {
635635
(TyAlias(lty), TyAlias(rty))
636-
if both_type(&lty.3, &rty.3) || both_opaque(&lty.3, &rty.3) =>
636+
if both_type(&lty.ty, &rty.ty) || both_opaque(&lty.ty, &rty.ty) =>
637637
{
638638
a.ident.as_str().cmp(&b.ident.as_str())
639639
}
640640
(Const(..), Const(..)) | (MacCall(..), MacCall(..)) => {
641641
a.ident.as_str().cmp(&b.ident.as_str())
642642
}
643643
(Fn(..), Fn(..)) => a.span.lo().cmp(&b.span.lo()),
644-
(TyAlias(ty), _) if is_type(&ty.3) => Ordering::Less,
645-
(_, TyAlias(ty)) if is_type(&ty.3) => Ordering::Greater,
644+
(TyAlias(ty), _) if is_type(&ty.ty) => Ordering::Less,
645+
(_, TyAlias(ty)) if is_type(&ty.ty) => Ordering::Greater,
646646
(TyAlias(..), _) => Ordering::Less,
647647
(_, TyAlias(..)) => Ordering::Greater,
648648
(Const(..), _) => Ordering::Less,
@@ -679,7 +679,7 @@ pub(crate) fn format_impl(
679679
offset: Indent,
680680
) -> Option<String> {
681681
if let ast::ItemKind::Impl(impl_kind) = &item.kind {
682-
let ast::ImplKind {
682+
let ast::Impl {
683683
ref generics,
684684
ref self_ty,
685685
ref items,
@@ -833,7 +833,7 @@ fn format_impl_ref_and_type(
833833
offset: Indent,
834834
) -> Option<String> {
835835
if let ast::ItemKind::Impl(impl_kind) = &item.kind {
836-
let ast::ImplKind {
836+
let ast::Impl {
837837
unsafety,
838838
polarity,
839839
defaultness,
@@ -1029,8 +1029,13 @@ pub(crate) fn format_trait(
10291029
offset: Indent,
10301030
) -> Option<String> {
10311031
if let ast::ItemKind::Trait(trait_kind) = &item.kind {
1032-
let ast::TraitKind(is_auto, unsafety, ref generics, ref generic_bounds, ref trait_items) =
1033-
**trait_kind;
1032+
let ast::Trait {
1033+
is_auto,
1034+
unsafety,
1035+
ref generics,
1036+
ref bounds,
1037+
ref items,
1038+
} = **trait_kind;
10341039
let mut result = String::with_capacity(128);
10351040
let header = format!(
10361041
"{}{}{}trait ",
@@ -1048,11 +1053,11 @@ pub(crate) fn format_trait(
10481053
result.push_str(&generics_str);
10491054

10501055
// FIXME(#2055): rustfmt fails to format when there are comments between trait bounds.
1051-
if !generic_bounds.is_empty() {
1056+
if !bounds.is_empty() {
10521057
let ident_hi = context
10531058
.snippet_provider
10541059
.span_after(item.span, &item.ident.as_str());
1055-
let bound_hi = generic_bounds.last().unwrap().span().hi();
1060+
let bound_hi = bounds.last().unwrap().span().hi();
10561061
let snippet = context.snippet(mk_sp(ident_hi, bound_hi));
10571062
if contains_comment(snippet) {
10581063
return None;
@@ -1061,7 +1066,7 @@ pub(crate) fn format_trait(
10611066
result = rewrite_assign_rhs_with(
10621067
context,
10631068
result + ":",
1064-
generic_bounds,
1069+
bounds,
10651070
shape,
10661071
RhsTactics::ForceNextLineWithoutIndent,
10671072
)?;
@@ -1072,10 +1077,10 @@ pub(crate) fn format_trait(
10721077
let where_on_new_line = context.config.indent_style() != IndentStyle::Block;
10731078

10741079
let where_budget = context.budget(last_line_width(&result));
1075-
let pos_before_where = if generic_bounds.is_empty() {
1080+
let pos_before_where = if bounds.is_empty() {
10761081
generics.where_clause.span.lo()
10771082
} else {
1078-
generic_bounds[generic_bounds.len() - 1].span().hi()
1083+
bounds[bounds.len() - 1].span().hi()
10791084
};
10801085
let option = WhereClauseOption::snuggled(&generics_str);
10811086
let where_clause_str = rewrite_where_clause(
@@ -1133,7 +1138,7 @@ pub(crate) fn format_trait(
11331138
result.push_str(&offset.to_string_with_newline(context.config));
11341139
}
11351140
_ if context.config.empty_item_single_line()
1136-
&& trait_items.is_empty()
1141+
&& items.is_empty()
11371142
&& !result.contains('\n')
11381143
&& !contains_comment(&snippet[open_pos..]) =>
11391144
{
@@ -1146,7 +1151,7 @@ pub(crate) fn format_trait(
11461151
BraceStyle::PreferSameLine => result.push(' '),
11471152
BraceStyle::SameLineWhere => {
11481153
if result.contains('\n')
1149-
|| (!generics.where_clause.predicates.is_empty() && !trait_items.is_empty())
1154+
|| (!generics.where_clause.predicates.is_empty() && !items.is_empty())
11501155
{
11511156
result.push_str(&offset.to_string_with_newline(context.config));
11521157
} else {
@@ -1158,12 +1163,12 @@ pub(crate) fn format_trait(
11581163

11591164
let outer_indent_str = offset.block_only().to_string_with_newline(context.config);
11601165

1161-
if !trait_items.is_empty() || contains_comment(&snippet[open_pos..]) {
1166+
if !items.is_empty() || contains_comment(&snippet[open_pos..]) {
11621167
let mut visitor = FmtVisitor::from_context(context);
11631168
visitor.block_indent = offset.block_only().block_indent(context.config);
11641169
visitor.last_pos = block_span.lo() + BytePos(open_pos as u32);
11651170

1166-
for item in trait_items {
1171+
for item in items {
11671172
visitor.visit_trait_item(item);
11681173
}
11691174

@@ -1522,15 +1527,20 @@ struct TyAliasRewriteInfo<'c, 'g>(
15221527
);
15231528

15241529
pub(crate) fn rewrite_type_alias<'a, 'b>(
1525-
ty_alias_kind: &ast::TyAliasKind,
1530+
ty_alias_kind: &ast::TyAlias,
15261531
context: &RewriteContext<'a>,
15271532
indent: Indent,
15281533
visitor_kind: &ItemVisitorKind<'b>,
15291534
span: Span,
15301535
) -> Option<String> {
15311536
use ItemVisitorKind::*;
15321537

1533-
let ast::TyAliasKind(defaultness, ref generics, ref generic_bounds, ref ty) = *ty_alias_kind;
1538+
let ast::TyAlias {
1539+
defaultness,
1540+
ref generics,
1541+
ref bounds,
1542+
ref ty,
1543+
} = *ty_alias_kind;
15341544
let ty_opt = ty.as_ref().map(|t| &**t);
15351545
let (ident, vis) = match visitor_kind {
15361546
Item(i) => (i.ident, &i.vis),
@@ -1545,17 +1555,17 @@ pub(crate) fn rewrite_type_alias<'a, 'b>(
15451555
// https://github.com/rust-dev-tools/fmt-rfcs/blob/master/guide/items.md#type-aliases
15461556
match (visitor_kind, ty_opt) {
15471557
(Item(_), None) => {
1548-
let op_ty = OpaqueType { generic_bounds };
1549-
rewrite_ty(rw_info, Some(generic_bounds), Some(&op_ty), vis)
1558+
let op_ty = OpaqueType { bounds };
1559+
rewrite_ty(rw_info, Some(bounds), Some(&op_ty), vis)
15501560
}
1551-
(Item(_), Some(ty)) => rewrite_ty(rw_info, Some(generic_bounds), Some(&*ty), vis),
1561+
(Item(_), Some(ty)) => rewrite_ty(rw_info, Some(bounds), Some(&*ty), vis),
15521562
(AssocImplItem(_), _) => {
15531563
let result = if let Some(ast::Ty {
1554-
kind: ast::TyKind::ImplTrait(_, ref generic_bounds),
1564+
kind: ast::TyKind::ImplTrait(_, ref bounds),
15551565
..
15561566
}) = ty_opt
15571567
{
1558-
let op_ty = OpaqueType { generic_bounds };
1568+
let op_ty = OpaqueType { bounds };
15591569
rewrite_ty(rw_info, None, Some(&op_ty), &DEFAULT_VISIBILITY)
15601570
} else {
15611571
rewrite_ty(rw_info, None, ty.as_ref(), vis)
@@ -1566,7 +1576,7 @@ pub(crate) fn rewrite_type_alias<'a, 'b>(
15661576
}
15671577
}
15681578
(AssocTraitItem(_), _) | (ForeignItem(_), _) => {
1569-
rewrite_ty(rw_info, Some(generic_bounds), ty.as_ref(), vis)
1579+
rewrite_ty(rw_info, Some(bounds), ty.as_ref(), vis)
15701580
}
15711581
}
15721582
}
@@ -1891,13 +1901,13 @@ fn rewrite_static(
18911901
}
18921902
}
18931903
struct OpaqueType<'a> {
1894-
generic_bounds: &'a ast::GenericBounds,
1904+
bounds: &'a ast::GenericBounds,
18951905
}
18961906

18971907
impl<'a> Rewrite for OpaqueType<'a> {
18981908
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
18991909
let shape = shape.offset_left(5)?; // `impl `
1900-
self.generic_bounds
1910+
self.bounds
19011911
.rewrite(context, shape)
19021912
.map(|s| format!("impl {}", s))
19031913
}
@@ -3126,17 +3136,22 @@ impl Rewrite for ast::ForeignItem {
31263136

31273137
let item_str = match self.kind {
31283138
ast::ForeignItemKind::Fn(ref fn_kind) => {
3129-
let ast::FnKind(defaultness, ref fn_sig, ref generics, ref block) = **fn_kind;
3130-
if let Some(ref body) = block {
3139+
let ast::Fn {
3140+
defaultness,
3141+
ref sig,
3142+
ref generics,
3143+
ref body,
3144+
} = **fn_kind;
3145+
if let Some(ref body) = body {
31313146
let mut visitor = FmtVisitor::from_context(context);
31323147
visitor.block_indent = shape.indent;
31333148
visitor.last_pos = self.span.lo();
31343149
let inner_attrs = inner_attributes(&self.attrs);
31353150
let fn_ctxt = visit::FnCtxt::Foreign;
31363151
visitor.visit_fn(
3137-
visit::FnKind::Fn(fn_ctxt, self.ident, fn_sig, &self.vis, Some(body)),
3152+
visit::FnKind::Fn(fn_ctxt, self.ident, &sig, &self.vis, Some(body)),
31383153
generics,
3139-
&fn_sig.decl,
3154+
&sig.decl,
31403155
self.span,
31413156
defaultness,
31423157
Some(&inner_attrs),
@@ -3147,7 +3162,7 @@ impl Rewrite for ast::ForeignItem {
31473162
context,
31483163
shape.indent,
31493164
self.ident,
3150-
&FnSig::from_method_sig(fn_sig, generics, &self.vis),
3165+
&FnSig::from_method_sig(&sig, generics, &self.vis),
31513166
span,
31523167
FnBraceStyle::None,
31533168
)

src/visitor.rs

+23-25
Original file line numberDiff line numberDiff line change
@@ -539,44 +539,37 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
539539
self.visit_static(&StaticParts::from_item(item));
540540
}
541541
ast::ItemKind::Fn(ref fn_kind) => {
542-
let ast::FnKind(defaultness, ref fn_signature, ref generics, ref block) =
543-
**fn_kind;
544-
if let Some(ref body) = block {
542+
let ast::Fn {
543+
defaultness,
544+
ref sig,
545+
ref generics,
546+
ref body,
547+
} = **fn_kind;
548+
if let Some(ref body) = body {
545549
let inner_attrs = inner_attributes(&item.attrs);
546-
let fn_ctxt = match fn_signature.header.ext {
550+
let fn_ctxt = match sig.header.ext {
547551
ast::Extern::None => visit::FnCtxt::Free,
548552
_ => visit::FnCtxt::Foreign,
549553
};
550554
self.visit_fn(
551-
visit::FnKind::Fn(
552-
fn_ctxt,
553-
item.ident,
554-
fn_signature,
555-
&item.vis,
556-
Some(body),
557-
),
555+
visit::FnKind::Fn(fn_ctxt, item.ident, &sig, &item.vis, Some(body)),
558556
generics,
559-
&fn_signature.decl,
557+
&sig.decl,
560558
item.span,
561559
defaultness,
562560
Some(&inner_attrs),
563561
)
564562
} else {
565563
let indent = self.block_indent;
566564
let rewrite = self.rewrite_required_fn(
567-
indent,
568-
item.ident,
569-
fn_signature,
570-
&item.vis,
571-
generics,
572-
item.span,
565+
indent, item.ident, &sig, &item.vis, generics, item.span,
573566
);
574567
self.push_rewrite(item.span, rewrite);
575568
}
576569
}
577-
ast::ItemKind::TyAlias(ref alias_kind) => {
570+
ast::ItemKind::TyAlias(ref ty_alias) => {
578571
use ItemVisitorKind::Item;
579-
self.visit_ty_alias_kind(alias_kind, &Item(&item), item.span);
572+
self.visit_ty_alias_kind(ty_alias, &Item(&item), item.span);
580573
}
581574
ast::ItemKind::GlobalAsm(..) => {
582575
let snippet = Some(self.snippet(item.span).to_owned());
@@ -601,7 +594,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
601594

602595
fn visit_ty_alias_kind(
603596
&mut self,
604-
ty_kind: &ast::TyAliasKind,
597+
ty_kind: &ast::TyAlias,
605598
visitor_kind: &ItemVisitorKind<'_>,
606599
span: Span,
607600
) {
@@ -639,8 +632,13 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
639632
self.visit_static(&StaticParts::from_impl_item(&ai))
640633
}
641634
(ast::AssocItemKind::Fn(ref fn_kind), _) => {
642-
let ast::FnKind(defaultness, ref sig, ref generics, ref block) = **fn_kind;
643-
if let Some(ref body) = block {
635+
let ast::Fn {
636+
defaultness,
637+
ref sig,
638+
ref generics,
639+
ref body,
640+
} = **fn_kind;
641+
if let Some(ref body) = body {
644642
let inner_attrs = inner_attributes(&ai.attrs);
645643
let fn_ctxt = visit::FnCtxt::Assoc(assoc_ctxt);
646644
self.visit_fn(
@@ -658,8 +656,8 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
658656
self.push_rewrite(ai.span, rewrite);
659657
}
660658
}
661-
(ast::AssocItemKind::TyAlias(ref ty_alias_kind), _) => {
662-
self.visit_ty_alias_kind(ty_alias_kind, visitor_kind, ai.span);
659+
(ast::AssocItemKind::TyAlias(ref ty_alias), _) => {
660+
self.visit_ty_alias_kind(ty_alias, visitor_kind, ai.span);
663661
}
664662
(ast::AssocItemKind::MacCall(ref mac), _) => {
665663
self.visit_mac(mac, Some(ai.ident), MacroPosition::Item);

0 commit comments

Comments
 (0)