Skip to content

Commit

Permalink
Include type info when available for awaited expr
Browse files Browse the repository at this point in the history
  • Loading branch information
tmandry committed Apr 14, 2020
1 parent 8ce334d commit df0a16b
Showing 1 changed file with 8 additions and 6 deletions.
Expand Up @@ -1378,10 +1378,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
)
};

let push_target_span = |span: &mut MultiSpan| {
let push_target_span_with_fallback = |span: &mut MultiSpan, fallback: &str| {
if target_ty.is_impl_trait() {
// It's not very useful to tell the user the type if it's opaque.
span.push_span_label(target_span, "created here".to_string());
span.push_span_label(target_span, fallback.to_string());
} else {
span.push_span_label(target_span, format!("has type `{}`", target_ty));
}
Expand All @@ -1390,10 +1390,12 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
if let Some(await_span) = from_awaited_ty {
// The type causing this obligation is one being awaited at await_span.
let mut span = MultiSpan::from_span(await_span);
span.push_span_label(await_span, "await occurs here".to_string());

if target_span != await_span {
push_target_span(&mut span);
if target_span == await_span {
push_target_span_with_fallback(&mut span, "await occurs here");
} else {
span.push_span_label(await_span, "await occurs here".to_string());
push_target_span_with_fallback(&mut span, "created here");
}

err.span_note(
Expand All @@ -1413,7 +1415,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
format!("{} occurs here, with `{}` maybe used later", await_or_yield, snippet),
);

push_target_span(&mut span);
push_target_span_with_fallback(&mut span, "created here");

// If available, use the scope span to annotate the drop location.
if let Some(scope_span) = scope_span {
Expand Down

0 comments on commit df0a16b

Please sign in to comment.