@@ -1369,12 +1369,12 @@ pub enum PlaceContext {
13691369impl PlaceContext {
13701370 /// Returns `true` if this place context represents a drop.
13711371 #[ inline]
1372- pub fn is_drop ( & self ) -> bool {
1372+ pub fn is_drop ( self ) -> bool {
13731373 matches ! ( self , PlaceContext :: MutatingUse ( MutatingUseContext :: Drop ) )
13741374 }
13751375
13761376 /// Returns `true` if this place context represents a borrow.
1377- pub fn is_borrow ( & self ) -> bool {
1377+ pub fn is_borrow ( self ) -> bool {
13781378 matches ! (
13791379 self ,
13801380 PlaceContext :: NonMutatingUse (
@@ -1384,7 +1384,7 @@ impl PlaceContext {
13841384 }
13851385
13861386 /// 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 {
13881388 matches ! (
13891389 self ,
13901390 PlaceContext :: NonMutatingUse ( NonMutatingUseContext :: RawBorrow )
@@ -1394,7 +1394,7 @@ impl PlaceContext {
13941394
13951395 /// Returns `true` if this place context represents a storage live or storage dead marker.
13961396 #[ inline]
1397- pub fn is_storage_marker ( & self ) -> bool {
1397+ pub fn is_storage_marker ( self ) -> bool {
13981398 matches ! (
13991399 self ,
14001400 PlaceContext :: NonUse ( NonUseContext :: StorageLive | NonUseContext :: StorageDead )
@@ -1403,18 +1403,18 @@ impl PlaceContext {
14031403
14041404 /// Returns `true` if this place context represents a use that potentially changes the value.
14051405 #[ inline]
1406- pub fn is_mutating_use ( & self ) -> bool {
1406+ pub fn is_mutating_use ( self ) -> bool {
14071407 matches ! ( self , PlaceContext :: MutatingUse ( ..) )
14081408 }
14091409
14101410 /// Returns `true` if this place context represents a use.
14111411 #[ inline]
1412- pub fn is_use ( & self ) -> bool {
1412+ pub fn is_use ( self ) -> bool {
14131413 !matches ! ( self , PlaceContext :: NonUse ( ..) )
14141414 }
14151415
14161416 /// 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 {
14181418 matches ! (
14191419 self ,
14201420 PlaceContext :: MutatingUse (
@@ -1424,4 +1424,19 @@ impl PlaceContext {
14241424 )
14251425 )
14261426 }
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+ }
14271442}
0 commit comments