diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-05-01 01:09:47 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-01 01:09:47 +0200 |
| commit | 1b262b8b5660bc70530f647822b477a8d56e1f4e (patch) | |
| tree | 41299c6d6c037d6b6addf13a984f9220fba45cd0 /compiler/rustc_ast_lowering/src/expr.rs | |
| parent | 9ecda8de85ce893cc3fc748ab06be0b8250147a7 (diff) | |
| parent | 6d6c90443182e18fb23c08cd2d97dae701d7b453 (diff) | |
| download | rust-1b262b8b5660bc70530f647822b477a8d56e1f4e.tar.gz rust-1b262b8b5660bc70530f647822b477a8d56e1f4e.zip | |
Rollup merge of #110823 - compiler-errors:tweak-await-span, r=b-naber
Tweak await span to not contain dot Fixes a discrepancy between method calls and await expressions where the latter are desugared to have a span that *contains* the dot (i.e. `.await`) but method call identifiers don't contain the dot. This leads to weird suggestions suggestions in borrowck -- see linked issue. Fixes #110761 This mostly touches a bunch of tests to tighten their `await` span.
Diffstat (limited to 'compiler/rustc_ast_lowering/src/expr.rs')
| -rw-r--r-- | compiler/rustc_ast_lowering/src/expr.rs | 24 |
1 files changed, 5 insertions, 19 deletions
diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index 7a0a7da9695..5e0ab80c6ac 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -185,21 +185,7 @@ impl<'hir> LoweringContext<'_, 'hir> { hir::AsyncGeneratorKind::Block, |this| this.with_new_scopes(|this| this.lower_block_expr(block)), ), - ExprKind::Await(expr) => { - let dot_await_span = if expr.span.hi() < e.span.hi() { - let span_with_whitespace = self - .tcx - .sess - .source_map() - .span_extend_while(expr.span, char::is_whitespace) - .unwrap_or(expr.span); - span_with_whitespace.shrink_to_hi().with_hi(e.span.hi()) - } else { - // this is a recovered `await expr` - e.span - }; - self.lower_expr_await(dot_await_span, expr) - } + ExprKind::Await(expr, await_kw_span) => self.lower_expr_await(*await_kw_span, expr), ExprKind::Closure(box Closure { binder, capture_clause, @@ -710,18 +696,18 @@ impl<'hir> LoweringContext<'_, 'hir> { /// } /// } /// ``` - fn lower_expr_await(&mut self, dot_await_span: Span, expr: &Expr) -> hir::ExprKind<'hir> { - let full_span = expr.span.to(dot_await_span); + fn lower_expr_await(&mut self, await_kw_span: Span, expr: &Expr) -> hir::ExprKind<'hir> { + let full_span = expr.span.to(await_kw_span); match self.generator_kind { Some(hir::GeneratorKind::Async(_)) => {} Some(hir::GeneratorKind::Gen) | None => { self.tcx.sess.emit_err(AwaitOnlyInAsyncFnAndBlocks { - dot_await_span, + await_kw_span, item_span: self.current_item, }); } } - let span = self.mark_span_with_reason(DesugaringKind::Await, dot_await_span, None); + let span = self.mark_span_with_reason(DesugaringKind::Await, await_kw_span, None); let gen_future_span = self.mark_span_with_reason( DesugaringKind::Await, full_span, |
