Enum rustc::middle::ty::BorrowKind[src]
pub enum BorrowKind {
ImmBorrow,
UniqueImmBorrow,
MutBorrow,
}Variants
ImmBorrow | Data must be immutable and is aliasable. |
UniqueImmBorrow | 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 int = ...; 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 int } let x: &mut int = ...; 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 struct Env { x: & &mut int } let x: &mut int = ...; 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 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. |
MutBorrow | Data is mutable and not aliasable. |