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
This commit is contained in:
commit
8dc4b26b60
@ -146,13 +146,19 @@ pub(super) fn lower_expr_mut(&mut self, e: &Expr) -> hir::Expr<'hir> {
|
|||||||
|this| this.with_new_scopes(|this| this.lower_block_expr(block)),
|
|this| this.with_new_scopes(|this| this.lower_block_expr(block)),
|
||||||
),
|
),
|
||||||
ExprKind::Await(ref expr) => {
|
ExprKind::Await(ref expr) => {
|
||||||
let span = if expr.span.hi() < e.span.hi() {
|
let dot_await_span = if expr.span.hi() < e.span.hi() {
|
||||||
expr.span.shrink_to_hi().with_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 {
|
} else {
|
||||||
// this is a recovered `await expr`
|
// this is a recovered `await expr`
|
||||||
e.span
|
e.span
|
||||||
};
|
};
|
||||||
self.lower_expr_await(span, expr)
|
self.lower_expr_await(dot_await_span, expr)
|
||||||
}
|
}
|
||||||
ExprKind::Closure(
|
ExprKind::Closure(
|
||||||
ref binder,
|
ref binder,
|
||||||
|
@ -1160,8 +1160,8 @@ fn suggest_remove_await(&self, obligation: &PredicateObligation<'tcx>, err: &mut
|
|||||||
// and if not maybe suggest doing something else? If we kept the expression around we
|
// 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
|
// could also check if it is an fn call (very likely) and suggest changing *that*, if
|
||||||
// it is from the local crate.
|
// it is from the local crate.
|
||||||
err.span_suggestion_verbose(
|
err.span_suggestion(
|
||||||
expr.span.shrink_to_hi().with_hi(span.hi()),
|
span,
|
||||||
"remove the `.await`",
|
"remove the `.await`",
|
||||||
"",
|
"",
|
||||||
Applicability::MachineApplicable,
|
Applicability::MachineApplicable,
|
||||||
|
17
src/test/ui/async-await/issue-101715.rs
Normal file
17
src/test/ui/async-await/issue-101715.rs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
// edition:2018
|
||||||
|
|
||||||
|
struct S;
|
||||||
|
|
||||||
|
impl S {
|
||||||
|
fn very_long_method_name_the_longest_method_name_in_the_whole_universe(self) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn foo() {
|
||||||
|
S.very_long_method_name_the_longest_method_name_in_the_whole_universe()
|
||||||
|
.await
|
||||||
|
//~^ error: `()` is not a future
|
||||||
|
//~| help: remove the `.await`
|
||||||
|
//~| help: the trait `Future` is not implemented for `()`
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
16
src/test/ui/async-await/issue-101715.stderr
Normal file
16
src/test/ui/async-await/issue-101715.stderr
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
error[E0277]: `()` is not a future
|
||||||
|
--> $DIR/issue-101715.rs:11:9
|
||||||
|
|
|
||||||
|
LL | .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 previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0277`.
|
@ -22,16 +22,14 @@ error[E0277]: `()` is not a future
|
|||||||
--> $DIR/issue-70594.rs:4:11
|
--> $DIR/issue-70594.rs:4:11
|
||||||
|
|
|
|
||||||
LL | [1; ().await];
|
LL | [1; ().await];
|
||||||
| ^^^^^^ `()` is not a future
|
| ^^^^^^
|
||||||
|
| |
|
||||||
|
| `()` is not a future
|
||||||
|
| help: remove the `.await`
|
||||||
|
|
|
|
||||||
= help: the trait `Future` is not implemented for `()`
|
= help: the trait `Future` is not implemented for `()`
|
||||||
= note: () must be a future or must implement `IntoFuture` to be awaited
|
= note: () must be a future or must implement `IntoFuture` to be awaited
|
||||||
= note: required for `()` to implement `IntoFuture`
|
= note: required for `()` to implement `IntoFuture`
|
||||||
help: remove the `.await`
|
|
||||||
|
|
|
||||||
LL - [1; ().await];
|
|
||||||
LL + [1; ()];
|
|
||||||
|
|
|
||||||
|
|
||||||
error: aborting due to 4 previous errors
|
error: aborting due to 4 previous errors
|
||||||
|
|
||||||
|
@ -28,16 +28,14 @@ error[E0277]: `[closure@$DIR/issue-62009-1.rs:12:6: 12:9]` is not a future
|
|||||||
--> $DIR/issue-62009-1.rs:12:15
|
--> $DIR/issue-62009-1.rs:12:15
|
||||||
|
|
|
|
||||||
LL | (|_| 2333).await;
|
LL | (|_| 2333).await;
|
||||||
| ^^^^^^ `[closure@$DIR/issue-62009-1.rs:12:6: 12:9]` is not a future
|
| ^^^^^^
|
||||||
|
| |
|
||||||
|
| `[closure@$DIR/issue-62009-1.rs:12:6: 12:9]` is not a future
|
||||||
|
| help: remove the `.await`
|
||||||
|
|
|
|
||||||
= help: the trait `Future` is not implemented for closure `[closure@$DIR/issue-62009-1.rs:12:6: 12:9]`
|
= help: the trait `Future` is not implemented for closure `[closure@$DIR/issue-62009-1.rs:12:6: 12:9]`
|
||||||
= note: [closure@$DIR/issue-62009-1.rs:12:6: 12:9] must be a future or must implement `IntoFuture` to be awaited
|
= note: [closure@$DIR/issue-62009-1.rs:12:6: 12:9] must be a future or must implement `IntoFuture` to be awaited
|
||||||
= note: required for `[closure@$DIR/issue-62009-1.rs:12:6: 12:9]` to implement `IntoFuture`
|
= note: required for `[closure@$DIR/issue-62009-1.rs:12:6: 12:9]` to implement `IntoFuture`
|
||||||
help: remove the `.await`
|
|
||||||
|
|
|
||||||
LL - (|_| 2333).await;
|
|
||||||
LL + (|_| 2333);
|
|
||||||
|
|
|
||||||
|
|
||||||
error: aborting due to 4 previous errors
|
error: aborting due to 4 previous errors
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user