Skip to content

Commit

Permalink
Rollup merge of #117019 - lukas-code:for-await, r=compiler-errors
Browse files Browse the repository at this point in the history
fix spans for removing `.await` on `for` expressions

We need to use a span with the outer syntax context of a desugared `for` expression to join it with the `.await` span.

fixes #117014
  • Loading branch information
matthiaskrgr committed Oct 21, 2023
2 parents 3051dde + ccc4638 commit bd1046d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1644,7 +1644,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {

// use nth(1) to skip one layer of desugaring from `IntoIter::into_iter`
if let Some((_, hir::Node::Expr(await_expr))) = hir.parent_iter(*hir_id).nth(1)
&& let Some(expr_span) = expr.span.find_ancestor_inside(await_expr.span)
&& let Some(expr_span) = expr.span.find_ancestor_inside_same_ctxt(await_expr.span)
{
let removal_span = self
.tcx
Expand Down
5 changes: 5 additions & 0 deletions tests/ui/async-await/unnecessary-await.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,9 @@ async fn with_macros() {
f!(());
}

// Regression test for issue #117014.
async fn desugaring_span_ctxt() {
for x in [] {}.await //~ ERROR `()` is not a future
}

fn main() {}
15 changes: 14 additions & 1 deletion tests/ui/async-await/unnecessary-await.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ LL | f!(());
= note: required for `()` to implement `IntoFuture`
= note: this error originates in the macro `f` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 3 previous errors
error[E0277]: `()` is not a future
--> $DIR/unnecessary-await.rs:36:20
|
LL | for x in [] {}.await
| -^^^^^
| ||
| |`()` is not a future
| help: remove the `.await`
|
= help: the trait `Future` is not implemented for `()`
= note: () must be a future or must implement `IntoFuture` to be awaited
= note: required for `()` to implement `IntoFuture`

error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0277`.

0 comments on commit bd1046d

Please sign in to comment.