@@ -3199,71 +3199,69 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
3199
3199
}
3200
3200
} ;
3201
3201
3202
- // Don't print the tuple of capture types
3203
- ' print: {
3204
- if !is_upvar_tys_infer_tuple {
3205
- let ty_str = tcx. short_ty_string ( ty, & mut long_ty_file) ;
3206
- let msg = format ! ( "required because it appears within the type `{ty_str}`" ) ;
3207
- match ty. kind ( ) {
3208
- ty:: Adt ( def, _) => match tcx. opt_item_ident ( def. did ( ) ) {
3209
- Some ( ident) => err. span_note ( ident. span , msg) ,
3210
- None => err. note ( msg) ,
3211
- } ,
3212
- ty:: Alias ( ty:: Opaque , ty:: AliasTy { def_id, .. } ) => {
3213
- // If the previous type is async fn, this is the future generated by the body of an async function.
3214
- // Avoid printing it twice (it was already printed in the `ty::Coroutine` arm below).
3215
- let is_future = tcx. ty_is_opaque_future ( ty) ;
3216
- debug ! (
3217
- ?obligated_types,
3218
- ?is_future,
3219
- "note_obligation_cause_code: check for async fn"
3220
- ) ;
3221
- if is_future
3222
- && obligated_types. last ( ) . is_some_and ( |ty| match ty. kind ( ) {
3223
- ty:: Coroutine ( last_def_id, ..) => {
3224
- tcx. coroutine_is_async ( * last_def_id)
3225
- }
3226
- _ => false ,
3227
- } )
3228
- {
3229
- break ' print;
3230
- }
3231
- err. span_note ( tcx. def_span ( def_id) , msg)
3202
+ if !is_upvar_tys_infer_tuple {
3203
+ let ty_str = tcx. short_ty_string ( ty, & mut long_ty_file) ;
3204
+ let msg = format ! ( "required because it appears within the type `{ty_str}`" ) ;
3205
+ match ty. kind ( ) {
3206
+ ty:: Adt ( def, _) => match tcx. opt_item_ident ( def. did ( ) ) {
3207
+ Some ( ident) => {
3208
+ err. span_note ( ident. span , msg) ;
3232
3209
}
3233
- ty:: CoroutineWitness ( def_id, args) => {
3234
- use std:: fmt:: Write ;
3235
-
3236
- // FIXME: this is kind of an unusual format for rustc, can we make it more clear?
3237
- // Maybe we should just remove this note altogether?
3238
- // FIXME: only print types which don't meet the trait requirement
3239
- let mut msg =
3240
- "required because it captures the following types: " . to_owned ( ) ;
3241
- for bty in tcx. coroutine_hidden_types ( * def_id) {
3242
- let ty = bty. instantiate ( tcx, args) ;
3243
- write ! ( msg, "`{ty}`, " ) . unwrap ( ) ;
3244
- }
3245
- err. note ( msg. trim_end_matches ( ", " ) . to_string ( ) )
3210
+ None => {
3211
+ err. note ( msg) ;
3246
3212
}
3247
- ty:: Coroutine ( def_id, _) => {
3248
- let sp = tcx. def_span ( def_id) ;
3249
-
3250
- // Special-case this to say "async block" instead of `[static coroutine]`.
3251
- let kind = tcx. coroutine_kind ( def_id) . unwrap ( ) ;
3252
- err. span_note (
3253
- sp,
3254
- with_forced_trimmed_paths ! ( format!(
3255
- "required because it's used within this {kind:#}" ,
3256
- ) ) ,
3257
- )
3213
+ } ,
3214
+ ty:: Alias ( ty:: Opaque , ty:: AliasTy { def_id, .. } ) => {
3215
+ // If the previous type is async fn, this is the future generated by the body of an async function.
3216
+ // Avoid printing it twice (it was already printed in the `ty::Coroutine` arm below).
3217
+ let is_future = tcx. ty_is_opaque_future ( ty) ;
3218
+ debug ! (
3219
+ ?obligated_types,
3220
+ ?is_future,
3221
+ "note_obligation_cause_code: check for async fn"
3222
+ ) ;
3223
+ if is_future
3224
+ && obligated_types. last ( ) . is_some_and ( |ty| match ty. kind ( ) {
3225
+ ty:: Coroutine ( last_def_id, ..) => {
3226
+ tcx. coroutine_is_async ( * last_def_id)
3227
+ }
3228
+ _ => false ,
3229
+ } )
3230
+ {
3231
+ // See comment above; skip printing twice.
3232
+ } else {
3233
+ err. span_note ( tcx. def_span ( def_id) , msg) ;
3258
3234
}
3259
- ty:: Closure ( def_id, _) => err. span_note (
3235
+ }
3236
+ ty:: Coroutine ( def_id, _) => {
3237
+ let sp = tcx. def_span ( def_id) ;
3238
+
3239
+ // Special-case this to say "async block" instead of `[static coroutine]`.
3240
+ let kind = tcx. coroutine_kind ( def_id) . unwrap ( ) ;
3241
+ err. span_note (
3242
+ sp,
3243
+ with_forced_trimmed_paths ! ( format!(
3244
+ "required because it's used within this {kind:#}" ,
3245
+ ) ) ,
3246
+ ) ;
3247
+ }
3248
+ ty:: CoroutineWitness ( ..) => {
3249
+ // Skip printing coroutine-witnesses, since we'll drill into
3250
+ // the bad field in another derived obligation cause.
3251
+ }
3252
+ ty:: Closure ( def_id, _) | ty:: CoroutineClosure ( def_id, _) => {
3253
+ err. span_note (
3260
3254
tcx. def_span ( def_id) ,
3261
3255
"required because it's used within this closure" ,
3262
- ) ,
3263
- ty:: Str => err. note ( "`str` is considered to contain a `[u8]` slice for auto trait purposes" ) ,
3264
- _ => err. note ( msg) ,
3265
- } ;
3266
- }
3256
+ ) ;
3257
+ }
3258
+ ty:: Str => {
3259
+ err. note ( "`str` is considered to contain a `[u8]` slice for auto trait purposes" ) ;
3260
+ }
3261
+ _ => {
3262
+ err. note ( msg) ;
3263
+ }
3264
+ } ;
3267
3265
}
3268
3266
3269
3267
obligated_types. push ( ty) ;
0 commit comments