@@ -473,8 +473,8 @@ impl<'a> FmtVisitor<'a> {
473473 let discr_ident_lens: Vec < usize > = enum_def
474474 . variants
475475 . iter ( )
476- . filter ( |var| var. node . disr_expr . is_some ( ) )
477- . map ( |var| rewrite_ident ( & self . get_context ( ) , var. node . ident ) . len ( ) )
476+ . filter ( |var| var. disr_expr . is_some ( ) )
477+ . map ( |var| rewrite_ident ( & self . get_context ( ) , var. ident ) . len ( ) )
478478 . collect ( ) ;
479479 // cut the list at the point of longest discrim shorter than the threshold
480480 // All of the discrims under the threshold will get padded, and all above - left as is.
@@ -491,8 +491,8 @@ impl<'a> FmtVisitor<'a> {
491491 "}" ,
492492 "," ,
493493 |f| {
494- if !f. node . attrs . is_empty ( ) {
495- f. node . attrs [ 0 ] . span . lo ( )
494+ if !f. attrs . is_empty ( ) {
495+ f. attrs [ 0 ] . span . lo ( )
496496 } else {
497497 f. span . lo ( )
498498 }
@@ -533,34 +533,33 @@ impl<'a> FmtVisitor<'a> {
533533 one_line_width : usize ,
534534 pad_discrim_ident_to : usize ,
535535 ) -> Option < String > {
536- if contains_skip ( & field. node . attrs ) {
537- let lo = field. node . attrs [ 0 ] . span . lo ( ) ;
536+ if contains_skip ( & field. attrs ) {
537+ let lo = field. attrs [ 0 ] . span . lo ( ) ;
538538 let span = mk_sp ( lo, field. span . hi ( ) ) ;
539539 return Some ( self . snippet ( span) . to_owned ( ) ) ;
540540 }
541541
542542 let context = self . get_context ( ) ;
543543 // 1 = ','
544544 let shape = self . shape ( ) . sub_width ( 1 ) ?;
545- let attrs_str = field. node . attrs . rewrite ( & context, shape) ?;
545+ let attrs_str = field. attrs . rewrite ( & context, shape) ?;
546546 let lo = field
547- . node
548547 . attrs
549548 . last ( )
550549 . map_or ( field. span . lo ( ) , |attr| attr. span . hi ( ) ) ;
551550 let span = mk_sp ( lo, field. span . lo ( ) ) ;
552551
553- let variant_body = match field. node . data {
552+ let variant_body = match field. data {
554553 ast:: VariantData :: Tuple ( ..) | ast:: VariantData :: Struct ( ..) => format_struct (
555554 & context,
556555 & StructParts :: from_variant ( field) ,
557556 self . block_indent ,
558557 Some ( one_line_width) ,
559558 ) ?,
560- ast:: VariantData :: Unit ( ..) => rewrite_ident ( & context, field. node . ident ) . to_owned ( ) ,
559+ ast:: VariantData :: Unit ( ..) => rewrite_ident ( & context, field. ident ) . to_owned ( ) ,
561560 } ;
562561
563- let variant_body = if let Some ( ref expr) = field. node . disr_expr {
562+ let variant_body = if let Some ( ref expr) = field. disr_expr {
564563 let lhs = format ! ( "{:1$} =" , variant_body, pad_discrim_ident_to) ;
565564 rewrite_assign_rhs_with (
566565 & context,
@@ -585,27 +584,27 @@ impl<'a> FmtVisitor<'a> {
585584 buffer. push ( ( self . buffer . clone ( ) , item. clone ( ) ) ) ;
586585 self . buffer . clear ( ) ;
587586 }
588- // type -> existential -> const -> macro -> method
587+ // type -> opaque -> const -> macro -> method
589588 use crate :: ast:: ImplItemKind :: * ;
590589 fn need_empty_line ( a : & ast:: ImplItemKind , b : & ast:: ImplItemKind ) -> bool {
591590 match ( a, b) {
592- ( Type ( ..) , Type ( ..) )
591+ ( TyAlias ( ..) , TyAlias ( ..) )
593592 | ( Const ( ..) , Const ( ..) )
594- | ( Existential ( ..) , Existential ( ..) ) => false ,
593+ | ( OpaqueTy ( ..) , OpaqueTy ( ..) ) => false ,
595594 _ => true ,
596595 }
597596 }
598597
599598 buffer. sort_by ( |( _, a) , ( _, b) | match ( & a. node , & b. node ) {
600- ( Type ( ..) , Type ( ..) )
599+ ( TyAlias ( ..) , TyAlias ( ..) )
601600 | ( Const ( ..) , Const ( ..) )
602601 | ( Macro ( ..) , Macro ( ..) )
603- | ( Existential ( ..) , Existential ( ..) ) => a. ident . as_str ( ) . cmp ( & b. ident . as_str ( ) ) ,
602+ | ( OpaqueTy ( ..) , OpaqueTy ( ..) ) => a. ident . as_str ( ) . cmp ( & b. ident . as_str ( ) ) ,
604603 ( Method ( ..) , Method ( ..) ) => a. span . lo ( ) . cmp ( & b. span . lo ( ) ) ,
605- ( Type ( ..) , _) => Ordering :: Less ,
606- ( _, Type ( ..) ) => Ordering :: Greater ,
607- ( Existential ( ..) , _) => Ordering :: Less ,
608- ( _, Existential ( ..) ) => Ordering :: Greater ,
604+ ( TyAlias ( ..) , _) => Ordering :: Less ,
605+ ( _, TyAlias ( ..) ) => Ordering :: Greater ,
606+ ( OpaqueTy ( ..) , _) => Ordering :: Less ,
607+ ( _, OpaqueTy ( ..) ) => Ordering :: Greater ,
609608 ( Const ( ..) , _) => Ordering :: Less ,
610609 ( _, Const ( ..) ) => Ordering :: Greater ,
611610 ( Macro ( ..) , _) => Ordering :: Less ,
@@ -920,9 +919,9 @@ impl<'a> StructParts<'a> {
920919 fn from_variant ( variant : & ' a ast:: Variant ) -> Self {
921920 StructParts {
922921 prefix : "" ,
923- ident : variant. node . ident ,
922+ ident : variant. ident ,
924923 vis : & DEFAULT_VISIBILITY ,
925- def : & variant. node . data ,
924+ def : & variant. data ,
926925 generics : None ,
927926 span : variant. span ,
928927 }
@@ -1517,7 +1516,7 @@ pub(crate) fn rewrite_type_alias(
15171516 rewrite_type_item ( context, indent, "type" , " =" , ident, ty, generics, vis)
15181517}
15191518
1520- pub ( crate ) fn rewrite_existential_type (
1519+ pub ( crate ) fn rewrite_opaque_type (
15211520 context : & RewriteContext < ' _ > ,
15221521 indent : Indent ,
15231522 ident : ast:: Ident ,
@@ -1528,8 +1527,8 @@ pub(crate) fn rewrite_existential_type(
15281527 rewrite_type_item (
15291528 context,
15301529 indent,
1531- "existential type" ,
1532- ": " ,
1530+ "type" ,
1531+ " = " ,
15331532 ident,
15341533 generic_bounds,
15351534 generics,
@@ -1786,15 +1785,42 @@ pub(crate) fn rewrite_associated_type(
17861785 }
17871786}
17881787
1789- pub ( crate ) fn rewrite_existential_impl_type (
1788+ struct OpaqueType < ' a > {
1789+ bounds : & ' a ast:: GenericBounds ,
1790+ }
1791+
1792+ impl < ' a > Rewrite for OpaqueType < ' a > {
1793+ fn rewrite ( & self , context : & RewriteContext < ' _ > , shape : Shape ) -> Option < String > {
1794+ let shape = shape. offset_left ( 5 ) ?; // `impl `
1795+ self . bounds
1796+ . rewrite ( context, shape)
1797+ . map ( |s| format ! ( "impl {}" , s) )
1798+ }
1799+ }
1800+
1801+ pub ( crate ) fn rewrite_opaque_impl_type (
17901802 context : & RewriteContext < ' _ > ,
17911803 ident : ast:: Ident ,
17921804 generics : & ast:: Generics ,
17931805 generic_bounds : & ast:: GenericBounds ,
17941806 indent : Indent ,
17951807) -> Option < String > {
1796- rewrite_associated_type ( ident, None , generics, Some ( generic_bounds) , context, indent)
1797- . map ( |s| format ! ( "existential {}" , s) )
1808+ let ident_str = rewrite_ident ( context, ident) ;
1809+ // 5 = "type "
1810+ let generics_shape = Shape :: indented ( indent, context. config ) . offset_left ( 5 ) ?;
1811+ let generics_str = rewrite_generics ( context, ident_str, generics, generics_shape) ?;
1812+ let prefix = format ! ( "type {} =" , generics_str) ;
1813+ let rhs = OpaqueType {
1814+ bounds : generic_bounds,
1815+ } ;
1816+
1817+ rewrite_assign_rhs (
1818+ context,
1819+ & prefix,
1820+ & rhs,
1821+ Shape :: indented ( indent, context. config ) . sub_width ( 1 ) ?,
1822+ )
1823+ . map ( |s| s + ";" )
17981824}
17991825
18001826pub ( crate ) fn rewrite_associated_impl_type (
@@ -1877,7 +1903,7 @@ fn get_missing_arg_comments(
18771903 ( comment_before_colon, comment_after_colon)
18781904}
18791905
1880- impl Rewrite for ast:: Arg {
1906+ impl Rewrite for ast:: Param {
18811907 fn rewrite ( & self , context : & RewriteContext < ' _ > , shape : Shape ) -> Option < String > {
18821908 if let Some ( ref explicit_self) = self . to_self ( ) {
18831909 rewrite_explicit_self ( context, explicit_self)
@@ -1941,23 +1967,23 @@ fn rewrite_explicit_self(
19411967 }
19421968}
19431969
1944- pub ( crate ) fn span_lo_for_arg ( arg : & ast:: Arg ) -> BytePos {
1970+ pub ( crate ) fn span_lo_for_arg ( arg : & ast:: Param ) -> BytePos {
19451971 if is_named_arg ( arg) {
19461972 arg. pat . span . lo ( )
19471973 } else {
19481974 arg. ty . span . lo ( )
19491975 }
19501976}
19511977
1952- pub ( crate ) fn span_hi_for_arg ( context : & RewriteContext < ' _ > , arg : & ast:: Arg ) -> BytePos {
1978+ pub ( crate ) fn span_hi_for_arg ( context : & RewriteContext < ' _ > , arg : & ast:: Param ) -> BytePos {
19531979 match arg. ty . node {
19541980 ast:: TyKind :: Infer if context. snippet ( arg. ty . span ) == "_" => arg. ty . span . hi ( ) ,
19551981 ast:: TyKind :: Infer if is_named_arg ( arg) => arg. pat . span . hi ( ) ,
19561982 _ => arg. ty . span . hi ( ) ,
19571983 }
19581984}
19591985
1960- pub ( crate ) fn is_named_arg ( arg : & ast:: Arg ) -> bool {
1986+ pub ( crate ) fn is_named_arg ( arg : & ast:: Param ) -> bool {
19611987 if let ast:: PatKind :: Ident ( _, ident, _) = arg. pat . node {
19621988 ident. name != symbol:: kw:: Invalid
19631989 } else {
@@ -2349,7 +2375,7 @@ impl WhereClauseOption {
23492375
23502376fn rewrite_args (
23512377 context : & RewriteContext < ' _ > ,
2352- args : & [ ast:: Arg ] ,
2378+ args : & [ ast:: Param ] ,
23532379 one_line_budget : usize ,
23542380 multi_line_budget : usize ,
23552381 indent : Indent ,
0 commit comments