From 1feef44daf4de5ab35c0bf1eea0f3a54c59cf49c Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 27 Feb 2024 16:02:19 +0000 Subject: [PATCH 1/2] rename RPITIT from opaque to synthetic --- compiler/rustc_hir/src/definitions.rs | 4 +++- compiler/rustc_span/src/symbol.rs | 1 + tests/ui/impl-trait/in-trait/async-and-ret-ref.stderr | 4 ++-- tests/ui/impl-trait/in-trait/doesnt-satisfy.stderr | 4 ++-- .../impl-trait/in-trait/missing-static-bound-from-impl.stderr | 4 ++-- .../ui/impl-trait/in-trait/return-dont-satisfy-bounds.stderr | 4 ++-- .../ui/rfcs/rfc-1937-termination-trait/issue-103052-2.stderr | 4 ++-- 7 files changed, 14 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_hir/src/definitions.rs b/compiler/rustc_hir/src/definitions.rs index b81ad8b194623..f538d6bcb9816 100644 --- a/compiler/rustc_hir/src/definitions.rs +++ b/compiler/rustc_hir/src/definitions.rs @@ -420,7 +420,9 @@ impl DefPathData { pub fn name(&self) -> DefPathDataName { use self::DefPathData::*; 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) => { DefPathDataName::Named(name) } diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index d472c406c4717..df8ee4cbc5ab4 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1690,6 +1690,7 @@ symbols! { suggestion, sym, sync, + synthetic, t32, target, target_abi, diff --git a/tests/ui/impl-trait/in-trait/async-and-ret-ref.stderr b/tests/ui/impl-trait/in-trait/async-and-ret-ref.stderr index 15aa3cf54bbe5..a17653496dbd2 100644 --- a/tests/ui/impl-trait/in-trait/async-and-ret-ref.stderr +++ b/tests/ui/impl-trait/in-trait/async-and-ret-ref.stderr @@ -1,10 +1,10 @@ -error[E0310]: the associated type `::{opaque#0}` may not live long enough +error[E0310]: the associated type `::{synthetic#0}` may not live long enough --> $DIR/async-and-ret-ref.rs:7:5 | LL | async fn foo() -> &'static impl T; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | - | the associated type `::{opaque#0}` must be valid for the static lifetime... + | the associated type `::{synthetic#0}` 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 diff --git a/tests/ui/impl-trait/in-trait/doesnt-satisfy.stderr b/tests/ui/impl-trait/in-trait/doesnt-satisfy.stderr index baee1b5db6e9c..fc3efb44ac76b 100644 --- a/tests/ui/impl-trait/in-trait/doesnt-satisfy.stderr +++ b/tests/ui/impl-trait/in-trait/doesnt-satisfy.stderr @@ -6,11 +6,11 @@ LL | fn bar() -> () {} | = 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: required by a bound in `Foo::{opaque#0}` +note: required by a bound in `Foo::{synthetic#0}` --> $DIR/doesnt-satisfy.rs:2:22 | 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 diff --git a/tests/ui/impl-trait/in-trait/missing-static-bound-from-impl.stderr b/tests/ui/impl-trait/in-trait/missing-static-bound-from-impl.stderr index 5ec0ee38347aa..7fa4b8dbd49cd 100644 --- a/tests/ui/impl-trait/in-trait/missing-static-bound-from-impl.stderr +++ b/tests/ui/impl-trait/in-trait/missing-static-bound-from-impl.stderr @@ -1,10 +1,10 @@ -error[E0310]: the associated type `::{opaque#0}` may not live long enough +error[E0310]: the associated type `::{synthetic#0}` may not live long enough --> $DIR/missing-static-bound-from-impl.rs:11:9 | LL | Box::new(::f()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | - | the associated type `::{opaque#0}` must be valid for the static lifetime... + | the associated type `::{synthetic#0}` 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 diff --git a/tests/ui/impl-trait/in-trait/return-dont-satisfy-bounds.stderr b/tests/ui/impl-trait/in-trait/return-dont-satisfy-bounds.stderr index 638de01f91393..12725c3456fd5 100644 --- a/tests/ui/impl-trait/in-trait/return-dont-satisfy-bounds.stderr +++ b/tests/ui/impl-trait/in-trait/return-dont-satisfy-bounds.stderr @@ -5,11 +5,11 @@ LL | fn foo>(self) -> impl Foo { | ^^^^^^^^^^^^ the trait `Foo` is not implemented for `impl Foo` | = help: the trait `Foo` 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 | LL | fn foo(self) -> impl Foo; - | ^^^^^^ required by this bound in `Foo::{opaque#0}` + | ^^^^^^ required by this bound in `Foo::{synthetic#0}` error[E0276]: impl has stricter requirements than trait --> $DIR/return-dont-satisfy-bounds.rs:8:16 diff --git a/tests/ui/rfcs/rfc-1937-termination-trait/issue-103052-2.stderr b/tests/ui/rfcs/rfc-1937-termination-trait/issue-103052-2.stderr index 3fbbfd0fd0dbf..b17700ec6325d 100644 --- a/tests/ui/rfcs/rfc-1937-termination-trait/issue-103052-2.stderr +++ b/tests/ui/rfcs/rfc-1937-termination-trait/issue-103052-2.stderr @@ -4,11 +4,11 @@ error[E0277]: the trait bound `Something: Termination` is not satisfied LL | fn main() -> 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 | 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 From b57ddfe079cbd9974f0b1f68a50f8f1b901cfdaf Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 27 Feb 2024 16:11:35 +0000 Subject: [PATCH 2/2] Print RPITIT like an opaque --- compiler/rustc_middle/src/ty/print/pretty.rs | 20 +++++++++++-------- .../impl-trait/in-trait/async-and-ret-ref.rs | 2 +- .../in-trait/async-and-ret-ref.stderr | 4 ++-- .../missing-static-bound-from-impl.rs | 2 +- .../missing-static-bound-from-impl.stderr | 4 ++-- 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 1910841f2684e..87acca9e945a3 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -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:?}")), @@ -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)); + } + } } diff --git a/tests/ui/impl-trait/in-trait/async-and-ret-ref.rs b/tests/ui/impl-trait/in-trait/async-and-ret-ref.rs index e991b74a0f81a..e0a7aef2c5f44 100644 --- a/tests/ui/impl-trait/in-trait/async-and-ret-ref.rs +++ b/tests/ui/impl-trait/in-trait/async-and-ret-ref.rs @@ -5,7 +5,7 @@ trait T {} trait MyTrait { async fn foo() -> &'static impl T; - //~^ ERROR the associated type `::{opaque#0}` may not live long enough + //~^ ERROR the associated type `impl T` may not live long enough } fn main() {} diff --git a/tests/ui/impl-trait/in-trait/async-and-ret-ref.stderr b/tests/ui/impl-trait/in-trait/async-and-ret-ref.stderr index a17653496dbd2..19ffff9d3f2bd 100644 --- a/tests/ui/impl-trait/in-trait/async-and-ret-ref.stderr +++ b/tests/ui/impl-trait/in-trait/async-and-ret-ref.stderr @@ -1,10 +1,10 @@ -error[E0310]: the associated type `::{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 `::{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 diff --git a/tests/ui/impl-trait/in-trait/missing-static-bound-from-impl.rs b/tests/ui/impl-trait/in-trait/missing-static-bound-from-impl.rs index a36799c3ebd46..ee9ecdda90289 100644 --- a/tests/ui/impl-trait/in-trait/missing-static-bound-from-impl.rs +++ b/tests/ui/impl-trait/in-trait/missing-static-bound-from-impl.rs @@ -9,7 +9,7 @@ trait Erased { impl Erased for T { fn f(&self) -> Box { Box::new(::f()) - //~^ ERROR the associated type `::{opaque#0}` may not live long enough + //~^ ERROR the associated type `impl Fn()` may not live long enough } } diff --git a/tests/ui/impl-trait/in-trait/missing-static-bound-from-impl.stderr b/tests/ui/impl-trait/in-trait/missing-static-bound-from-impl.stderr index 7fa4b8dbd49cd..1f787c1842cf9 100644 --- a/tests/ui/impl-trait/in-trait/missing-static-bound-from-impl.stderr +++ b/tests/ui/impl-trait/in-trait/missing-static-bound-from-impl.stderr @@ -1,10 +1,10 @@ -error[E0310]: the associated type `::{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(::f()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | - | the associated type `::{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