Skip to content

Commit ccc4638

Browse files
author
Lukas Markeffsky
committed
fix spans for removing .await on for expressions
1 parent 6f97d83 commit ccc4638

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1644,7 +1644,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
16441644

16451645
// use nth(1) to skip one layer of desugaring from `IntoIter::into_iter`
16461646
if let Some((_, hir::Node::Expr(await_expr))) = hir.parent_iter(*hir_id).nth(1)
1647-
&& let Some(expr_span) = expr.span.find_ancestor_inside(await_expr.span)
1647+
&& let Some(expr_span) = expr.span.find_ancestor_inside_same_ctxt(await_expr.span)
16481648
{
16491649
let removal_span = self
16501650
.tcx

tests/ui/async-await/unnecessary-await.rs

+5
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,9 @@ async fn with_macros() {
3131
f!(());
3232
}
3333

34+
// Regression test for issue #117014.
35+
async fn desugaring_span_ctxt() {
36+
for x in [] {}.await //~ ERROR `()` is not a future
37+
}
38+
3439
fn main() {}

tests/ui/async-await/unnecessary-await.stderr

+14-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,19 @@ LL | f!(());
4949
= note: required for `()` to implement `IntoFuture`
5050
= note: this error originates in the macro `f` (in Nightly builds, run with -Z macro-backtrace for more info)
5151

52-
error: aborting due to 3 previous errors
52+
error[E0277]: `()` is not a future
53+
--> $DIR/unnecessary-await.rs:36:20
54+
|
55+
LL | for x in [] {}.await
56+
| -^^^^^
57+
| ||
58+
| |`()` is not a future
59+
| help: remove the `.await`
60+
|
61+
= help: the trait `Future` is not implemented for `()`
62+
= note: () must be a future or must implement `IntoFuture` to be awaited
63+
= note: required for `()` to implement `IntoFuture`
64+
65+
error: aborting due to 4 previous errors
5366

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

0 commit comments

Comments
 (0)