about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorKen Matsui <26405363+ken-matsui@users.noreply.github.com>2022-05-02 08:19:57 +0900
committerKen Matsui <26405363+ken-matsui@users.noreply.github.com>2022-05-08 09:34:02 +0900
commit8b89a1280c929f7aaf11386f8f1a9ecdbef2f539 (patch)
tree8ba30baef2760c8f2f7f0385f325e6fae6fa09ad /compiler
parentbf611439e3239ad3f74bd76cc46a4e89b87d8219 (diff)
downloadrust-8b89a1280c929f7aaf11386f8f1a9ecdbef2f539.tar.gz
rust-8b89a1280c929f7aaf11386f8f1a9ecdbef2f539.zip
Fix incorrect syntax suggestion with `pub async fn`
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs28
1 files changed, 19 insertions, 9 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
index 446b14a17ae..09a2560fd46 100644
--- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
+++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
@@ -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,
+                                );
+                            }
                         }
                     }
                 }