Babur Makhmudov
Babur Makhmudov

Reputation: 532

Can unused struct field be optimized away by rust compiler?

Imagine a self-referential struct (simplified for clarity)

struct Storage {
    /// a mutable pointer into memory region owned by `_store`
    store: *mut u8,
    /// underlying memory buffer
    _store: Box<[u8]>,
}

If _store field is never used directly after being initialized, is it possible for rust/llvm compiler to optimize it away? If so what will happen to store, will it be a dangling pointer or something more outrageous? :)

Upvotes: 0

Views: 45

Answers (0)

Related Questions