@@ -1789,7 +1789,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
1789
1789
self . note_conflicting_closure_bounds ( cause, & mut err) ;
1790
1790
1791
1791
if let Some ( found_node) = found_node {
1792
- hint_missing_borrow ( span, found_span , found, expected, found_node, & mut err) ;
1792
+ hint_missing_borrow ( span, found, expected, found_node, & mut err) ;
1793
1793
}
1794
1794
1795
1795
err
@@ -2344,28 +2344,33 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
2344
2344
}
2345
2345
}
2346
2346
GeneratorInteriorOrUpvar :: Upvar ( upvar_span) => {
2347
- // `Some(ref_ty) ` if `target_ty` is `&T` and ` T` fails to impl `Sync `
2348
- let refers_to_non_sync = match target_ty. kind ( ) {
2349
- ty:: Ref ( _, ref_ty, _ ) => match self . evaluate_obligation ( & obligation) {
2350
- Ok ( eval) if !eval. may_apply ( ) => Some ( ref_ty) ,
2347
+ // `Some(( ref_ty, is_mut)) ` if `target_ty` is `&T` or `&mut T` and fails to impl `Send `
2348
+ let non_send = match target_ty. kind ( ) {
2349
+ ty:: Ref ( _, ref_ty, mutability ) => match self . evaluate_obligation ( & obligation) {
2350
+ Ok ( eval) if !eval. may_apply ( ) => Some ( ( ref_ty, mutability . is_mut ( ) ) ) ,
2351
2351
_ => None ,
2352
2352
} ,
2353
2353
_ => None ,
2354
2354
} ;
2355
2355
2356
- let ( span_label, span_note) = match refers_to_non_sync {
2357
- // if `target_ty` is `&T` and `T` fails to impl `Sync`,
2358
- // include suggestions to make `T: Sync` so that `&T: Send`
2359
- Some ( ref_ty) => (
2360
- format ! (
2361
- "has type `{}` which {}, because `{}` is not `Sync`" ,
2362
- target_ty, trait_explanation, ref_ty
2363
- ) ,
2364
- format ! (
2365
- "captured value {} because `&` references cannot be sent unless their referent is `Sync`" ,
2366
- trait_explanation
2367
- ) ,
2368
- ) ,
2356
+ let ( span_label, span_note) = match non_send {
2357
+ // if `target_ty` is `&T` or `&mut T` and fails to impl `Send`,
2358
+ // include suggestions to make `T: Sync` so that `&T: Send`,
2359
+ // or to make `T: Send` so that `&mut T: Send`
2360
+ Some ( ( ref_ty, is_mut) ) => {
2361
+ let ref_ty_trait = if is_mut { "Send" } else { "Sync" } ;
2362
+ let ref_kind = if is_mut { "&mut" } else { "&" } ;
2363
+ (
2364
+ format ! (
2365
+ "has type `{}` which {}, because `{}` is not `{}`" ,
2366
+ target_ty, trait_explanation, ref_ty, ref_ty_trait
2367
+ ) ,
2368
+ format ! (
2369
+ "captured value {} because `{}` references cannot be sent unless their referent is `{}`" ,
2370
+ trait_explanation, ref_kind, ref_ty_trait
2371
+ ) ,
2372
+ )
2373
+ }
2369
2374
None => (
2370
2375
format ! ( "has type `{}` which {}" , target_ty, trait_explanation) ,
2371
2376
format ! ( "captured value {}" , trait_explanation) ,
@@ -3455,7 +3460,6 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
3455
3460
/// Add a hint to add a missing borrow or remove an unnecessary one.
3456
3461
fn hint_missing_borrow < ' tcx > (
3457
3462
span : Span ,
3458
- found_span : Span ,
3459
3463
found : Ty < ' tcx > ,
3460
3464
expected : Ty < ' tcx > ,
3461
3465
found_node : Node < ' _ > ,
@@ -3474,9 +3478,8 @@ fn hint_missing_borrow<'tcx>(
3474
3478
}
3475
3479
} ;
3476
3480
3477
- let fn_decl = found_node
3478
- . fn_decl ( )
3479
- . unwrap_or_else ( || span_bug ! ( found_span, "found node must be a function" ) ) ;
3481
+ // This could be a variant constructor, for example.
3482
+ let Some ( fn_decl) = found_node. fn_decl ( ) else { return ; } ;
3480
3483
3481
3484
let arg_spans = fn_decl. inputs . iter ( ) . map ( |ty| ty. span ) ;
3482
3485
0 commit comments