diff options
| author | Ken Matsui <26405363+ken-matsui@users.noreply.github.com> | 2022-05-02 08:19:57 +0900 |
|---|---|---|
| committer | Ken Matsui <26405363+ken-matsui@users.noreply.github.com> | 2022-05-08 09:34:02 +0900 |
| commit | 8b89a1280c929f7aaf11386f8f1a9ecdbef2f539 (patch) | |
| tree | 8ba30baef2760c8f2f7f0385f325e6fae6fa09ad /compiler | |
| parent | bf611439e3239ad3f74bd76cc46a4e89b87d8219 (diff) | |
| download | rust-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.rs | 28 |
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, + ); + } } } } |
