Skip to content

Commit 86df903

Browse files
committed
Tweak "use .await" suggestion
1 parent 07a63e6 commit 86df903

File tree

11 files changed

+55
-53
lines changed

11 files changed

+55
-53
lines changed

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use rustc_middle::ty::{
2121
};
2222
use rustc_middle::ty::{TypeAndMut, TypeckResults};
2323
use rustc_span::symbol::{kw, sym, Ident, Symbol};
24-
use rustc_span::{MultiSpan, Span, DUMMY_SP};
24+
use rustc_span::{BytePos, MultiSpan, Span, DUMMY_SP};
2525
use rustc_target::spec::abi;
2626
use std::fmt;
2727

@@ -2114,10 +2114,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
21142114
if self.predicate_may_hold(&try_obligation) && impls_future {
21152115
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) {
21162116
if snippet.ends_with('?') {
2117-
err.span_suggestion(
2118-
span,
2119-
"consider using `.await` here",
2120-
format!("{}.await?", snippet.trim_end_matches('?')),
2117+
err.span_suggestion_verbose(
2118+
span.with_hi(span.hi() - BytePos(1)).shrink_to_hi(),
2119+
"consider `await`ing on the `Future`",
2120+
".await".to_string(),
21212121
Applicability::MaybeIncorrect,
21222122
);
21232123
}

compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -497,16 +497,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
497497

498498
if self.infcx.predicate_may_hold(&obligation) {
499499
debug!("suggest_missing_await: obligation held: {:?}", obligation);
500-
if let Ok(code) = self.sess().source_map().span_to_snippet(sp) {
501-
err.span_suggestion(
502-
sp,
503-
"consider using `.await` here",
504-
format!("{}.await", code),
505-
Applicability::MaybeIncorrect,
506-
);
507-
} else {
508-
debug!("suggest_missing_await: no snippet for {:?}", sp);
509-
}
500+
err.span_suggestion_verbose(
501+
sp.shrink_to_hi(),
502+
"consider `await`ing on the `Future`",
503+
".await".to_string(),
504+
Applicability::MaybeIncorrect,
505+
);
510506
} else {
511507
debug!("suggest_missing_await: obligation did not hold: {:?}", obligation)
512508
}

src/test/ui/async-await/await-keyword/incorrect-syntax-suggestions.stderr

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,13 +237,14 @@ error[E0277]: the `?` operator can only be applied to values that implement `Try
237237
--> $DIR/incorrect-syntax-suggestions.rs:16:19
238238
|
239239
LL | let _ = await bar()?;
240-
| ^^^^^^
241-
| |
242-
| the `?` operator cannot be applied to type `impl Future`
243-
| help: consider using `.await` here: `bar().await?`
240+
| ^^^^^^ the `?` operator cannot be applied to type `impl Future`
244241
|
245242
= help: the trait `Try` is not implemented for `impl Future`
246243
= note: required by `into_result`
244+
help: consider `await`ing on the `Future`
245+
|
246+
LL | let _ = await bar().await?;
247+
| ^^^^^^
247248

248249
error[E0277]: the `?` operator can only be applied to values that implement `Try`
249250
--> $DIR/incorrect-syntax-suggestions.rs:63:19

src/test/ui/async-await/issue-61076.stderr

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,27 @@ error[E0277]: the `?` operator can only be applied to values that implement `Try
22
--> $DIR/issue-61076.rs:42:5
33
|
44
LL | foo()?;
5-
| ^^^^^^
6-
| |
7-
| the `?` operator cannot be applied to type `impl Future`
8-
| help: consider using `.await` here: `foo().await?`
5+
| ^^^^^^ the `?` operator cannot be applied to type `impl Future`
96
|
107
= help: the trait `Try` is not implemented for `impl Future`
118
= note: required by `into_result`
9+
help: consider `await`ing on the `Future`
10+
|
11+
LL | foo().await?;
12+
| ^^^^^^
1213

1314
error[E0277]: the `?` operator can only be applied to values that implement `Try`
1415
--> $DIR/issue-61076.rs:56:5
1516
|
1617
LL | t?;
17-
| ^^
18-
| |
19-
| the `?` operator cannot be applied to type `T`
20-
| help: consider using `.await` here: `t.await?`
18+
| ^^ the `?` operator cannot be applied to type `T`
2119
|
2220
= help: the trait `Try` is not implemented for `T`
2321
= note: required by `into_result`
22+
help: consider `await`ing on the `Future`
23+
|
24+
LL | t.await?;
25+
| ^^^^^^
2426

2527
error[E0609]: no field `0` on type `impl Future`
2628
--> $DIR/issue-61076.rs:58:26

src/test/ui/async-await/suggest-missing-await-closure.fixed

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ async fn suggest_await_in_async_closure() {
1515
let x = make_u32();
1616
take_u32(x.await)
1717
//~^ ERROR mismatched types [E0308]
18-
//~| HELP consider using `.await` here
19-
//~| SUGGESTION x.await
18+
//~| HELP consider `await`ing on the `Future`
19+
//~| SUGGESTION .await
2020
};
2121
}
2222

src/test/ui/async-await/suggest-missing-await-closure.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ async fn suggest_await_in_async_closure() {
1515
let x = make_u32();
1616
take_u32(x)
1717
//~^ ERROR mismatched types [E0308]
18-
//~| HELP consider using `.await` here
19-
//~| SUGGESTION x.await
18+
//~| HELP consider `await`ing on the `Future`
19+
//~| SUGGESTION .await
2020
};
2121
}
2222

src/test/ui/async-await/suggest-missing-await-closure.stderr

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ LL | async fn make_u32() -> u32 {
55
| --- the `Output` of this `async fn`'s found opaque type
66
...
77
LL | take_u32(x)
8-
| ^
9-
| |
10-
| expected `u32`, found opaque type
11-
| help: consider using `.await` here: `x.await`
8+
| ^ expected `u32`, found opaque type
129
|
1310
= note: expected type `u32`
1411
found opaque type `impl Future`
12+
help: consider `await`ing on the `Future`
13+
|
14+
LL | take_u32(x.await)
15+
| ^^^^^^
1516

1617
error: aborting due to previous error
1718

src/test/ui/async-await/suggest-missing-await.fixed

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ async fn suggest_await_in_async_fn() {
1212
let x = make_u32();
1313
take_u32(x.await)
1414
//~^ ERROR mismatched types [E0308]
15-
//~| HELP consider using `.await` here
16-
//~| SUGGESTION x.await
15+
//~| HELP consider `await`ing on the `Future`
16+
//~| SUGGESTION .await
1717
}
1818

1919
async fn dummy() {}
@@ -23,8 +23,8 @@ async fn suggest_await_in_async_fn_return() {
2323
dummy().await;
2424
//~^ ERROR mismatched types [E0308]
2525
//~| HELP try adding a semicolon
26-
//~| HELP consider using `.await` here
27-
//~| SUGGESTION dummy().await
26+
//~| HELP consider `await`ing on the `Future`
27+
//~| SUGGESTION .await
2828
}
2929

3030
fn main() {}

src/test/ui/async-await/suggest-missing-await.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ async fn suggest_await_in_async_fn() {
1212
let x = make_u32();
1313
take_u32(x)
1414
//~^ ERROR mismatched types [E0308]
15-
//~| HELP consider using `.await` here
16-
//~| SUGGESTION x.await
15+
//~| HELP consider `await`ing on the `Future`
16+
//~| SUGGESTION .await
1717
}
1818

1919
async fn dummy() {}
@@ -23,8 +23,8 @@ async fn suggest_await_in_async_fn_return() {
2323
dummy()
2424
//~^ ERROR mismatched types [E0308]
2525
//~| HELP try adding a semicolon
26-
//~| HELP consider using `.await` here
27-
//~| SUGGESTION dummy().await
26+
//~| HELP consider `await`ing on the `Future`
27+
//~| SUGGESTION .await
2828
}
2929

3030
fn main() {}

src/test/ui/async-await/suggest-missing-await.stderr

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ LL | async fn make_u32() -> u32 {
55
| --- the `Output` of this `async fn`'s found opaque type
66
...
77
LL | take_u32(x)
8-
| ^
9-
| |
10-
| expected `u32`, found opaque type
11-
| help: consider using `.await` here: `x.await`
8+
| ^ expected `u32`, found opaque type
129
|
1310
= note: expected type `u32`
1411
found opaque type `impl Future`
12+
help: consider `await`ing on the `Future`
13+
|
14+
LL | take_u32(x.await)
15+
| ^^^^^^
1516

1617
error[E0308]: mismatched types
1718
--> $DIR/suggest-missing-await.rs:23:5
@@ -28,10 +29,10 @@ help: try adding a semicolon
2829
|
2930
LL | dummy();
3031
| ^
31-
help: consider using `.await` here
32+
help: consider `await`ing on the `Future`
3233
|
3334
LL | dummy().await
34-
|
35+
| ^^^^^^
3536

3637
error: aborting due to 2 previous errors
3738

src/test/ui/suggestions/issue-72766.stderr

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ error[E0277]: the `?` operator can only be applied to values that implement `Try
22
--> $DIR/issue-72766.rs:14:5
33
|
44
LL | SadGirl {}.call()?;
5-
| ^^^^^^^^^^^^^^^^^^
6-
| |
7-
| the `?` operator cannot be applied to type `impl Future`
8-
| help: consider using `.await` here: `SadGirl {}.call().await?`
5+
| ^^^^^^^^^^^^^^^^^^ the `?` operator cannot be applied to type `impl Future`
96
|
107
= help: the trait `Try` is not implemented for `impl Future`
118
= note: required by `into_result`
9+
help: consider `await`ing on the `Future`
10+
|
11+
LL | SadGirl {}.call().await?;
12+
| ^^^^^^
1213

1314
error: aborting due to previous error
1415

0 commit comments

Comments
 (0)