[−][src]Enum rustc_middle::ty::BorrowKind
Variants
Data must be immutable and is aliasable.
Data must be immutable but not aliasable. This kind of borrow cannot currently be expressed by the user and is used only in implicit closure bindings. It is needed when the closure is borrowing or mutating a mutable referent, e.g.:
let x: &mut isize = ...; let y = || *x += 5;
If we were to try to translate this closure into a more explicit form, we'd encounter an error with the code as written:
struct Env { x: & &mut isize } let x: &mut isize = ...; let y = (&mut Env { &x }, fn_ptr); // Closure is pair of env and fn fn fn_ptr(env: &mut Env) { **env.x += 5; }
This is then illegal because you cannot mutate a &mut found
in an aliasable location. To solve, you'd have to translate with
an &mut borrow:
struct Env { x: & &mut isize } let x: &mut isize = ...; let y = (&mut Env { &mut x }, fn_ptr); // changed from &x to &mut x fn fn_ptr(env: &mut Env) { **env.x += 5; }
Now the assignment to **env.x is legal, but creating a
mutable pointer to x is not because x is not mutable. We
could fix this by declaring x as let mut x. This is ok in
user code, if awkward, but extra weird for closures, since the
borrow is hidden.
So we introduce a "unique imm" borrow -- the referent is immutable, but not aliasable. This solves the problem. For simplicity, we don't give users the way to express this borrow, it's just used when translating closures.
Data is mutable and not aliasable.
Implementations
impl BorrowKind[src]
pub fn from_mutbl(m: Mutability) -> BorrowKind[src]
pub fn to_mutbl_lossy(self) -> Mutability[src]
Returns a mutability m such that an &m T pointer could be used to obtain this borrow
kind. Because borrow kinds are richer than mutabilities, we sometimes have to pick a
mutability that is stronger than necessary so that it at least would permit the borrow in
question.
pub fn to_user_str(&self) -> &'static str[src]
Trait Implementations
impl Clone for BorrowKind[src]
pub fn clone(&self) -> BorrowKind[src]
pub fn clone_from(&mut self, source: &Self)1.0.0[src]
impl Copy for BorrowKind[src]
impl Debug for BorrowKind[src]
impl<'tcx, __D: TyDecoder<'tcx>> Decodable<__D> for BorrowKind[src]
impl<'tcx, __E: TyEncoder<'tcx>> Encodable<__E> for BorrowKind[src]
impl<'__ctx> HashStable<StableHashingContext<'__ctx>> for BorrowKind[src]
pub fn hash_stable(
&self,
__hcx: &mut StableHashingContext<'__ctx>,
__hasher: &mut StableHasher
)[src]
&self,
__hcx: &mut StableHashingContext<'__ctx>,
__hasher: &mut StableHasher
)
impl PartialEq<BorrowKind> for BorrowKind[src]
pub fn eq(&self, other: &BorrowKind) -> bool[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool1.0.0[src]
impl StructuralPartialEq for BorrowKind[src]
Auto Trait Implementations
impl RefUnwindSafe for BorrowKind
impl Send for BorrowKind
impl Sync for BorrowKind
impl Unpin for BorrowKind
impl UnwindSafe for BorrowKind
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<'tcx, T> ArenaAllocatable<'tcx, ()> for T where
T: Copy, [src]
T: Copy,
pub fn allocate_on(Self, &'a Arena<'tcx>) -> &'a mut T[src]
pub fn allocate_from_iter(
&'a Arena<'tcx>,
impl IntoIterator<Item = T>
) -> &'a mut [T][src]
&'a Arena<'tcx>,
impl IntoIterator<Item = T>
) -> &'a mut [T]
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T[src]
impl<'a, T> Captures<'a> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T> MaybeResult<T> for T[src]
type Error = !
pub fn from(Result<T, <T as MaybeResult<T>>::Error>) -> T[src]
pub fn to_result(self) -> Result<T, <T as MaybeResult<T>>::Error>[src]
impl<T> ToOwned for T where
T: Clone, [src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T[src]
pub fn clone_into(&self, target: &mut T)[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.