diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-09-05 12:11:19 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-09-05 12:11:19 +0200 |
| commit | afc7e0e9d3945dbb9799752e3a83c749fdd26320 (patch) | |
| tree | df52f78d42b2e14c8574d2e7e7f564ef6ba08e94 | |
| parent | 23265741d33b9baff5ae0c50b328ccd54a3c1b47 (diff) | |
| parent | 9483db5052415464fcb59ab480479afdd35710a5 (diff) | |
| download | rust-afc7e0e9d3945dbb9799752e3a83c749fdd26320.tar.gz rust-afc7e0e9d3945dbb9799752e3a83c749fdd26320.zip | |
Rollup merge of #64157 - gilescope:opaque-type-location, r=cramertj,Centril
Opaque type locations in error message for clarity. Attempts to fix #63167
| -rw-r--r-- | src/librustc/infer/error_reporting/mod.rs | 11 | ||||
| -rw-r--r-- | src/test/ui/suggestions/opaque-type-error.stderr | 4 |
2 files changed, 11 insertions, 4 deletions
diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index bf9cb79fb8a..5883be6e268 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -1136,12 +1136,19 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { if let Some((expected, found)) = expected_found { match (terr, is_simple_error, expected == found) { (&TypeError::Sorts(ref values), false, true) => { + let sort_string = | a_type: Ty<'tcx> | + if let ty::Opaque(def_id, _) = a_type.sty { + format!(" (opaque type at {})", self.tcx.sess.source_map() + .mk_substr_filename(self.tcx.def_span(def_id))) + } else { + format!(" ({})", a_type.sort_string(self.tcx)) + }; diag.note_expected_found_extra( &"type", expected, found, - &format!(" ({})", values.expected.sort_string(self.tcx)), - &format!(" ({})", values.found.sort_string(self.tcx)), + &sort_string(values.expected), + &sort_string(values.found), ); } (_, false, _) => { diff --git a/src/test/ui/suggestions/opaque-type-error.stderr b/src/test/ui/suggestions/opaque-type-error.stderr index 3c9ea05aece..450cbd4799f 100644 --- a/src/test/ui/suggestions/opaque-type-error.stderr +++ b/src/test/ui/suggestions/opaque-type-error.stderr @@ -10,8 +10,8 @@ LL | | thing_two() LL | | }.await | |_____- if and else have incompatible types | - = note: expected type `impl std::future::Future` (opaque type) - found type `impl std::future::Future` (opaque type) + = note: expected type `impl std::future::Future` (opaque type at <$DIR/opaque-type-error.rs:8:19>) + found type `impl std::future::Future` (opaque type at <$DIR/opaque-type-error.rs:12:19>) = note: distinct uses of `impl Trait` result in different opaque types = help: if both `Future`s have the same `Output` type, consider `.await`ing on both of them |
