@@ -1369,12 +1369,12 @@ pub enum PlaceContext {
1369
1369
impl PlaceContext {
1370
1370
/// Returns `true` if this place context represents a drop.
1371
1371
#[ inline]
1372
- pub fn is_drop ( & self ) -> bool {
1372
+ pub fn is_drop ( self ) -> bool {
1373
1373
matches ! ( self , PlaceContext :: MutatingUse ( MutatingUseContext :: Drop ) )
1374
1374
}
1375
1375
1376
1376
/// Returns `true` if this place context represents a borrow.
1377
- pub fn is_borrow ( & self ) -> bool {
1377
+ pub fn is_borrow ( self ) -> bool {
1378
1378
matches ! (
1379
1379
self ,
1380
1380
PlaceContext :: NonMutatingUse (
@@ -1384,7 +1384,7 @@ impl PlaceContext {
1384
1384
}
1385
1385
1386
1386
/// Returns `true` if this place context represents an address-of.
1387
- pub fn is_address_of ( & self ) -> bool {
1387
+ pub fn is_address_of ( self ) -> bool {
1388
1388
matches ! (
1389
1389
self ,
1390
1390
PlaceContext :: NonMutatingUse ( NonMutatingUseContext :: RawBorrow )
@@ -1394,7 +1394,7 @@ impl PlaceContext {
1394
1394
1395
1395
/// Returns `true` if this place context represents a storage live or storage dead marker.
1396
1396
#[ inline]
1397
- pub fn is_storage_marker ( & self ) -> bool {
1397
+ pub fn is_storage_marker ( self ) -> bool {
1398
1398
matches ! (
1399
1399
self ,
1400
1400
PlaceContext :: NonUse ( NonUseContext :: StorageLive | NonUseContext :: StorageDead )
@@ -1403,18 +1403,18 @@ impl PlaceContext {
1403
1403
1404
1404
/// Returns `true` if this place context represents a use that potentially changes the value.
1405
1405
#[ inline]
1406
- pub fn is_mutating_use ( & self ) -> bool {
1406
+ pub fn is_mutating_use ( self ) -> bool {
1407
1407
matches ! ( self , PlaceContext :: MutatingUse ( ..) )
1408
1408
}
1409
1409
1410
1410
/// Returns `true` if this place context represents a use.
1411
1411
#[ inline]
1412
- pub fn is_use ( & self ) -> bool {
1412
+ pub fn is_use ( self ) -> bool {
1413
1413
!matches ! ( self , PlaceContext :: NonUse ( ..) )
1414
1414
}
1415
1415
1416
1416
/// Returns `true` if this place context represents an assignment statement.
1417
- pub fn is_place_assignment ( & self ) -> bool {
1417
+ pub fn is_place_assignment ( self ) -> bool {
1418
1418
matches ! (
1419
1419
self ,
1420
1420
PlaceContext :: MutatingUse (
@@ -1424,4 +1424,19 @@ impl PlaceContext {
1424
1424
)
1425
1425
)
1426
1426
}
1427
+
1428
+ /// The variance of a place in the given context.
1429
+ pub fn ambient_variance ( self ) -> ty:: Variance {
1430
+ use NonMutatingUseContext :: * ;
1431
+ use NonUseContext :: * ;
1432
+ match self {
1433
+ PlaceContext :: MutatingUse ( _) => ty:: Invariant ,
1434
+ PlaceContext :: NonUse ( StorageDead | StorageLive | VarDebugInfo ) => ty:: Invariant ,
1435
+ PlaceContext :: NonMutatingUse (
1436
+ Inspect | Copy | Move | PlaceMention | SharedBorrow | FakeBorrow | RawBorrow
1437
+ | Projection ,
1438
+ ) => ty:: Covariant ,
1439
+ PlaceContext :: NonUse ( AscribeUserTy ( variance) ) => variance,
1440
+ }
1441
+ }
1427
1442
}
0 commit comments