Rollup merge of #121686 - compiler-errors:rpitit-printing, r=lcnr

Adjust printing for RPITITs

1. Call RPITITs `{synthetic#N}` instead of `{opaque#N}`.
2. Fall back to printing the RPITIT like an opaque even when printed as an `AliasTy`, just like we do for `ty::Alias`.

You could argue that (2.) is misleading, but I believe it's more consistent than naming `{synthetic#N}`, which I assume approximately nobody knows where that def path name comes from.

r? lcnr
This commit is contained in:
Guillaume Gomez 2024-02-28 16:04:52 +01:00 committed by GitHub
commit a0027e86aa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 28 additions and 21 deletions

View File

@ -420,7 +420,9 @@ impl DefPathData {
pub fn name(&self) -> DefPathDataName { pub fn name(&self) -> DefPathDataName {
use self::DefPathData::*; use self::DefPathData::*;
match *self { match *self {
TypeNs(name) if name == kw::Empty => DefPathDataName::Anon { namespace: sym::opaque }, TypeNs(name) if name == kw::Empty => {
DefPathDataName::Anon { namespace: sym::synthetic }
}
TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name) => { TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name) => {
DefPathDataName::Named(name) DefPathDataName::Named(name)
} }

View File

@ -715,13 +715,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
p!(print_def_path(def_id, &[])); p!(print_def_path(def_id, &[]));
} }
ty::Alias(ty::Projection | ty::Inherent | ty::Weak, ref data) => { ty::Alias(ty::Projection | ty::Inherent | ty::Weak, ref data) => {
if !(self.should_print_verbose() || with_no_queries()) p!(print(data))
&& 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))
}
} }
ty::Placeholder(placeholder) => match placeholder.bound.kind { ty::Placeholder(placeholder) => match placeholder.bound.kind {
ty::BoundTyKind::Anon => p!(write("{placeholder:?}")), ty::BoundTyKind::Anon => p!(write("{placeholder:?}")),
@ -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)) { if let DefKind::Impl { of_trait: false } = cx.tcx().def_kind(cx.tcx().parent(self.def_id)) {
p!(pretty_print_inherent_projection(self)) p!(pretty_print_inherent_projection(self))
} else { } 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));
}
} }
} }

View File

@ -1690,6 +1690,7 @@ symbols! {
suggestion, suggestion,
sym, sym,
sync, sync,
synthetic,
t32, t32,
target, target,
target_abi, target_abi,

View File

@ -5,7 +5,7 @@ trait T {}
trait MyTrait { trait MyTrait {
async fn foo() -> &'static impl T; 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() {} fn main() {}

View File

@ -1,10 +1,10 @@
error[E0310]: the associated type `<Self as MyTrait>::{opaque#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 --> $DIR/async-and-ret-ref.rs:7:5
| |
LL | async fn foo() -> &'static impl T; LL | async fn foo() -> &'static impl T;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| | | |
| the associated type `<Self as MyTrait>::{opaque#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 | ...so that the reference type `&'static impl T` does not outlive the data it points at
error: aborting due to 1 previous error error: aborting due to 1 previous error

View File

@ -6,11 +6,11 @@ LL | fn bar() -> () {}
| |
= help: the trait `std::fmt::Display` is not implemented for `()` = help: the trait `std::fmt::Display` is not implemented for `()`
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
note: required by a bound in `Foo::{opaque#0}` note: required by a bound in `Foo::{synthetic#0}`
--> $DIR/doesnt-satisfy.rs:2:22 --> $DIR/doesnt-satisfy.rs:2:22
| |
LL | fn bar() -> impl std::fmt::Display; LL | fn bar() -> impl std::fmt::Display;
| ^^^^^^^^^^^^^^^^^ required by this bound in `Foo::{opaque#0}` | ^^^^^^^^^^^^^^^^^ required by this bound in `Foo::{synthetic#0}`
error: aborting due to 1 previous error error: aborting due to 1 previous error

View File

@ -9,7 +9,7 @@ trait Erased {
impl<T: Original> Erased for T { impl<T: Original> Erased for T {
fn f(&self) -> Box<dyn Fn()> { fn f(&self) -> Box<dyn Fn()> {
Box::new(<T as Original>::f()) 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
} }
} }

View File

@ -1,10 +1,10 @@
error[E0310]: the associated type `<T as Original>::{opaque#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 --> $DIR/missing-static-bound-from-impl.rs:11:9
| |
LL | Box::new(<T as Original>::f()) LL | Box::new(<T as Original>::f())
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| | | |
| the associated type `<T as Original>::{opaque#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 | ...so that the type `impl Fn()` will meet its required lifetime bounds
error: aborting due to 1 previous error error: aborting due to 1 previous error

View File

@ -5,11 +5,11 @@ LL | fn foo<F2: Foo<u8>>(self) -> impl Foo<u8> {
| ^^^^^^^^^^^^ the trait `Foo<char>` is not implemented for `impl Foo<u8>` | ^^^^^^^^^^^^ the trait `Foo<char>` is not implemented for `impl Foo<u8>`
| |
= help: the trait `Foo<char>` is implemented for `Bar` = help: the trait `Foo<char>` is implemented for `Bar`
note: required by a bound in `Foo::{opaque#0}` note: required by a bound in `Foo::{synthetic#0}`
--> $DIR/return-dont-satisfy-bounds.rs:2:30 --> $DIR/return-dont-satisfy-bounds.rs:2:30
| |
LL | fn foo<F2>(self) -> impl Foo<T>; LL | fn foo<F2>(self) -> impl Foo<T>;
| ^^^^^^ required by this bound in `Foo::{opaque#0}` | ^^^^^^ required by this bound in `Foo::{synthetic#0}`
error[E0276]: impl has stricter requirements than trait error[E0276]: impl has stricter requirements than trait
--> $DIR/return-dont-satisfy-bounds.rs:8:16 --> $DIR/return-dont-satisfy-bounds.rs:8:16

View File

@ -4,11 +4,11 @@ error[E0277]: the trait bound `Something: Termination` is not satisfied
LL | fn main() -> Something { LL | fn main() -> Something {
| ^^^^^^^^^ the trait `Termination` is not implemented for `Something` | ^^^^^^^^^ the trait `Termination` is not implemented for `Something`
| |
note: required by a bound in `Main::{opaque#0}` note: required by a bound in `Main::{synthetic#0}`
--> $DIR/issue-103052-2.rs:5:27 --> $DIR/issue-103052-2.rs:5:27
| |
LL | fn main() -> impl std::process::Termination; LL | fn main() -> impl std::process::Termination;
| ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Main::{opaque#0}` | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Main::{synthetic#0}`
error: aborting due to 1 previous error error: aborting due to 1 previous error