mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-29 06:23:25 +00:00
fix: reorder dyn bounds on render
This commit is contained in:
parent
3a69435af7
commit
5e43ea96aa
2 changed files with 33 additions and 1 deletions
|
@ -751,9 +751,19 @@ impl HirDisplay for Ty {
|
||||||
}
|
}
|
||||||
TyKind::BoundVar(idx) => idx.hir_fmt(f)?,
|
TyKind::BoundVar(idx) => idx.hir_fmt(f)?,
|
||||||
TyKind::Dyn(dyn_ty) => {
|
TyKind::Dyn(dyn_ty) => {
|
||||||
|
// Reorder bounds to satisfy `write_bounds_like_dyn_trait()`'s expectation.
|
||||||
|
// FIXME: `Iterator::partition_in_place()` or `Vec::drain_filter()` may make it
|
||||||
|
// more efficient when either of them hits stable.
|
||||||
|
let mut bounds: SmallVec<[_; 4]> =
|
||||||
|
dyn_ty.bounds.skip_binders().iter(Interner).cloned().collect();
|
||||||
|
let (auto_traits, others): (SmallVec<[_; 4]>, _) =
|
||||||
|
bounds.drain(1..).partition(|b| b.skip_binders().trait_id().is_some());
|
||||||
|
bounds.extend(others);
|
||||||
|
bounds.extend(auto_traits);
|
||||||
|
|
||||||
write_bounds_like_dyn_trait_with_prefix(
|
write_bounds_like_dyn_trait_with_prefix(
|
||||||
"dyn",
|
"dyn",
|
||||||
dyn_ty.bounds.skip_binders().interned(),
|
&bounds,
|
||||||
SizedByDefault::NotSized,
|
SizedByDefault::NotSized,
|
||||||
f,
|
f,
|
||||||
)?;
|
)?;
|
||||||
|
|
|
@ -55,6 +55,28 @@ fn main() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn render_dyn_ty_independent_of_order() {
|
||||||
|
check_types_source_code(
|
||||||
|
r#"
|
||||||
|
auto trait Send {}
|
||||||
|
trait A {
|
||||||
|
type Assoc;
|
||||||
|
}
|
||||||
|
trait B: A {}
|
||||||
|
|
||||||
|
fn test(
|
||||||
|
_: &(dyn A<Assoc = ()> + Send),
|
||||||
|
//^ &(dyn A<Assoc = ()> + Send)
|
||||||
|
_: &(dyn Send + A<Assoc = ()>),
|
||||||
|
//^ &(dyn A<Assoc = ()> + Send)
|
||||||
|
_: &dyn B<Assoc = ()>,
|
||||||
|
//^ &(dyn B<Assoc = ()>)
|
||||||
|
) {}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn render_dyn_for_ty() {
|
fn render_dyn_for_ty() {
|
||||||
// FIXME
|
// FIXME
|
||||||
|
|
Loading…
Reference in a new issue