File tree 2 files changed +31
-1
lines changed
2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -751,9 +751,17 @@ impl HirDisplay for Ty {
751
751
}
752
752
TyKind :: BoundVar ( idx) => idx. hir_fmt ( f) ?,
753
753
TyKind :: Dyn ( dyn_ty) => {
754
+ // Reorder bounds to satisfy `write_bounds_like_dyn_trait()`'s expectation.
755
+ let mut bounds: SmallVec < [ _ ; 4 ] > =
756
+ dyn_ty. bounds . skip_binders ( ) . iter ( Interner ) . cloned ( ) . collect ( ) ;
757
+ let ( auto_traits, others) : ( SmallVec < [ _ ; 4 ] > , _ ) =
758
+ bounds. drain ( 1 ..) . partition ( |b| b. skip_binders ( ) . trait_id ( ) . is_some ( ) ) ;
759
+ bounds. extend ( others) ;
760
+ bounds. extend ( auto_traits) ;
761
+
754
762
write_bounds_like_dyn_trait_with_prefix (
755
763
"dyn" ,
756
- dyn_ty . bounds . skip_binders ( ) . interned ( ) ,
764
+ & bounds,
757
765
SizedByDefault :: NotSized ,
758
766
f,
759
767
) ?;
Original file line number Diff line number Diff line change @@ -55,6 +55,28 @@ fn main() {
55
55
) ;
56
56
}
57
57
58
+ #[ test]
59
+ fn render_dyn_ty_independent_of_order ( ) {
60
+ check_types_source_code (
61
+ r#"
62
+ auto trait Send {}
63
+ trait A {
64
+ type Assoc;
65
+ }
66
+ trait B: A {}
67
+
68
+ fn test(
69
+ _: &(dyn A<Assoc = ()> + Send),
70
+ //^ &(dyn A<Assoc = ()> + Send)
71
+ _: &(dyn Send + A<Assoc = ()>),
72
+ //^ &(dyn A<Assoc = ()> + Send)
73
+ _: &dyn B<Assoc = ()>,
74
+ //^ &(dyn B<Assoc = ()>)
75
+ ) {}
76
+ "# ,
77
+ ) ;
78
+ }
79
+
58
80
#[ test]
59
81
fn render_dyn_for_ty ( ) {
60
82
// FIXME
You can’t perform that action at this time.
0 commit comments