diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2022-09-12 22:47:15 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-09-12 22:47:15 +0200 |
| commit | 8dc4b26b60bd366f260e453c1c48504eabd3219e (patch) | |
| tree | f3ffe80d5c5f15dd0b42b6ef0da77106725e80d2 /compiler | |
| parent | 57273313ae0a2f3be31caf2cf4c4da219e1115ba (diff) | |
| parent | 2b7fb8d9418dbf98e6ee8ed406f830b4fcbea55f (diff) | |
| download | rust-8dc4b26b60bd366f260e453c1c48504eabd3219e.tar.gz rust-8dc4b26b60bd366f260e453c1c48504eabd3219e.zip | |
Rollup merge of #101723 - lukas-code:await-diag, r=compiler-errors
Impove diagnostic for `.await`ing non-futures Strip leading whitespace from the span and use a non-verbose suggestion. fixes #101715
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_ast_lowering/src/expr.rs | 12 | ||||
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs | 4 |
2 files changed, 11 insertions, 5 deletions
diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index f929549d704..cd03e3fb457 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -146,13 +146,19 @@ impl<'hir> LoweringContext<'_, 'hir> { |this| this.with_new_scopes(|this| this.lower_block_expr(block)), ), ExprKind::Await(ref expr) => { - let span = if expr.span.hi() < e.span.hi() { - expr.span.shrink_to_hi().with_hi(e.span.hi()) + 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(span, expr) + self.lower_expr_await(dot_await_span, expr) } ExprKind::Closure( ref binder, diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index ecbeb9d79b1..cb605cacc9c 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -1160,8 +1160,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { // and if not maybe suggest doing something else? If we kept the expression around we // could also check if it is an fn call (very likely) and suggest changing *that*, if // it is from the local crate. - err.span_suggestion_verbose( - expr.span.shrink_to_hi().with_hi(span.hi()), + err.span_suggestion( + span, "remove the `.await`", "", Applicability::MachineApplicable, |
