Enum rustc::mir::BorrowKind [−][src]
pub enum BorrowKind {
Shared,
Unique,
Mut {
allow_two_phase_borrow: bool,
},
}🔬 This is a nightly-only experimental API. (rustc_private)
this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml instead?
Variants
🔬 This is a nightly-only experimental API. (rustc_private)
this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml instead?
Data must be immutable and is aliasable.
Unique🔬 This is a nightly-only experimental API. (rustc_private)
this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml instead?
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 you 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.
Mut🔬 This is a nightly-only experimental API. (rustc_private)
this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml instead?
Data is mutable and not aliasable.
Fields of Mut
allow_two_phase_borrow: bool | 🔬 This is a nightly-only experimental API. ( |
Methods
impl BorrowKind[src]
impl BorrowKindpub fn to_mutbl_lossy(self) -> Mutability[src]
pub fn to_mutbl_lossy(self) -> Mutability🔬 This is a nightly-only experimental API. (rustc_private)
this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml instead?
impl BorrowKind[src]
impl BorrowKindpub fn allows_two_phase_borrow(&self) -> bool[src]
pub fn allows_two_phase_borrow(&self) -> bool🔬 This is a nightly-only experimental API. (rustc_private)
this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml instead?
Trait Implementations
impl<'a> HashStable<StableHashingContext<'a>> for BorrowKind[src]
impl<'a> HashStable<StableHashingContext<'a>> for BorrowKindfn hash_stable<W: StableHasherResult>(
&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>
)[src]
fn hash_stable<W: StableHasherResult>(
&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>
)🔬 This is a nightly-only experimental API. (rustc_private)
this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml instead?
impl Copy for BorrowKind[src]
impl Copy for BorrowKindimpl Clone for BorrowKind[src]
impl Clone for BorrowKindfn clone(&self) -> BorrowKind[src]
fn clone(&self) -> BorrowKindReturns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)1.0.0[src]
fn clone_from(&mut self, source: &Self)Performs copy-assignment from source. Read more
impl Debug for BorrowKind[src]
impl Debug for BorrowKindfn fmt(&self, f: &mut Formatter) -> Result[src]
fn fmt(&self, f: &mut Formatter) -> ResultFormats the value using the given formatter. Read more
impl PartialEq for BorrowKind[src]
impl PartialEq for BorrowKindfn eq(&self, other: &BorrowKind) -> bool[src]
fn eq(&self, other: &BorrowKind) -> boolThis method tests for self and other values to be equal, and is used by ==. Read more
fn ne(&self, other: &BorrowKind) -> bool[src]
fn ne(&self, other: &BorrowKind) -> boolThis method tests for !=.
impl Eq for BorrowKind[src]
impl Eq for BorrowKindfn assert_receiver_is_total_eq(&self)[src]
fn assert_receiver_is_total_eq(&self)impl Encodable for BorrowKind[src]
impl Encodable for BorrowKindfn encode<__S: Encoder>(&self, s: &mut __S) -> Result<(), __S::Error>[src]
fn encode<__S: Encoder>(&self, s: &mut __S) -> Result<(), __S::Error>🔬 This is a nightly-only experimental API. (rustc_private)
this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml instead?
impl Decodable for BorrowKind[src]
impl Decodable for BorrowKindAuto Trait Implementations
impl Send for BorrowKind
impl Send for BorrowKindimpl Sync for BorrowKind
impl Sync for BorrowKind