@@ -1428,7 +1428,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1428
1428
item_name,
1429
1429
field_ty,
1430
1430
call_expr,
1431
- ProbeScope :: AllTraits ,
1431
+ ProbeScope :: TraitsInScope ,
1432
1432
)
1433
1433
. ok ( )
1434
1434
. map ( |pick| ( variant, field, pick) )
@@ -1500,59 +1500,88 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1500
1500
item_name,
1501
1501
ty,
1502
1502
call_expr,
1503
- ProbeScope :: AllTraits ,
1503
+ ProbeScope :: TraitsInScope ,
1504
1504
) else { return ; } ;
1505
1505
1506
1506
let name = self . ty_to_value_string ( actual) ;
1507
1507
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
+ } ;
1508
1515
1509
1516
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 " ) ;
1511
1518
} else if Some ( kind. did ( ) ) == tcx. lang_items ( ) . maybe_uninit ( ) {
1512
1519
err. help ( format ! (
1513
1520
"if this `{name}` has been initialized, \
1514
1521
use one of the `assume_init` methods to access the inner value"
1515
1522
) ) ;
1516
1523
} 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 ) => {
1521
1526
err. span_suggestion_verbose (
1522
1527
expr. span . shrink_to_hi ( ) ,
1523
1528
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."
1526
1531
) ,
1527
1532
".borrow()" ,
1528
1533
Applicability :: MaybeIncorrect ,
1529
1534
) ;
1530
1535
}
1531
- Some ( AutorefOrPtrAdjustment :: Autoref {
1532
- mutbl : Mutability :: Mut , ..
1533
- } ) => {
1536
+ Some ( Mutability :: Mut ) => {
1534
1537
err. span_suggestion_verbose (
1535
1538
expr. span . shrink_to_hi ( ) ,
1536
1539
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."
1539
1542
) ,
1540
1543
".borrow_mut()" ,
1541
1544
Applicability :: MaybeIncorrect ,
1542
1545
) ;
1543
1546
}
1544
- _ => return ,
1547
+ None => return ,
1545
1548
}
1546
1549
} else if tcx. is_diagnostic_item ( sym:: Mutex , inner_id) {
1547
1550
err. span_suggestion_verbose (
1548
1551
expr. span . shrink_to_hi ( ) ,
1549
1552
format ! (
1550
- "use `.lock()` to borrow the {ty}, \
1553
+ "use `.lock()` to borrow the ` {ty}` , \
1551
1554
blocking the current thread until it can be acquired"
1552
1555
) ,
1553
1556
".lock().unwrap()" ,
1554
1557
Applicability :: MaybeIncorrect ,
1555
1558
) ;
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
+ }
1556
1585
} else {
1557
1586
return ;
1558
1587
} ;
0 commit comments