Skip to content

Commit cc696b9

Browse files
authored
Rollup merge of rust-lang#62383 - Aaron1011:fix/async-error-span, r=varkor
Improve error span for async type inference error Fixes rust-lang#62382 Previously, we would point at the spawn of the 'await' expression, instead of the actual expression with an unknown type.
2 parents ccd925b + 779308a commit cc696b9

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

src/librustc_typeck/check/generator_interior.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl<'a, 'tcx> InteriorVisitor<'a, 'tcx> {
7575
// If unresolved type isn't a ty_var then unresolved_type_span is None
7676
self.fcx.need_type_info_err_in_generator(
7777
self.kind,
78-
unresolved_type_span.unwrap_or(yield_data.span),
78+
unresolved_type_span.unwrap_or(source_span),
7979
unresolved_type,
8080
)
8181
.span_note(yield_data.span, &*note)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// edition:2018
2+
#![feature(async_await)]
3+
4+
// Regression test for issue #62382
5+
6+
use std::future::Future;
7+
8+
fn get_future() -> impl Future<Output = ()> {
9+
panic!()
10+
}
11+
12+
async fn foo() {
13+
let a; //~ ERROR type inside `async` object must be known in this context
14+
get_future().await;
15+
}
16+
17+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0698]: type inside `async` object must be known in this context
2+
--> $DIR/async-error-span.rs:13:9
3+
|
4+
LL | let a;
5+
| ^ cannot infer type
6+
|
7+
note: the type is part of the `async` object because of this `await`
8+
--> $DIR/async-error-span.rs:14:5
9+
|
10+
LL | get_future().await;
11+
| ^^^^^^^^^^^^^^^^^^
12+
13+
error: aborting due to previous error
14+
15+
For more information about this error, try `rustc --explain E0698`.

0 commit comments

Comments
 (0)