Skip to content

Commit 59d8609

Browse files
authored
Rollup merge of #154454 - ytmimi:rustfmt_issue_6513, r=jieyouxu
fix: [rustfmt] prevent panic when rewritng associated item delegations Tracking issue: #118212 rustfmt issue: rust-lang/rustfmt#6513 Fixes a rustfmt bug for `#![feature(fn_delegation)]`
2 parents 0ddeea3 + a53356e commit 59d8609

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

‎src/tools/rustfmt/src/visitor.rs‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -665,11 +665,11 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
665665
}
666666

667667
// TODO(calebcartwright): consider enabling box_patterns feature gate
668-
match (&ai.kind, visitor_kind) {
669-
(ast::AssocItemKind::Const(c), AssocTraitItem) => {
668+
match (&ai.kind, assoc_ctxt) {
669+
(ast::AssocItemKind::Const(c), visit::AssocCtxt::Trait) => {
670670
self.visit_static(&StaticParts::from_trait_item(ai, c.ident))
671671
}
672-
(ast::AssocItemKind::Const(c), AssocImplItem) => {
672+
(ast::AssocItemKind::Const(c), visit::AssocCtxt::Impl { .. }) => {
673673
self.visit_static(&StaticParts::from_impl_item(ai, c.ident))
674674
}
675675
(ast::AssocItemKind::Fn(ref fn_kind), _) => {
@@ -714,7 +714,11 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
714714
(ast::AssocItemKind::MacCall(ref mac), _) => {
715715
self.visit_mac(mac, MacroPosition::Item);
716716
}
717-
_ => unreachable!(),
717+
(ast::AssocItemKind::Delegation(_) | ast::AssocItemKind::DelegationMac(_), _) => {
718+
// TODO(ytmimi) #![feature(fn_delegation)]
719+
// add formatting for `AssocItemKind::Delegation` and `AssocItemKind::DelegationMac`
720+
self.push_rewrite(ai.span, None);
721+
}
718722
}
719723
}
720724

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![feature(fn_delegation)]
2+
3+
struct Ty;
4+
impl Ty {
5+
reuse std::convert::identity;
6+
}
7+
8+
trait Trait {
9+
reuse std::convert::identity;
10+
}

0 commit comments

Comments
 (0)