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 {
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
+ // 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
+
754
764
write_bounds_like_dyn_trait_with_prefix(
755
765
"dyn",
756
- dyn_ty. bounds.skip_binders().interned() ,
766
+ & bounds,
757
767
SizedByDefault::NotSized,
758
768
f,
759
769
)?;
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