diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-05-08 21:31:16 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-05-08 21:31:16 +0200 |
| commit | cdaa5c03c92e172d7777347dc2f55432ac45b4f7 (patch) | |
| tree | 25b99b9035aab0f273f7460c8d34d0d1fcd05cfa /compiler/rustc_trait_selection/src | |
| parent | 83322c557fcaa9b6750955ceb6b9591df6c53a65 (diff) | |
| parent | 8b89a1280c929f7aaf11386f8f1a9ecdbef2f539 (diff) | |
Rollup merge of #96617 - ken-matsui:fix-incorrect-syntax-suggestion-with-pub-async-fn, r=cjgillot
Fix incorrect syntax suggestion with `pub async fn` This PR closes: https://github.com/rust-lang/rust/issues/96555
Diffstat (limited to 'compiler/rustc_trait_selection/src')
| -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 bfb8ce6f105..d20ba99ebc9 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -1085,18 +1085,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, + ); + } } } } |
