Skip to content

Commit 270b776

Browse files
Adjust pretty printing of RPITITs
1 parent ec170be commit 270b776

File tree

5 files changed

+31
-11
lines changed

5 files changed

+31
-11
lines changed

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+14
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
6161
use rustc_errors::{pluralize, struct_span_err, Diagnostic, ErrorGuaranteed, IntoDiagnosticArg};
6262
use rustc_errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString, MultiSpan};
6363
use rustc_hir as hir;
64+
use rustc_hir::def::DefKind;
6465
use rustc_hir::def_id::{DefId, LocalDefId};
6566
use rustc_hir::lang_items::LangItem;
6667
use rustc_hir::Node;
@@ -1682,6 +1683,19 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
16821683
pos.col.to_usize() + 1,
16831684
)
16841685
}
1686+
(true, ty::Projection(proj))
1687+
if self.tcx.def_kind(proj.item_def_id)
1688+
== DefKind::ImplTraitPlaceholder =>
1689+
{
1690+
let sm = self.tcx.sess.source_map();
1691+
let pos = sm.lookup_char_pos(self.tcx.def_span(proj.item_def_id).lo());
1692+
format!(
1693+
" (trait associated opaque type at <{}:{}:{}>)",
1694+
sm.filename_for_diagnostics(&pos.file.name),
1695+
pos.line,
1696+
pos.col.to_usize() + 1,
1697+
)
1698+
}
16851699
(true, _) => format!(" ({})", ty.sort_string(self.tcx)),
16861700
(false, _) => "".to_string(),
16871701
};

compiler/rustc_middle/src/ty/print/pretty.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,13 @@ pub trait PrettyPrinter<'tcx>:
632632
ty::Foreign(def_id) => {
633633
p!(print_def_path(def_id, &[]));
634634
}
635-
ty::Projection(ref data) => p!(print(data)),
635+
ty::Projection(ref data) => {
636+
if self.tcx().def_kind(data.item_def_id) == DefKind::ImplTraitPlaceholder {
637+
return self.pretty_print_opaque_impl_type(data.item_def_id, data.substs);
638+
} else {
639+
p!(print(data))
640+
}
641+
}
636642
ty::Placeholder(placeholder) => p!(write("Placeholder({:?})", placeholder)),
637643
ty::Opaque(def_id, substs) => {
638644
// FIXME(eddyb) print this with `print_def_path`.

src/test/ui/async-await/async-trait-fn.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ LL | async fn foo() {}
4848
LL | pub const fn from_generator<T>(gen: T) -> impl Future<Output = T::Return>
4949
| ------------------------------- the found opaque type
5050
|
51-
= note: expected associated type `<Self as T>::foo::{opaque#0}`
52-
found opaque type `impl Future<Output = ()>`
51+
= note: expected associated type `impl Future<Output = ()>` (trait associated opaque type at <$DIR/async-trait-fn.rs:3:20>)
52+
found opaque type `impl Future<Output = ()>` (opaque type at <$SRC_DIR/core/src/future/mod.rs:LL:COL>)
5353

5454
error[E0308]: mismatched types
5555
--> $DIR/async-trait-fn.rs:5:25
@@ -62,8 +62,8 @@ LL | async fn bar(&self) {}
6262
LL | pub const fn from_generator<T>(gen: T) -> impl Future<Output = T::Return>
6363
| ------------------------------- the found opaque type
6464
|
65-
= note: expected associated type `<Self as T>::bar::{opaque#0}<'_>`
66-
found opaque type `impl Future<Output = ()>`
65+
= note: expected associated type `impl Future<Output = ()>` (trait associated opaque type at <$DIR/async-trait-fn.rs:5:25>)
66+
found opaque type `impl Future<Output = ()>` (opaque type at <$SRC_DIR/core/src/future/mod.rs:LL:COL>)
6767

6868
error[E0308]: mismatched types
6969
--> $DIR/async-trait-fn.rs:7:20
@@ -81,8 +81,8 @@ LL | | }
8181
LL | pub const fn from_generator<T>(gen: T) -> impl Future<Output = T::Return>
8282
| ------------------------------- the found opaque type
8383
|
84-
= note: expected associated type `<Self as T>::baz::{opaque#0}`
85-
found opaque type `impl Future<Output = ()>`
84+
= note: expected associated type `impl Future<Output = ()>` (trait associated opaque type at <$DIR/async-trait-fn.rs:7:20>)
85+
found opaque type `impl Future<Output = ()>` (opaque type at <$SRC_DIR/core/src/future/mod.rs:LL:COL>)
8686

8787
error: aborting due to 6 previous errors
8888

src/test/ui/async-await/edition-deny-async-fns-2015.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ LL | async fn foo() {}
103103
LL | pub const fn from_generator<T>(gen: T) -> impl Future<Output = T::Return>
104104
| ------------------------------- the found opaque type
105105
|
106-
= note: expected associated type `<Self as Bar>::foo::{opaque#0}`
107-
found opaque type `impl Future<Output = ()>`
106+
= note: expected associated type `impl Future<Output = ()>` (trait associated opaque type at <$DIR/edition-deny-async-fns-2015.rs:18:20>)
107+
found opaque type `impl Future<Output = ()>` (opaque type at <$SRC_DIR/core/src/future/mod.rs:LL:COL>)
108108

109109
error: aborting due to 11 previous errors
110110

src/test/ui/span/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ LL | trait C{async fn new(val: T) {}
8585
LL | pub const fn from_generator<T>(gen: T) -> impl Future<Output = T::Return>
8686
| ------------------------------- the found opaque type
8787
|
88-
= note: expected associated type `<Self as C>::new::{opaque#0}`
89-
found opaque type `impl Future<Output = ()>`
88+
= 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>)
89+
found opaque type `impl Future<Output = ()>` (opaque type at <$SRC_DIR/core/src/future/mod.rs:LL:COL>)
9090

9191
warning: changes to closure capture in Rust 2021 will affect drop order
9292
--> $DIR/drop-location-span-error-rust-2021-incompatible-closure-captures-93117.rs:13:30

0 commit comments

Comments
 (0)