@@ -11,7 +11,9 @@ use rustc_middle::ty::print::with_no_trimmed_paths;
11
11
use rustc_middle:: ty:: { self as ty, IsSuggestable , Ty , TypeVisitable } ;
12
12
use rustc_span:: { sym, BytePos , Span } ;
13
13
14
- use crate :: errors:: { SuggAddLetForLetChains , SuggestRemoveSemiOrReturnBinding } ;
14
+ use crate :: errors:: {
15
+ ConsiderAddingAwait , SuggAddLetForLetChains , SuggestRemoveSemiOrReturnBinding ,
16
+ } ;
15
17
16
18
use super :: TypeErrCtxt ;
17
19
@@ -191,7 +193,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
191
193
return ;
192
194
}
193
195
194
- match (
196
+ let subdiag = match (
195
197
self . get_impl_future_output_ty ( exp_found. expected ) ,
196
198
self . get_impl_future_output_ty ( exp_found. found ) ,
197
199
) {
@@ -200,65 +202,52 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
200
202
{
201
203
ObligationCauseCode :: IfExpression ( box IfExpressionCause { then_id, .. } ) => {
202
204
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
+ } )
211
209
}
212
210
ObligationCauseCode :: MatchExpressionArm ( box MatchExpressionArmCause {
213
211
prior_arms,
214
212
..
215
213
} ) => {
216
214
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
+ } )
225
219
} else {
226
- diag . help ( "consider `await`ing on both `Future`s" ) ;
220
+ Some ( ConsiderAddingAwait :: BothFuturesHelp )
227
221
}
228
222
}
229
- _ => {
230
- diag. help ( "consider `await`ing on both `Future`s" ) ;
231
- }
223
+ _ => Some ( ConsiderAddingAwait :: BothFuturesHelp ) ,
232
224
} ,
233
225
( _, 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 ( ) } )
236
227
}
237
228
( Some ( ty) , _) if self . same_type_modulo_infer ( ty, exp_found. found ) => match cause. code ( )
238
229
{
239
230
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 ( ) } )
241
232
}
242
233
ObligationCauseCode :: IfExpression ( box IfExpressionCause { then_id, .. } ) => {
243
234
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 ( ) } )
245
236
}
246
237
ObligationCauseCode :: MatchExpressionArm ( box MatchExpressionArmCause {
247
238
ref prior_arms,
248
239
..
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 ,
260
246
} ,
261
- _ => { }
247
+ _ => None ,
248
+ } ;
249
+ if let Some ( subdiag) = subdiag {
250
+ diag. subdiagnostic ( subdiag) ;
262
251
}
263
252
}
264
253
0 commit comments