Skip to content

Commit fe2c6b1

Browse files
committed
Opaque type locations in error message for clarity.
1 parent b505208 commit fe2c6b1

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/librustc/infer/error_reporting/mod.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ use crate::ty::error::TypeError;
6060
use crate::ty::{self, subst::{Subst, SubstsRef}, Region, Ty, TyCtxt, TypeFoldable};
6161
use errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString};
6262
use std::{cmp, fmt};
63+
use std::borrow::Cow;
6364
use syntax_pos::{Pos, Span};
6465

6566
mod note;
@@ -1140,8 +1141,20 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
11401141
&"type",
11411142
expected,
11421143
found,
1143-
&format!(" ({})", values.expected.sort_string(self.tcx)),
1144-
&format!(" ({})", values.found.sort_string(self.tcx)),
1144+
&format!(" ({})",
1145+
if let ty::Opaque(def_id, _) = values.expected.sty {
1146+
Cow::from(format!("opaque type at {}", self.tcx.sess
1147+
.source_map().mk_substr_filename(self.tcx.def_span(def_id))))
1148+
} else {
1149+
values.expected.sort_string(self.tcx)
1150+
}),
1151+
&format!(" ({})",
1152+
if let ty::Opaque(def_id, _) = values.found.sty {
1153+
Cow::from(format!("opaque type at {}", self.tcx.sess
1154+
.source_map().mk_substr_filename(self.tcx.def_span(def_id))))
1155+
} else {
1156+
values.found.sort_string(self.tcx)
1157+
}),
11451158
);
11461159
}
11471160
(_, false, _) => {

src/test/ui/suggestions/opaque-type-error.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ LL | | thing_two()
1010
LL | | }.await
1111
| |_____- if and else have incompatible types
1212
|
13-
= note: expected type `impl std::future::Future` (opaque type)
14-
found type `impl std::future::Future` (opaque type)
13+
= note: expected type `impl std::future::Future` (opaque type at <$DIR/opaque-type-error.rs:8:19>)
14+
found type `impl std::future::Future` (opaque type at <$DIR/opaque-type-error.rs:12:19>)
1515
= note: distinct uses of `impl Trait` result in different opaque types
1616
= help: if both `Future`s have the same `Output` type, consider `.await`ing on both of them
1717

0 commit comments

Comments
 (0)