Skip to content

Commit

Permalink
Ensure that dyn trait bounds stay sorted
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Sep 7, 2023
1 parent 67e7d85 commit 3bf3dad
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 18 deletions.
19 changes: 8 additions & 11 deletions compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}));
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/traits/object/enforce-supertrait-projection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
Original file line number Diff line number Diff line change
@@ -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
|
Expand Down

0 comments on commit 3bf3dad

Please sign in to comment.