mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
Tweak "use .await
" suggestion
This commit is contained in:
parent
07a63e6d1f
commit
86df9039b2
@ -21,7 +21,7 @@ use rustc_middle::ty::{
|
||||
};
|
||||
use rustc_middle::ty::{TypeAndMut, TypeckResults};
|
||||
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||
use rustc_span::{MultiSpan, Span, DUMMY_SP};
|
||||
use rustc_span::{BytePos, MultiSpan, Span, DUMMY_SP};
|
||||
use rustc_target::spec::abi;
|
||||
use std::fmt;
|
||||
|
||||
@ -2114,10 +2114,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||
if self.predicate_may_hold(&try_obligation) && impls_future {
|
||||
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) {
|
||||
if snippet.ends_with('?') {
|
||||
err.span_suggestion(
|
||||
span,
|
||||
"consider using `.await` here",
|
||||
format!("{}.await?", snippet.trim_end_matches('?')),
|
||||
err.span_suggestion_verbose(
|
||||
span.with_hi(span.hi() - BytePos(1)).shrink_to_hi(),
|
||||
"consider `await`ing on the `Future`",
|
||||
".await".to_string(),
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
}
|
||||
|
@ -497,16 +497,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
|
||||
if self.infcx.predicate_may_hold(&obligation) {
|
||||
debug!("suggest_missing_await: obligation held: {:?}", obligation);
|
||||
if let Ok(code) = self.sess().source_map().span_to_snippet(sp) {
|
||||
err.span_suggestion(
|
||||
sp,
|
||||
"consider using `.await` here",
|
||||
format!("{}.await", code),
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
} else {
|
||||
debug!("suggest_missing_await: no snippet for {:?}", sp);
|
||||
}
|
||||
err.span_suggestion_verbose(
|
||||
sp.shrink_to_hi(),
|
||||
"consider `await`ing on the `Future`",
|
||||
".await".to_string(),
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
} else {
|
||||
debug!("suggest_missing_await: obligation did not hold: {:?}", obligation)
|
||||
}
|
||||
|
@ -237,13 +237,14 @@ error[E0277]: the `?` operator can only be applied to values that implement `Try
|
||||
--> $DIR/incorrect-syntax-suggestions.rs:16:19
|
||||
|
|
||||
LL | let _ = await bar()?;
|
||||
| ^^^^^^
|
||||
| |
|
||||
| the `?` operator cannot be applied to type `impl Future`
|
||||
| help: consider using `.await` here: `bar().await?`
|
||||
| ^^^^^^ the `?` operator cannot be applied to type `impl Future`
|
||||
|
|
||||
= help: the trait `Try` is not implemented for `impl Future`
|
||||
= note: required by `into_result`
|
||||
help: consider `await`ing on the `Future`
|
||||
|
|
||||
LL | let _ = await bar().await?;
|
||||
| ^^^^^^
|
||||
|
||||
error[E0277]: the `?` operator can only be applied to values that implement `Try`
|
||||
--> $DIR/incorrect-syntax-suggestions.rs:63:19
|
||||
|
@ -2,25 +2,27 @@ error[E0277]: the `?` operator can only be applied to values that implement `Try
|
||||
--> $DIR/issue-61076.rs:42:5
|
||||
|
|
||||
LL | foo()?;
|
||||
| ^^^^^^
|
||||
| |
|
||||
| the `?` operator cannot be applied to type `impl Future`
|
||||
| help: consider using `.await` here: `foo().await?`
|
||||
| ^^^^^^ the `?` operator cannot be applied to type `impl Future`
|
||||
|
|
||||
= help: the trait `Try` is not implemented for `impl Future`
|
||||
= note: required by `into_result`
|
||||
help: consider `await`ing on the `Future`
|
||||
|
|
||||
LL | foo().await?;
|
||||
| ^^^^^^
|
||||
|
||||
error[E0277]: the `?` operator can only be applied to values that implement `Try`
|
||||
--> $DIR/issue-61076.rs:56:5
|
||||
|
|
||||
LL | t?;
|
||||
| ^^
|
||||
| |
|
||||
| the `?` operator cannot be applied to type `T`
|
||||
| help: consider using `.await` here: `t.await?`
|
||||
| ^^ the `?` operator cannot be applied to type `T`
|
||||
|
|
||||
= help: the trait `Try` is not implemented for `T`
|
||||
= note: required by `into_result`
|
||||
help: consider `await`ing on the `Future`
|
||||
|
|
||||
LL | t.await?;
|
||||
| ^^^^^^
|
||||
|
||||
error[E0609]: no field `0` on type `impl Future`
|
||||
--> $DIR/issue-61076.rs:58:26
|
||||
|
@ -15,8 +15,8 @@ async fn suggest_await_in_async_closure() {
|
||||
let x = make_u32();
|
||||
take_u32(x.await)
|
||||
//~^ ERROR mismatched types [E0308]
|
||||
//~| HELP consider using `.await` here
|
||||
//~| SUGGESTION x.await
|
||||
//~| HELP consider `await`ing on the `Future`
|
||||
//~| SUGGESTION .await
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -15,8 +15,8 @@ async fn suggest_await_in_async_closure() {
|
||||
let x = make_u32();
|
||||
take_u32(x)
|
||||
//~^ ERROR mismatched types [E0308]
|
||||
//~| HELP consider using `.await` here
|
||||
//~| SUGGESTION x.await
|
||||
//~| HELP consider `await`ing on the `Future`
|
||||
//~| SUGGESTION .await
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -5,13 +5,14 @@ LL | async fn make_u32() -> u32 {
|
||||
| --- the `Output` of this `async fn`'s found opaque type
|
||||
...
|
||||
LL | take_u32(x)
|
||||
| ^
|
||||
| |
|
||||
| expected `u32`, found opaque type
|
||||
| help: consider using `.await` here: `x.await`
|
||||
| ^ expected `u32`, found opaque type
|
||||
|
|
||||
= note: expected type `u32`
|
||||
found opaque type `impl Future`
|
||||
help: consider `await`ing on the `Future`
|
||||
|
|
||||
LL | take_u32(x.await)
|
||||
| ^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -12,8 +12,8 @@ async fn suggest_await_in_async_fn() {
|
||||
let x = make_u32();
|
||||
take_u32(x.await)
|
||||
//~^ ERROR mismatched types [E0308]
|
||||
//~| HELP consider using `.await` here
|
||||
//~| SUGGESTION x.await
|
||||
//~| HELP consider `await`ing on the `Future`
|
||||
//~| SUGGESTION .await
|
||||
}
|
||||
|
||||
async fn dummy() {}
|
||||
@ -23,8 +23,8 @@ async fn suggest_await_in_async_fn_return() {
|
||||
dummy().await;
|
||||
//~^ ERROR mismatched types [E0308]
|
||||
//~| HELP try adding a semicolon
|
||||
//~| HELP consider using `.await` here
|
||||
//~| SUGGESTION dummy().await
|
||||
//~| HELP consider `await`ing on the `Future`
|
||||
//~| SUGGESTION .await
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
@ -12,8 +12,8 @@ async fn suggest_await_in_async_fn() {
|
||||
let x = make_u32();
|
||||
take_u32(x)
|
||||
//~^ ERROR mismatched types [E0308]
|
||||
//~| HELP consider using `.await` here
|
||||
//~| SUGGESTION x.await
|
||||
//~| HELP consider `await`ing on the `Future`
|
||||
//~| SUGGESTION .await
|
||||
}
|
||||
|
||||
async fn dummy() {}
|
||||
@ -23,8 +23,8 @@ async fn suggest_await_in_async_fn_return() {
|
||||
dummy()
|
||||
//~^ ERROR mismatched types [E0308]
|
||||
//~| HELP try adding a semicolon
|
||||
//~| HELP consider using `.await` here
|
||||
//~| SUGGESTION dummy().await
|
||||
//~| HELP consider `await`ing on the `Future`
|
||||
//~| SUGGESTION .await
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
@ -5,13 +5,14 @@ LL | async fn make_u32() -> u32 {
|
||||
| --- the `Output` of this `async fn`'s found opaque type
|
||||
...
|
||||
LL | take_u32(x)
|
||||
| ^
|
||||
| |
|
||||
| expected `u32`, found opaque type
|
||||
| help: consider using `.await` here: `x.await`
|
||||
| ^ expected `u32`, found opaque type
|
||||
|
|
||||
= note: expected type `u32`
|
||||
found opaque type `impl Future`
|
||||
help: consider `await`ing on the `Future`
|
||||
|
|
||||
LL | take_u32(x.await)
|
||||
| ^^^^^^
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/suggest-missing-await.rs:23:5
|
||||
@ -28,10 +29,10 @@ help: try adding a semicolon
|
||||
|
|
||||
LL | dummy();
|
||||
| ^
|
||||
help: consider using `.await` here
|
||||
help: consider `await`ing on the `Future`
|
||||
|
|
||||
LL | dummy().await
|
||||
|
|
||||
| ^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
@ -2,13 +2,14 @@ error[E0277]: the `?` operator can only be applied to values that implement `Try
|
||||
--> $DIR/issue-72766.rs:14:5
|
||||
|
|
||||
LL | SadGirl {}.call()?;
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| the `?` operator cannot be applied to type `impl Future`
|
||||
| help: consider using `.await` here: `SadGirl {}.call().await?`
|
||||
| ^^^^^^^^^^^^^^^^^^ the `?` operator cannot be applied to type `impl Future`
|
||||
|
|
||||
= help: the trait `Try` is not implemented for `impl Future`
|
||||
= note: required by `into_result`
|
||||
help: consider `await`ing on the `Future`
|
||||
|
|
||||
LL | SadGirl {}.call().await?;
|
||||
| ^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user