@@ -1428,7 +1428,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14281428 item_name,
14291429 field_ty,
14301430 call_expr,
1431- ProbeScope :: AllTraits ,
1431+ ProbeScope :: TraitsInScope ,
14321432 )
14331433 . ok ( )
14341434 . map ( |pick| ( variant, field, pick) )
@@ -1500,59 +1500,88 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15001500 item_name,
15011501 ty,
15021502 call_expr,
1503- ProbeScope :: AllTraits ,
1503+ ProbeScope :: TraitsInScope ,
15041504 ) else { return ; } ;
15051505
15061506 let name = self . ty_to_value_string ( actual) ;
15071507 let inner_id = kind. did ( ) ;
1508+ let mutable = if let Some ( AutorefOrPtrAdjustment :: Autoref { mutbl, .. } ) =
1509+ pick. autoref_or_ptr_adjustment
1510+ {
1511+ Some ( mutbl)
1512+ } else {
1513+ None
1514+ } ;
15081515
15091516 if tcx. is_diagnostic_item ( sym:: LocalKey , inner_id) {
1510- err. help ( "use `with` or `try_with` to access the contents of threadlocals " ) ;
1517+ err. help ( "use `with` or `try_with` to access thread local storage " ) ;
15111518 } else if Some ( kind. did ( ) ) == tcx. lang_items ( ) . maybe_uninit ( ) {
15121519 err. help ( format ! (
15131520 "if this `{name}` has been initialized, \
15141521 use one of the `assume_init` methods to access the inner value"
15151522 ) ) ;
15161523 } else if tcx. is_diagnostic_item ( sym:: RefCell , inner_id) {
1517- match pick. autoref_or_ptr_adjustment {
1518- Some ( AutorefOrPtrAdjustment :: Autoref {
1519- mutbl : Mutability :: Not , ..
1520- } ) => {
1524+ match mutable {
1525+ Some ( Mutability :: Not ) => {
15211526 err. span_suggestion_verbose (
15221527 expr. span . shrink_to_hi ( ) ,
15231528 format ! (
1524- "use `.borrow()` to borrow the {ty}, \
1525- panicking if any outstanding mutable borrows exist."
1529+ "use `.borrow()` to borrow the ` {ty}` , \
1530+ panicking if any outstanding mutable borrows exist."
15261531 ) ,
15271532 ".borrow()" ,
15281533 Applicability :: MaybeIncorrect ,
15291534 ) ;
15301535 }
1531- Some ( AutorefOrPtrAdjustment :: Autoref {
1532- mutbl : Mutability :: Mut , ..
1533- } ) => {
1536+ Some ( Mutability :: Mut ) => {
15341537 err. span_suggestion_verbose (
15351538 expr. span . shrink_to_hi ( ) ,
15361539 format ! (
1537- "use `.borrow_mut()` to mutably borrow the {ty}, \
1538- panicking if any outstanding borrows exist."
1540+ "use `.borrow_mut()` to mutably borrow the ` {ty}` , \
1541+ panicking if any outstanding borrows exist."
15391542 ) ,
15401543 ".borrow_mut()" ,
15411544 Applicability :: MaybeIncorrect ,
15421545 ) ;
15431546 }
1544- _ => return ,
1547+ None => return ,
15451548 }
15461549 } else if tcx. is_diagnostic_item ( sym:: Mutex , inner_id) {
15471550 err. span_suggestion_verbose (
15481551 expr. span . shrink_to_hi ( ) ,
15491552 format ! (
1550- "use `.lock()` to borrow the {ty}, \
1553+ "use `.lock()` to borrow the ` {ty}` , \
15511554 blocking the current thread until it can be acquired"
15521555 ) ,
15531556 ".lock().unwrap()" ,
15541557 Applicability :: MaybeIncorrect ,
15551558 ) ;
1559+ } else if tcx. is_diagnostic_item ( sym:: RwLock , inner_id) {
1560+ match mutable {
1561+ Some ( Mutability :: Not ) => {
1562+ err. span_suggestion_verbose (
1563+ expr. span . shrink_to_hi ( ) ,
1564+ format ! (
1565+ "use `.read()` to borrow the `{ty}`, \
1566+ blocking the current thread until it can be acquired"
1567+ ) ,
1568+ ".read().unwrap()" ,
1569+ Applicability :: MaybeIncorrect ,
1570+ ) ;
1571+ }
1572+ Some ( Mutability :: Mut ) => {
1573+ err. span_suggestion_verbose (
1574+ expr. span . shrink_to_hi ( ) ,
1575+ format ! (
1576+ "use `.write()` to mutably borrow the `{ty}`, \
1577+ blocking the current thread until it can be acquired"
1578+ ) ,
1579+ ".write().unwrap()" ,
1580+ Applicability :: MaybeIncorrect ,
1581+ ) ;
1582+ }
1583+ None => return ,
1584+ }
15561585 } else {
15571586 return ;
15581587 } ;
0 commit comments