Ensure that dyn trait bounds stay sorted

This commit is contained in:
Michael Goulet 2023-09-07 06:57:08 +00:00
parent 67e7d85ad2
commit 3bf3dadbc0
5 changed files with 15 additions and 18 deletions

View File

@ -1239,21 +1239,18 @@ pub trait PrettyPrinter<'tcx>:
.generics_of(principal.def_id)
.own_args_no_defaults(cx.tcx(), principal.args);
let mut projections = predicates.projection_bounds();
let mut args = args.iter().cloned();
let arg0 = args.next();
let projection0 = projections.next();
if arg0.is_some() || projection0.is_some() {
let args = arg0.into_iter().chain(args);
let projections = projection0.into_iter().chain(projections);
let mut projections: Vec<_> = predicates.projection_bounds().collect();
projections.sort_by_cached_key(|proj| {
cx.tcx().item_name(proj.item_def_id()).to_string()
});
if !args.is_empty() || !projections.is_empty() {
p!(generic_delimiters(|mut cx| {
cx = cx.comma_sep(args)?;
if arg0.is_some() && projection0.is_some() {
cx = cx.comma_sep(args.iter().copied())?;
if !args.is_empty() && !projections.is_empty() {
write!(cx, ", ")?;
}
cx.comma_sep(projections)
cx.comma_sep(projections.iter().copied())
}));
}
}

View File

@ -7,7 +7,7 @@ trait Trait: SuperTrait<A = <Self as SuperTrait>::B> {}
fn transmute<A, B>(x: A) -> B {
foo::<A, B, dyn Trait<A = A, B = B>>(x)
//~^ ERROR type mismatch resolving `<dyn Trait<B = B, A = A> as SuperTrait>::A == B`
//~^ ERROR type mismatch resolving `<dyn Trait<A = A, B = B> as SuperTrait>::A == B`
}
fn foo<A, B, T: ?Sized>(x: T::A) -> B

View File

@ -1,4 +1,4 @@
error[E0271]: type mismatch resolving `<dyn Trait<B = B, A = A> as SuperTrait>::A == B`
error[E0271]: type mismatch resolving `<dyn Trait<A = A, B = B> as SuperTrait>::A == B`
--> $DIR/enforce-supertrait-projection.rs:9:17
|
LL | fn transmute<A, B>(x: A) -> B {

View File

@ -9,7 +9,7 @@ where
I: Iterator<Item = i32>,
{
use_iterator(i);
//~^ ERROR `&dyn IntoIterator<Item = i32, IntoIter = I>` is not an iterator
//~^ ERROR `&dyn IntoIterator<IntoIter = I, Item = i32>` is not an iterator
}
fn main() {}

View File

@ -1,13 +1,13 @@
error[E0277]: `&dyn IntoIterator<Item = i32, IntoIter = I>` is not an iterator
error[E0277]: `&dyn IntoIterator<IntoIter = I, Item = i32>` is not an iterator
--> $DIR/dont-suggest-unsize-deref.rs:11:18
|
LL | use_iterator(i);
| ------------ ^ `&dyn IntoIterator<Item = i32, IntoIter = I>` is not an iterator
| ------------ ^ `&dyn IntoIterator<IntoIter = I, Item = i32>` is not an iterator
| |
| required by a bound introduced by this call
|
= help: the trait `Iterator` is not implemented for `&dyn IntoIterator<Item = i32, IntoIter = I>`
= note: required for `&dyn IntoIterator<Item = i32, IntoIter = I>` to implement `IntoIterator`
= help: the trait `Iterator` is not implemented for `&dyn IntoIterator<IntoIter = I, Item = i32>`
= note: required for `&dyn IntoIterator<IntoIter = I, Item = i32>` to implement `IntoIterator`
note: required by a bound in `use_iterator`
--> $DIR/dont-suggest-unsize-deref.rs:3:8
|