@@ -11,7 +11,9 @@ use rustc_middle::ty::print::with_no_trimmed_paths;
1111use rustc_middle:: ty:: { self as ty, IsSuggestable , Ty , TypeVisitable } ;
1212use rustc_span:: { sym, BytePos , Span } ;
1313
14- use crate :: errors:: { SuggAddLetForLetChains , SuggestRemoveSemiOrReturnBinding } ;
14+ use crate :: errors:: {
15+ ConsiderAddingAwait , SuggAddLetForLetChains , SuggestRemoveSemiOrReturnBinding ,
16+ } ;
1517
1618use super :: TypeErrCtxt ;
1719
@@ -191,7 +193,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
191193 return ;
192194 }
193195
194- match (
196+ let subdiag = match (
195197 self . get_impl_future_output_ty ( exp_found. expected ) ,
196198 self . get_impl_future_output_ty ( exp_found. found ) ,
197199 ) {
@@ -200,65 +202,52 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
200202 {
201203 ObligationCauseCode :: IfExpression ( box IfExpressionCause { then_id, .. } ) => {
202204 let then_span = self . find_block_span_from_hir_id ( * then_id) ;
203- diag. multipart_suggestion (
204- "consider `await`ing on both `Future`s" ,
205- vec ! [
206- ( then_span. shrink_to_hi( ) , ".await" . to_string( ) ) ,
207- ( exp_span. shrink_to_hi( ) , ".await" . to_string( ) ) ,
208- ] ,
209- Applicability :: MaybeIncorrect ,
210- ) ;
205+ Some ( ConsiderAddingAwait :: BothFuturesSugg {
206+ first : then_span. shrink_to_hi ( ) ,
207+ second : exp_span. shrink_to_hi ( ) ,
208+ } )
211209 }
212210 ObligationCauseCode :: MatchExpressionArm ( box MatchExpressionArmCause {
213211 prior_arms,
214212 ..
215213 } ) => {
216214 if let [ .., arm_span] = & prior_arms[ ..] {
217- diag. multipart_suggestion (
218- "consider `await`ing on both `Future`s" ,
219- vec ! [
220- ( arm_span. shrink_to_hi( ) , ".await" . to_string( ) ) ,
221- ( exp_span. shrink_to_hi( ) , ".await" . to_string( ) ) ,
222- ] ,
223- Applicability :: MaybeIncorrect ,
224- ) ;
215+ Some ( ConsiderAddingAwait :: BothFuturesSugg {
216+ first : arm_span. shrink_to_hi ( ) ,
217+ second : exp_span. shrink_to_hi ( ) ,
218+ } )
225219 } else {
226- diag . help ( "consider `await`ing on both `Future`s" ) ;
220+ Some ( ConsiderAddingAwait :: BothFuturesHelp )
227221 }
228222 }
229- _ => {
230- diag. help ( "consider `await`ing on both `Future`s" ) ;
231- }
223+ _ => Some ( ConsiderAddingAwait :: BothFuturesHelp ) ,
232224 } ,
233225 ( _, Some ( ty) ) if self . same_type_modulo_infer ( exp_found. expected , ty) => {
234- self . suggest_await_on_future ( diag, exp_span) ;
235- diag. span_note ( exp_span, "calling an async function returns a future" ) ;
226+ Some ( ConsiderAddingAwait :: FutureSuggWithNote { span : exp_span. shrink_to_hi ( ) } )
236227 }
237228 ( Some ( ty) , _) if self . same_type_modulo_infer ( ty, exp_found. found ) => match cause. code ( )
238229 {
239230 ObligationCauseCode :: Pattern { span : Some ( then_span) , .. } => {
240- self . suggest_await_on_future ( diag , then_span. shrink_to_hi ( ) ) ;
231+ Some ( ConsiderAddingAwait :: FutureSugg { span : then_span. shrink_to_hi ( ) } )
241232 }
242233 ObligationCauseCode :: IfExpression ( box IfExpressionCause { then_id, .. } ) => {
243234 let then_span = self . find_block_span_from_hir_id ( * then_id) ;
244- self . suggest_await_on_future ( diag , then_span. shrink_to_hi ( ) ) ;
235+ Some ( ConsiderAddingAwait :: FutureSugg { span : then_span. shrink_to_hi ( ) } )
245236 }
246237 ObligationCauseCode :: MatchExpressionArm ( box MatchExpressionArmCause {
247238 ref prior_arms,
248239 ..
249- } ) => {
250- diag. multipart_suggestion_verbose (
251- "consider `await`ing on the `Future`" ,
252- prior_arms
253- . iter ( )
254- . map ( |arm| ( arm. shrink_to_hi ( ) , ".await" . to_string ( ) ) )
255- . collect ( ) ,
256- Applicability :: MaybeIncorrect ,
257- ) ;
258- }
259- _ => { }
240+ } ) => Some ( {
241+ ConsiderAddingAwait :: FutureSuggMultiple {
242+ spans : prior_arms. iter ( ) . map ( |arm| arm. shrink_to_hi ( ) ) . collect ( ) ,
243+ }
244+ } ) ,
245+ _ => None ,
260246 } ,
261- _ => { }
247+ _ => None ,
248+ } ;
249+ if let Some ( subdiag) = subdiag {
250+ diag. subdiagnostic ( subdiag) ;
262251 }
263252 }
264253
0 commit comments