Adjust pretty printing of RPITITs

This commit is contained in:
Michael Goulet 2022-09-08 00:45:09 +00:00
parent ec170bef0d
commit 270b776ef9
5 changed files with 31 additions and 11 deletions

View File

@ -61,6 +61,7 @@
use rustc_errors::{pluralize, struct_span_err, Diagnostic, ErrorGuaranteed, IntoDiagnosticArg}; use rustc_errors::{pluralize, struct_span_err, Diagnostic, ErrorGuaranteed, IntoDiagnosticArg};
use rustc_errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString, MultiSpan}; use rustc_errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString, MultiSpan};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::lang_items::LangItem; use rustc_hir::lang_items::LangItem;
use rustc_hir::Node; use rustc_hir::Node;
@ -1682,6 +1683,19 @@ enum Mismatch<'a> {
pos.col.to_usize() + 1, pos.col.to_usize() + 1,
) )
} }
(true, ty::Projection(proj))
if self.tcx.def_kind(proj.item_def_id)
== DefKind::ImplTraitPlaceholder =>
{
let sm = self.tcx.sess.source_map();
let pos = sm.lookup_char_pos(self.tcx.def_span(proj.item_def_id).lo());
format!(
" (trait associated opaque type at <{}:{}:{}>)",
sm.filename_for_diagnostics(&pos.file.name),
pos.line,
pos.col.to_usize() + 1,
)
}
(true, _) => format!(" ({})", ty.sort_string(self.tcx)), (true, _) => format!(" ({})", ty.sort_string(self.tcx)),
(false, _) => "".to_string(), (false, _) => "".to_string(),
}; };

View File

@ -632,7 +632,13 @@ fn pretty_print_type(mut self, ty: Ty<'tcx>) -> Result<Self::Type, Self::Error>
ty::Foreign(def_id) => { ty::Foreign(def_id) => {
p!(print_def_path(def_id, &[])); p!(print_def_path(def_id, &[]));
} }
ty::Projection(ref data) => p!(print(data)), ty::Projection(ref data) => {
if self.tcx().def_kind(data.item_def_id) == DefKind::ImplTraitPlaceholder {
return self.pretty_print_opaque_impl_type(data.item_def_id, data.substs);
} else {
p!(print(data))
}
}
ty::Placeholder(placeholder) => p!(write("Placeholder({:?})", placeholder)), ty::Placeholder(placeholder) => p!(write("Placeholder({:?})", placeholder)),
ty::Opaque(def_id, substs) => { ty::Opaque(def_id, substs) => {
// FIXME(eddyb) print this with `print_def_path`. // FIXME(eddyb) print this with `print_def_path`.

View File

@ -48,8 +48,8 @@ LL | async fn foo() {}
LL | pub const fn from_generator<T>(gen: T) -> impl Future<Output = T::Return> LL | pub const fn from_generator<T>(gen: T) -> impl Future<Output = T::Return>
| ------------------------------- the found opaque type | ------------------------------- the found opaque type
| |
= note: expected associated type `<Self as T>::foo::{opaque#0}` = note: expected associated type `impl Future<Output = ()>` (trait associated opaque type at <$DIR/async-trait-fn.rs:3:20>)
found opaque type `impl Future<Output = ()>` found opaque type `impl Future<Output = ()>` (opaque type at <$SRC_DIR/core/src/future/mod.rs:LL:COL>)
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/async-trait-fn.rs:5:25 --> $DIR/async-trait-fn.rs:5:25
@ -62,8 +62,8 @@ LL | async fn bar(&self) {}
LL | pub const fn from_generator<T>(gen: T) -> impl Future<Output = T::Return> LL | pub const fn from_generator<T>(gen: T) -> impl Future<Output = T::Return>
| ------------------------------- the found opaque type | ------------------------------- the found opaque type
| |
= note: expected associated type `<Self as T>::bar::{opaque#0}<'_>` = note: expected associated type `impl Future<Output = ()>` (trait associated opaque type at <$DIR/async-trait-fn.rs:5:25>)
found opaque type `impl Future<Output = ()>` found opaque type `impl Future<Output = ()>` (opaque type at <$SRC_DIR/core/src/future/mod.rs:LL:COL>)
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/async-trait-fn.rs:7:20 --> $DIR/async-trait-fn.rs:7:20
@ -81,8 +81,8 @@ LL | | }
LL | pub const fn from_generator<T>(gen: T) -> impl Future<Output = T::Return> LL | pub const fn from_generator<T>(gen: T) -> impl Future<Output = T::Return>
| ------------------------------- the found opaque type | ------------------------------- the found opaque type
| |
= note: expected associated type `<Self as T>::baz::{opaque#0}` = note: expected associated type `impl Future<Output = ()>` (trait associated opaque type at <$DIR/async-trait-fn.rs:7:20>)
found opaque type `impl Future<Output = ()>` found opaque type `impl Future<Output = ()>` (opaque type at <$SRC_DIR/core/src/future/mod.rs:LL:COL>)
error: aborting due to 6 previous errors error: aborting due to 6 previous errors

View File

@ -103,8 +103,8 @@ LL | async fn foo() {}
LL | pub const fn from_generator<T>(gen: T) -> impl Future<Output = T::Return> LL | pub const fn from_generator<T>(gen: T) -> impl Future<Output = T::Return>
| ------------------------------- the found opaque type | ------------------------------- the found opaque type
| |
= note: expected associated type `<Self as Bar>::foo::{opaque#0}` = note: expected associated type `impl Future<Output = ()>` (trait associated opaque type at <$DIR/edition-deny-async-fns-2015.rs:18:20>)
found opaque type `impl Future<Output = ()>` found opaque type `impl Future<Output = ()>` (opaque type at <$SRC_DIR/core/src/future/mod.rs:LL:COL>)
error: aborting due to 11 previous errors error: aborting due to 11 previous errors

View File

@ -85,8 +85,8 @@ LL | trait C{async fn new(val: T) {}
LL | pub const fn from_generator<T>(gen: T) -> impl Future<Output = T::Return> LL | pub const fn from_generator<T>(gen: T) -> impl Future<Output = T::Return>
| ------------------------------- the found opaque type | ------------------------------- the found opaque type
| |
= note: expected associated type `<Self as C>::new::{opaque#0}` = note: expected associated type `impl Future<Output = ()>` (trait associated opaque type at <$DIR/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.rs:13:30>)
found opaque type `impl Future<Output = ()>` found opaque type `impl Future<Output = ()>` (opaque type at <$SRC_DIR/core/src/future/mod.rs:LL:COL>)
warning: changes to closure capture in Rust 2021 will affect drop order warning: changes to closure capture in Rust 2021 will affect drop order
--> $DIR/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.rs:13:30 --> $DIR/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.rs:13:30