@@ -5,7 +5,6 @@ use std::cmp::{max, min, Ordering};
5
5
6
6
use regex:: Regex ;
7
7
use rustc_span:: { BytePos , DUMMY_SP , source_map, Span , symbol} ;
8
- use rustc_target:: spec:: abi;
9
8
use syntax:: visit;
10
9
use syntax:: { ast, ptr} ;
11
10
@@ -195,7 +194,11 @@ impl<'a> Item<'a> {
195
194
fn from_foreign_mod ( fm : & ' a ast:: ForeignMod , span : Span , config : & Config ) -> Item < ' a > {
196
195
Item {
197
196
keyword : "" ,
198
- abi : format_extern ( ast:: Extern :: from_abi ( fm. abi ) , config. force_explicit_abi ( ) , true ) ,
197
+ abi : format_extern (
198
+ ast:: Extern :: from_abi ( fm. abi ) ,
199
+ config. force_explicit_abi ( ) ,
200
+ true ,
201
+ ) ,
199
202
vis : None ,
200
203
body : fm
201
204
. items
@@ -220,7 +223,6 @@ pub(crate) struct FnSig<'a> {
220
223
decl : & ' a ast:: FnDecl ,
221
224
generics : & ' a ast:: Generics ,
222
225
ext : ast:: Extern ,
223
- // abi: abi::Abi,
224
226
is_async : Cow < ' a , ast:: IsAsync > ,
225
227
constness : ast:: Constness ,
226
228
defaultness : ast:: Defaultness ,
@@ -250,11 +252,6 @@ impl<'a> FnSig<'a> {
250
252
method_sig : & ' a ast:: FnSig ,
251
253
generics : & ' a ast:: Generics ,
252
254
) -> FnSig < ' a > {
253
- // let abi = match method_sig.header.ext {
254
- // ast::Extern::None => abi::Abi::Rust,
255
- // ast::Extern::Implicit => abi::Abi::C,
256
- // ast::Extern::Explicit(abi) => self.lower_abi(abi),
257
- // };
258
255
FnSig {
259
256
unsafety : method_sig. header . unsafety ,
260
257
is_async : Cow :: Borrowed ( & method_sig. header . asyncness . node ) ,
@@ -646,21 +643,70 @@ impl<'a> FmtVisitor<'a> {
646
643
buffer. push ( ( self . buffer . clone ( ) , item. clone ( ) ) ) ;
647
644
self . buffer . clear ( ) ;
648
645
}
646
+
647
+ fn is_type ( ty : & Option < syntax:: ptr:: P < ast:: Ty > > ) -> bool {
648
+ match ty {
649
+ None => true ,
650
+ Some ( lty) => match lty. kind . opaque_top_hack ( ) {
651
+ None => true ,
652
+ Some ( _) => false ,
653
+ } ,
654
+ }
655
+ }
656
+
657
+ fn is_opaque ( ty : & Option < syntax:: ptr:: P < ast:: Ty > > ) -> bool {
658
+ match ty {
659
+ None => false ,
660
+ Some ( lty) => match lty. kind . opaque_top_hack ( ) {
661
+ None => false ,
662
+ Some ( _) => true ,
663
+ } ,
664
+ }
665
+ }
666
+
667
+ fn both_type (
668
+ a : & Option < syntax:: ptr:: P < ast:: Ty > > ,
669
+ b : & Option < syntax:: ptr:: P < ast:: Ty > > ,
670
+ ) -> bool {
671
+ is_type ( a) && is_type ( b)
672
+ }
673
+
674
+ fn both_opaque (
675
+ a : & Option < syntax:: ptr:: P < ast:: Ty > > ,
676
+ b : & Option < syntax:: ptr:: P < ast:: Ty > > ,
677
+ ) -> bool {
678
+ is_opaque ( a) && is_opaque ( b)
679
+ }
680
+
681
+ // In rustc-ap-v638 the `OpaqueTy` AssocItemKind was removed but
682
+ // we still need to differentiate to maintain sorting order.
683
+
649
684
// type -> opaque -> const -> macro -> method
650
685
use crate :: ast:: AssocItemKind :: * ;
651
686
fn need_empty_line ( a : & ast:: AssocItemKind , b : & ast:: AssocItemKind ) -> bool {
652
687
match ( a, b) {
653
- ( TyAlias ( ..) , TyAlias ( ..) )
654
- | ( Const ( ..) , Const ( ..) ) => false ,
688
+ ( TyAlias ( _, ref lty) , TyAlias ( _, ref rty) )
689
+ if both_type ( lty, rty) || both_opaque ( lty, rty) =>
690
+ {
691
+ false
692
+ }
693
+ ( Const ( ..) , Const ( ..) ) => false ,
655
694
_ => true ,
656
695
}
657
696
}
658
697
659
698
buffer. sort_by ( |( _, a) , ( _, b) | match ( & a. kind , & b. kind ) {
660
- ( TyAlias ( ..) , TyAlias ( ..) )
661
- | ( Const ( ..) , Const ( ..) )
662
- | ( Macro ( ..) , Macro ( ..) ) => a. ident . as_str ( ) . cmp ( & b. ident . as_str ( ) ) ,
699
+ ( TyAlias ( _, ref lty) , TyAlias ( _, ref rty) )
700
+ if both_type ( lty, rty) || both_opaque ( lty, rty) =>
701
+ {
702
+ a. ident . as_str ( ) . cmp ( & b. ident . as_str ( ) )
703
+ }
704
+ ( Const ( ..) , Const ( ..) ) | ( Macro ( ..) , Macro ( ..) ) => {
705
+ a. ident . as_str ( ) . cmp ( & b. ident . as_str ( ) )
706
+ }
663
707
( Fn ( ..) , Fn ( ..) ) => a. span . lo ( ) . cmp ( & b. span . lo ( ) ) ,
708
+ ( TyAlias ( _, ref ty) , _) if is_type ( ty) => Ordering :: Less ,
709
+ ( _, TyAlias ( _, ref ty) ) if is_type ( ty) => Ordering :: Greater ,
664
710
( TyAlias ( ..) , _) => Ordering :: Less ,
665
711
( _, TyAlias ( ..) ) => Ordering :: Greater ,
666
712
( Const ( ..) , _) => Ordering :: Less ,
0 commit comments