Add missing check for async body when suggesting await on futures.
This commit is contained in:
parent
a48e7b0057
commit
ab2c8ffda9
4 changed files with 12 additions and 19 deletions
|
@ -167,6 +167,18 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
exp_span, exp_found.expected, exp_found.found,
|
exp_span, exp_found.expected, exp_found.found,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
match self.tcx.coroutine_kind(cause.body_id) {
|
||||||
|
Some(hir::CoroutineKind::Desugared(
|
||||||
|
hir::CoroutineDesugaring::Async | hir::CoroutineDesugaring::AsyncGen,
|
||||||
|
_,
|
||||||
|
)) => (),
|
||||||
|
None
|
||||||
|
| Some(
|
||||||
|
hir::CoroutineKind::Coroutine(_)
|
||||||
|
| hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Gen, _),
|
||||||
|
) => return,
|
||||||
|
}
|
||||||
|
|
||||||
if let ObligationCauseCode::CompareImplItem { .. } = cause.code() {
|
if let ObligationCauseCode::CompareImplItem { .. } = cause.code() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,6 @@ LL | fun(one(), two());
|
||||||
| | expected all arguments to be this future type because they need to match the type of this parameter
|
| | expected all arguments to be this future type because they need to match the type of this parameter
|
||||||
| arguments to this function are incorrect
|
| arguments to this function are incorrect
|
||||||
|
|
|
|
||||||
= help: consider `await`ing on both `Future`s
|
|
||||||
= note: distinct uses of `impl Trait` result in different opaque types
|
= note: distinct uses of `impl Trait` result in different opaque types
|
||||||
note: function defined here
|
note: function defined here
|
||||||
--> $DIR/coroutine-desc.rs:7:4
|
--> $DIR/coroutine-desc.rs:7:4
|
||||||
|
|
|
@ -6,20 +6,11 @@ LL | take_u32(x)
|
||||||
| |
|
| |
|
||||||
| arguments to this function are incorrect
|
| arguments to this function are incorrect
|
||||||
|
|
|
|
||||||
note: calling an async function returns a future
|
|
||||||
--> $DIR/dont-suggest-missing-await.rs:14:18
|
|
||||||
|
|
|
||||||
LL | take_u32(x)
|
|
||||||
| ^
|
|
||||||
note: function defined here
|
note: function defined here
|
||||||
--> $DIR/dont-suggest-missing-await.rs:5:4
|
--> $DIR/dont-suggest-missing-await.rs:5:4
|
||||||
|
|
|
|
||||||
LL | fn take_u32(x: u32) {}
|
LL | fn take_u32(x: u32) {}
|
||||||
| ^^^^^^^^ ------
|
| ^^^^^^^^ ------
|
||||||
help: consider `await`ing on the `Future`
|
|
||||||
|
|
|
||||||
LL | take_u32(x.await)
|
|
||||||
| ++++++
|
|
||||||
|
|
||||||
error: aborting due to 1 previous error
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
|
|
@ -14,20 +14,11 @@ LL | convert_result(foo())
|
||||||
| |
|
| |
|
||||||
| arguments to this function are incorrect
|
| arguments to this function are incorrect
|
||||||
|
|
|
|
||||||
note: calling an async function returns a future
|
|
||||||
--> $DIR/issue-102605.rs:13:20
|
|
||||||
|
|
|
||||||
LL | convert_result(foo())
|
|
||||||
| ^^^^^
|
|
||||||
note: function defined here
|
note: function defined here
|
||||||
--> $DIR/issue-102605.rs:7:4
|
--> $DIR/issue-102605.rs:7:4
|
||||||
|
|
|
|
||||||
LL | fn convert_result<T, E>(r: Result<T, E>) -> Option<T> {
|
LL | fn convert_result<T, E>(r: Result<T, E>) -> Option<T> {
|
||||||
| ^^^^^^^^^^^^^^ ---------------
|
| ^^^^^^^^^^^^^^ ---------------
|
||||||
help: consider `await`ing on the `Future`
|
|
||||||
|
|
|
||||||
LL | convert_result(foo().await)
|
|
||||||
| ++++++
|
|
||||||
help: try wrapping the expression in `Err`
|
help: try wrapping the expression in `Err`
|
||||||
|
|
|
|
||||||
LL | convert_result(Err(foo()))
|
LL | convert_result(Err(foo()))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue