Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't suggest dereferencing to unsized type #115629

Merged
merged 3 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
});
Comment on lines +1243 to +1245
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interestingly, this isn't necessary for the pretty-printing of impl Trait, because dyn Trait is the only thing that we actually end up sorting the bounds after the fact 🤦‍♂️


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
Loading