Skip to content

Commit 8f775dc

Browse files
authored
Rollup merge of #108731 - Ezrashaw:pin-suggestion-on-impl-future, r=petrochenkov
feat: impl better help for `.poll()` not found on `impl Future` Partially address #108572 I'd like to also address suggestions for generalized `Self` parameters as well. That'll be a separate PR.
2 parents 2a196db + aaaffa9 commit 8f775dc

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

compiler/rustc_hir_typeck/src/method/suggest.rs

+10
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
348348
err.downgrade_to_delayed_bug();
349349
}
350350

351+
if tcx.ty_is_opaque_future(rcvr_ty) && item_name.name == sym::poll {
352+
err.help(&format!(
353+
"method `poll` found on `Pin<&mut {ty_str}>`, \
354+
see documentation for `std::pin::Pin`"
355+
));
356+
err.help("self type must be pinned to call `Future::poll`, \
357+
see https://rust-lang.github.io/async-book/04_pinning/01_chapter.html#pinning-in-practice"
358+
);
359+
}
360+
351361
if let Mode::MethodCall = mode && let SelfSource::MethodCall(cal) = source {
352362
self.suggest_await_before_method(
353363
&mut err, item_name, rcvr_ty, cal, span, expected.only_has_type(self),

tests/ui/async-await/issue-108572.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// edition: 2021
2+
3+
use std::future::Future;
4+
fn foo() -> impl Future<Output=()> {
5+
async { }
6+
}
7+
8+
fn main() {
9+
let fut = foo();
10+
fut.poll();
11+
//~^ ERROR no method named `poll` found for opaque type `impl Future<Output = ()>` in the current scope [E0599]
12+
}
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0599]: no method named `poll` found for opaque type `impl Future<Output = ()>` in the current scope
2+
--> $DIR/issue-108572.rs:10:9
3+
|
4+
LL | fut.poll();
5+
| ^^^^ method not found in `impl Future<Output = ()>`
6+
|
7+
= help: method `poll` found on `Pin<&mut impl Future<Output = ()>>`, see documentation for `std::pin::Pin`
8+
= help: self type must be pinned to call `Future::poll`, see https://rust-lang.github.io/async-book/04_pinning/01_chapter.html#pinning-in-practice
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0599`.

0 commit comments

Comments
 (0)