Skip to content

Commit

Permalink
Rollup merge of rust-lang#64157 - gilescope:opaque-type-location, r=c…
Browse files Browse the repository at this point in the history
…ramertj

Opaque type locations in error message for clarity.

Attempts to fix rust-lang#63167
  • Loading branch information
Centril authored Sep 5, 2019
2 parents cecca35 + fe2c6b1 commit 00c3f67
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
17 changes: 15 additions & 2 deletions src/librustc/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ use crate::ty::error::TypeError;
use crate::ty::{self, subst::{Subst, SubstsRef}, Region, Ty, TyCtxt, TypeFoldable};
use errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString};
use std::{cmp, fmt};
use std::borrow::Cow;
use syntax_pos::{Pos, Span};

mod note;
Expand Down Expand Up @@ -1140,8 +1141,20 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
&"type",
expected,
found,
&format!(" ({})", values.expected.sort_string(self.tcx)),
&format!(" ({})", values.found.sort_string(self.tcx)),
&format!(" ({})",
if let ty::Opaque(def_id, _) = values.expected.sty {
Cow::from(format!("opaque type at {}", self.tcx.sess
.source_map().mk_substr_filename(self.tcx.def_span(def_id))))
} else {
values.expected.sort_string(self.tcx)
}),
&format!(" ({})",
if let ty::Opaque(def_id, _) = values.found.sty {
Cow::from(format!("opaque type at {}", self.tcx.sess
.source_map().mk_substr_filename(self.tcx.def_span(def_id))))
} else {
values.found.sort_string(self.tcx)
}),
);
}
(_, false, _) => {
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/suggestions/opaque-type-error.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 00c3f67

Please sign in to comment.