@@ -473,8 +473,8 @@ impl<'a> FmtVisitor<'a> {
473
473
let discr_ident_lens: Vec < usize > = enum_def
474
474
. variants
475
475
. 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 ( ) )
478
478
. collect ( ) ;
479
479
// cut the list at the point of longest discrim shorter than the threshold
480
480
// All of the discrims under the threshold will get padded, and all above - left as is.
@@ -491,8 +491,8 @@ impl<'a> FmtVisitor<'a> {
491
491
"}" ,
492
492
"," ,
493
493
|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 ( )
496
496
} else {
497
497
f. span . lo ( )
498
498
}
@@ -533,34 +533,33 @@ impl<'a> FmtVisitor<'a> {
533
533
one_line_width : usize ,
534
534
pad_discrim_ident_to : usize ,
535
535
) -> 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 ( ) ;
538
538
let span = mk_sp ( lo, field. span . hi ( ) ) ;
539
539
return Some ( self . snippet ( span) . to_owned ( ) ) ;
540
540
}
541
541
542
542
let context = self . get_context ( ) ;
543
543
// 1 = ','
544
544
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) ?;
546
546
let lo = field
547
- . node
548
547
. attrs
549
548
. last ( )
550
549
. map_or ( field. span . lo ( ) , |attr| attr. span . hi ( ) ) ;
551
550
let span = mk_sp ( lo, field. span . lo ( ) ) ;
552
551
553
- let variant_body = match field. node . data {
552
+ let variant_body = match field. data {
554
553
ast:: VariantData :: Tuple ( ..) | ast:: VariantData :: Struct ( ..) => format_struct (
555
554
& context,
556
555
& StructParts :: from_variant ( field) ,
557
556
self . block_indent ,
558
557
Some ( one_line_width) ,
559
558
) ?,
560
- ast:: VariantData :: Unit ( ..) => rewrite_ident ( & context, field. node . ident ) . to_owned ( ) ,
559
+ ast:: VariantData :: Unit ( ..) => rewrite_ident ( & context, field. ident ) . to_owned ( ) ,
561
560
} ;
562
561
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 {
564
563
let lhs = format ! ( "{:1$} =" , variant_body, pad_discrim_ident_to) ;
565
564
rewrite_assign_rhs_with (
566
565
& context,
@@ -585,27 +584,27 @@ impl<'a> FmtVisitor<'a> {
585
584
buffer. push ( ( self . buffer . clone ( ) , item. clone ( ) ) ) ;
586
585
self . buffer . clear ( ) ;
587
586
}
588
- // type -> existential -> const -> macro -> method
587
+ // type -> opaque -> const -> macro -> method
589
588
use crate :: ast:: ImplItemKind :: * ;
590
589
fn need_empty_line ( a : & ast:: ImplItemKind , b : & ast:: ImplItemKind ) -> bool {
591
590
match ( a, b) {
592
- ( Type ( ..) , Type ( ..) )
591
+ ( TyAlias ( ..) , TyAlias ( ..) )
593
592
| ( Const ( ..) , Const ( ..) )
594
- | ( Existential ( ..) , Existential ( ..) ) => false ,
593
+ | ( OpaqueTy ( ..) , OpaqueTy ( ..) ) => false ,
595
594
_ => true ,
596
595
}
597
596
}
598
597
599
598
buffer. sort_by ( |( _, a) , ( _, b) | match ( & a. node , & b. node ) {
600
- ( Type ( ..) , Type ( ..) )
599
+ ( TyAlias ( ..) , TyAlias ( ..) )
601
600
| ( Const ( ..) , Const ( ..) )
602
601
| ( 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 ( ) ) ,
604
603
( 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 ,
609
608
( Const ( ..) , _) => Ordering :: Less ,
610
609
( _, Const ( ..) ) => Ordering :: Greater ,
611
610
( Macro ( ..) , _) => Ordering :: Less ,
@@ -920,9 +919,9 @@ impl<'a> StructParts<'a> {
920
919
fn from_variant ( variant : & ' a ast:: Variant ) -> Self {
921
920
StructParts {
922
921
prefix : "" ,
923
- ident : variant. node . ident ,
922
+ ident : variant. ident ,
924
923
vis : & DEFAULT_VISIBILITY ,
925
- def : & variant. node . data ,
924
+ def : & variant. data ,
926
925
generics : None ,
927
926
span : variant. span ,
928
927
}
@@ -1517,7 +1516,7 @@ pub(crate) fn rewrite_type_alias(
1517
1516
rewrite_type_item ( context, indent, "type" , " =" , ident, ty, generics, vis)
1518
1517
}
1519
1518
1520
- pub ( crate ) fn rewrite_existential_type (
1519
+ pub ( crate ) fn rewrite_opaque_type (
1521
1520
context : & RewriteContext < ' _ > ,
1522
1521
indent : Indent ,
1523
1522
ident : ast:: Ident ,
@@ -1528,8 +1527,8 @@ pub(crate) fn rewrite_existential_type(
1528
1527
rewrite_type_item (
1529
1528
context,
1530
1529
indent,
1531
- "existential type" ,
1532
- ": " ,
1530
+ "type" ,
1531
+ " = " ,
1533
1532
ident,
1534
1533
generic_bounds,
1535
1534
generics,
@@ -1786,15 +1785,42 @@ pub(crate) fn rewrite_associated_type(
1786
1785
}
1787
1786
}
1788
1787
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 (
1790
1802
context : & RewriteContext < ' _ > ,
1791
1803
ident : ast:: Ident ,
1792
1804
generics : & ast:: Generics ,
1793
1805
generic_bounds : & ast:: GenericBounds ,
1794
1806
indent : Indent ,
1795
1807
) -> 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 + ";" )
1798
1824
}
1799
1825
1800
1826
pub ( crate ) fn rewrite_associated_impl_type (
@@ -1877,7 +1903,7 @@ fn get_missing_arg_comments(
1877
1903
( comment_before_colon, comment_after_colon)
1878
1904
}
1879
1905
1880
- impl Rewrite for ast:: Arg {
1906
+ impl Rewrite for ast:: Param {
1881
1907
fn rewrite ( & self , context : & RewriteContext < ' _ > , shape : Shape ) -> Option < String > {
1882
1908
if let Some ( ref explicit_self) = self . to_self ( ) {
1883
1909
rewrite_explicit_self ( context, explicit_self)
@@ -1941,23 +1967,23 @@ fn rewrite_explicit_self(
1941
1967
}
1942
1968
}
1943
1969
1944
- pub ( crate ) fn span_lo_for_arg ( arg : & ast:: Arg ) -> BytePos {
1970
+ pub ( crate ) fn span_lo_for_arg ( arg : & ast:: Param ) -> BytePos {
1945
1971
if is_named_arg ( arg) {
1946
1972
arg. pat . span . lo ( )
1947
1973
} else {
1948
1974
arg. ty . span . lo ( )
1949
1975
}
1950
1976
}
1951
1977
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 {
1953
1979
match arg. ty . node {
1954
1980
ast:: TyKind :: Infer if context. snippet ( arg. ty . span ) == "_" => arg. ty . span . hi ( ) ,
1955
1981
ast:: TyKind :: Infer if is_named_arg ( arg) => arg. pat . span . hi ( ) ,
1956
1982
_ => arg. ty . span . hi ( ) ,
1957
1983
}
1958
1984
}
1959
1985
1960
- pub ( crate ) fn is_named_arg ( arg : & ast:: Arg ) -> bool {
1986
+ pub ( crate ) fn is_named_arg ( arg : & ast:: Param ) -> bool {
1961
1987
if let ast:: PatKind :: Ident ( _, ident, _) = arg. pat . node {
1962
1988
ident. name != symbol:: kw:: Invalid
1963
1989
} else {
@@ -2349,7 +2375,7 @@ impl WhereClauseOption {
2349
2375
2350
2376
fn rewrite_args (
2351
2377
context : & RewriteContext < ' _ > ,
2352
- args : & [ ast:: Arg ] ,
2378
+ args : & [ ast:: Param ] ,
2353
2379
one_line_budget : usize ,
2354
2380
multi_line_budget : usize ,
2355
2381
indent : Indent ,
0 commit comments