Skip to content

Commit 44a6e39

Browse files
authored
Rollup merge of #64157 - gilescope:opaque-type-location, r=cramertj,Centril
Opaque type locations in error message for clarity. Attempts to fix #63167
2 parents 15aeb27 + 9483db5 commit 44a6e39

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/librustc/infer/error_reporting/mod.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -1136,12 +1136,19 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
11361136
if let Some((expected, found)) = expected_found {
11371137
match (terr, is_simple_error, expected == found) {
11381138
(&TypeError::Sorts(ref values), false, true) => {
1139+
let sort_string = | a_type: Ty<'tcx> |
1140+
if let ty::Opaque(def_id, _) = a_type.sty {
1141+
format!(" (opaque type at {})", self.tcx.sess.source_map()
1142+
.mk_substr_filename(self.tcx.def_span(def_id)))
1143+
} else {
1144+
format!(" ({})", a_type.sort_string(self.tcx))
1145+
};
11391146
diag.note_expected_found_extra(
11401147
&"type",
11411148
expected,
11421149
found,
1143-
&format!(" ({})", values.expected.sort_string(self.tcx)),
1144-
&format!(" ({})", values.found.sort_string(self.tcx)),
1150+
&sort_string(values.expected),
1151+
&sort_string(values.found),
11451152
);
11461153
}
11471154
(_, 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)