Skip to content

Commit

Permalink
Print RPITIT like an opaque
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Feb 27, 2024
1 parent 1feef44 commit b57ddfe
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
20 changes: 12 additions & 8 deletions compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,13 +715,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
p!(print_def_path(def_id, &[]));
}
ty::Alias(ty::Projection | ty::Inherent | ty::Weak, ref data) => {
if !(self.should_print_verbose() || with_no_queries())
&& self.tcx().is_impl_trait_in_trait(data.def_id)
{
return self.pretty_print_opaque_impl_type(data.def_id, data.args);
} else {
p!(print(data))
}
p!(print(data))
}
ty::Placeholder(placeholder) => match placeholder.bound.kind {
ty::BoundTyKind::Anon => p!(write("{placeholder:?}")),
Expand Down Expand Up @@ -3053,7 +3047,17 @@ define_print_and_forward_display! {
if let DefKind::Impl { of_trait: false } = cx.tcx().def_kind(cx.tcx().parent(self.def_id)) {
p!(pretty_print_inherent_projection(self))
} else {
p!(print_def_path(self.def_id, self.args));
// If we're printing verbosely, or don't want to invoke queries
// (`is_impl_trait_in_trait`), then fall back to printing the def path.
// This is likely what you want if you're debugging the compiler anyways.
if !(cx.should_print_verbose() || with_no_queries())
&& cx.tcx().is_impl_trait_in_trait(self.def_id)
{
return cx.pretty_print_opaque_impl_type(self.def_id, self.args);
} else {
p!(print_def_path(self.def_id, self.args));
}

}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/impl-trait/in-trait/async-and-ret-ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ trait T {}

trait MyTrait {
async fn foo() -> &'static impl T;
//~^ ERROR the associated type `<Self as MyTrait>::{opaque#0}` may not live long enough
//~^ ERROR the associated type `impl T` may not live long enough
}

fn main() {}
4 changes: 2 additions & 2 deletions tests/ui/impl-trait/in-trait/async-and-ret-ref.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
error[E0310]: the associated type `<Self as MyTrait>::{synthetic#0}` may not live long enough
error[E0310]: the associated type `impl T` may not live long enough
--> $DIR/async-and-ret-ref.rs:7:5
|
LL | async fn foo() -> &'static impl T;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| the associated type `<Self as MyTrait>::{synthetic#0}` must be valid for the static lifetime...
| the associated type `impl T` must be valid for the static lifetime...
| ...so that the reference type `&'static impl T` does not outlive the data it points at

error: aborting due to 1 previous error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ trait Erased {
impl<T: Original> Erased for T {
fn f(&self) -> Box<dyn Fn()> {
Box::new(<T as Original>::f())
//~^ ERROR the associated type `<T as Original>::{opaque#0}` may not live long enough
//~^ ERROR the associated type `impl Fn()` may not live long enough
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
error[E0310]: the associated type `<T as Original>::{synthetic#0}` may not live long enough
error[E0310]: the associated type `impl Fn()` may not live long enough
--> $DIR/missing-static-bound-from-impl.rs:11:9
|
LL | Box::new(<T as Original>::f())
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| the associated type `<T as Original>::{synthetic#0}` must be valid for the static lifetime...
| the associated type `impl Fn()` must be valid for the static lifetime...
| ...so that the type `impl Fn()` will meet its required lifetime bounds

error: aborting due to 1 previous error
Expand Down

0 comments on commit b57ddfe

Please sign in to comment.