Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect syntax suggestion with pub async fn #96617

Merged
merged 1 commit into from
May 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1079,18 +1079,28 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
self.in_progress_typeck_results.map(|t| t.borrow())
&& let ty = typeck_results.expr_ty_adjusted(base)
&& let ty::FnDef(def_id, _substs) = ty.kind()
&& let Some(hir::Node::Item(hir::Item { span, ident, .. })) =
&& let Some(hir::Node::Item(hir::Item { ident, span, vis_span, .. })) =
hir.get_if_local(*def_id)
{
err.span_suggestion_verbose(
span.shrink_to_lo(),
&format!(
"alternatively, consider making `fn {}` asynchronous",
ident
),
"async ".to_string(),
Applicability::MaybeIncorrect,
let msg = format!(
"alternatively, consider making `fn {}` asynchronous",
ident
);
if vis_span.is_empty() {
err.span_suggestion_verbose(
span.shrink_to_lo(),
&msg,
"async ".to_string(),
Applicability::MaybeIncorrect,
);
} else {
err.span_suggestion_verbose(
vis_span.shrink_to_hi(),
&msg,
" async".to_string(),
Applicability::MaybeIncorrect,
);
}
}
}
}
Expand Down
19 changes: 19 additions & 0 deletions src/test/ui/suggestions/issue-96555.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// edition:2018

async fn f() {
m::f1().await; //~ ERROR `()` is not a future
m::f2().await; //~ ERROR `()` is not a future
m::f3().await; //~ ERROR `()` is not a future
}

mod m {
pub fn f1() {}

pub(crate) fn f2() {}

pub
fn
f3() {}
}

fn main() {}
66 changes: 66 additions & 0 deletions src/test/ui/suggestions/issue-96555.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
error[E0277]: `()` is not a future
--> $DIR/issue-96555.rs:4:12
|
LL | m::f1().await;
| -------^^^^^^ `()` is not a future
| |
| this call returns `()`
|
= help: the trait `Future` is not implemented for `()`
= note: () must be a future or must implement `IntoFuture` to be awaited
= note: required because of the requirements on the impl of `IntoFuture` for `()`
help: remove the `.await`
|
LL - m::f1().await;
LL + m::f1();
|
help: alternatively, consider making `fn f1` asynchronous
|
LL | pub async fn f1() {}
| +++++

error[E0277]: `()` is not a future
--> $DIR/issue-96555.rs:5:12
|
LL | m::f2().await;
| -------^^^^^^ `()` is not a future
| |
| this call returns `()`
|
= help: the trait `Future` is not implemented for `()`
= note: () must be a future or must implement `IntoFuture` to be awaited
= note: required because of the requirements on the impl of `IntoFuture` for `()`
help: remove the `.await`
|
LL - m::f2().await;
LL + m::f2();
|
help: alternatively, consider making `fn f2` asynchronous
|
LL | pub(crate) async fn f2() {}
| +++++

error[E0277]: `()` is not a future
--> $DIR/issue-96555.rs:6:12
|
LL | m::f3().await;
| -------^^^^^^ `()` is not a future
| |
| this call returns `()`
|
= help: the trait `Future` is not implemented for `()`
= note: () must be a future or must implement `IntoFuture` to be awaited
= note: required because of the requirements on the impl of `IntoFuture` for `()`
help: remove the `.await`
|
LL - m::f3().await;
LL + m::f3();
|
help: alternatively, consider making `fn f3` asynchronous
|
LL | pub async
| +++++

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0277`.