Skip to content

Commit 9aeaaa2

Browse files
committed
Include type info when available for awaited expr
1 parent 4687b8d commit 9aeaaa2

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/librustc_trait_selection/traits/error_reporting/suggestions.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -1263,10 +1263,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
12631263
)
12641264
};
12651265

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

1280-
if target_span != await_span {
1281-
push_target_span(&mut span);
1279+
if target_span == await_span {
1280+
push_target_span_with_fallback(&mut span, "await occurs here");
1281+
} else {
1282+
span.push_span_label(await_span, "await occurs here".to_string());
1283+
push_target_span_with_fallback(&mut span, "created here");
12821284
}
12831285

12841286
err.span_note(
@@ -1298,7 +1300,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
12981300
format!("{} occurs here, with `{}` maybe used later", await_or_yield, snippet),
12991301
);
13001302

1301-
push_target_span(&mut span);
1303+
push_target_span_with_fallback(&mut span, "created here");
13021304

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

0 commit comments

Comments
 (0)