File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -751,9 +751,19 @@ impl HirDisplay for Ty {
751751 }
752752 TyKind :: BoundVar ( idx) => idx. hir_fmt ( f) ?,
753753 TyKind :: Dyn ( dyn_ty) => {
754+ // Reorder bounds to satisfy `write_bounds_like_dyn_trait()`'s expectation.
755+ // FIXME: `Iterator::partition_in_place()` or `Vec::drain_filter()` may make it
756+ // more efficient when either of them hits stable.
757+ let mut bounds: SmallVec < [ _ ; 4 ] > =
758+ dyn_ty. bounds . skip_binders ( ) . iter ( Interner ) . cloned ( ) . collect ( ) ;
759+ let ( auto_traits, others) : ( SmallVec < [ _ ; 4 ] > , _ ) =
760+ bounds. drain ( 1 ..) . partition ( |b| b. skip_binders ( ) . trait_id ( ) . is_some ( ) ) ;
761+ bounds. extend ( others) ;
762+ bounds. extend ( auto_traits) ;
763+
754764 write_bounds_like_dyn_trait_with_prefix (
755765 "dyn" ,
756- dyn_ty . bounds . skip_binders ( ) . interned ( ) ,
766+ & bounds,
757767 SizedByDefault :: NotSized ,
758768 f,
759769 ) ?;
Original file line number Diff line number Diff line change @@ -55,6 +55,28 @@ fn main() {
5555 ) ;
5656}
5757
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+
5880#[ test]
5981fn render_dyn_for_ty ( ) {
6082 // FIXME
You can’t perform that action at this time.
0 commit comments