pub struct BorrowChecker { /* private fields */ }Expand description
Compile-time borrow checker embedded in BytecodeCompiler.
Tracks active borrows per-slot and enforces aliasing rules. Borrows are scoped to regions (lexical scopes) and automatically released when their region exits.
Implementations§
Source§impl BorrowChecker
impl BorrowChecker
Sourcepub fn enter_region(&mut self) -> RegionId
pub fn enter_region(&mut self) -> RegionId
Enter a new lexical scope (creates a new region).
Sourcepub fn exit_region(&mut self)
pub fn exit_region(&mut self)
Exit the current lexical scope, releasing all borrows created in it.
Sourcepub fn current_region(&self) -> RegionId
pub fn current_region(&self) -> RegionId
Get the current region ID.
Sourcepub fn create_borrow(
&mut self,
slot: u16,
ref_slot: u16,
mode: BorrowMode,
span: Span,
source_location: Option<SourceLocation>,
) -> Result<(), ShapeError>
pub fn create_borrow( &mut self, slot: u16, ref_slot: u16, mode: BorrowMode, span: Span, source_location: Option<SourceLocation>, ) -> Result<(), ShapeError>
Create a borrow of slot into ref_slot.
If is_exclusive is true (callee mutates), enforces:
- No other borrows (shared or exclusive) exist for
slot
If is_exclusive is false (callee reads only), enforces:
- No exclusive borrows exist for
slot
Sourcepub fn check_write_allowed(
&self,
slot: u16,
source_location: Option<SourceLocation>,
) -> Result<(), ShapeError>
pub fn check_write_allowed( &self, slot: u16, source_location: Option<SourceLocation>, ) -> Result<(), ShapeError>
Check whether a write to slot is allowed (fails if any borrow exists).
Sourcepub fn check_read_allowed(
&self,
slot: u16,
source_location: Option<SourceLocation>,
) -> Result<(), ShapeError>
pub fn check_read_allowed( &self, slot: u16, source_location: Option<SourceLocation>, ) -> Result<(), ShapeError>
Check whether a direct read from slot is allowed.
Reads are blocked while the slot has an active exclusive borrow.
Sourcepub fn check_no_escape(
&self,
ref_slot: u16,
source_location: Option<SourceLocation>,
) -> Result<(), ShapeError>
pub fn check_no_escape( &self, ref_slot: u16, source_location: Option<SourceLocation>, ) -> Result<(), ShapeError>
Check that a reference does not escape its scope. Called when a ref_slot might be returned or stored.
Auto Trait Implementations§
impl Freeze for BorrowChecker
impl RefUnwindSafe for BorrowChecker
impl Send for BorrowChecker
impl Sync for BorrowChecker
impl Unpin for BorrowChecker
impl UnsafeUnpin for BorrowChecker
impl UnwindSafe for BorrowChecker
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more