Re:From Zero to Main(): Bare Metal Rust
by wahern on Wednesday December 18, 2019 @01:08AM
(#21822285)
> you can't take two mutable references to the same variable in unsafe block,
Huh? Creating multiple, unchecked mutable references to the same object is one of the few reasons to even use unsafe. If you get this wrong, Rust's type safety won't save you--any bug effectively undermines the integrity of the remainder of the program. Of course, that doesn't negate the benefits of Rust's type safety, or mean that any program using unsafe is no better than a C or C++ project.
Re:From Zero to Main(): Bare Metal Rust
by steveklabnik on Wednesday December 18, 2019 @01:52AM
(#21822493)
Usually, "mutable reference" refers to &mut T. "mutable pointer" refers to *mut T. Creating aliasing &mut Ts is UB, even in an unsafe block.
Sometimes people are not precise about these words, but that's how I read the parent, given they drew the distinction between "mutable reference"s and "raw pointers".
2. That's not correct. Board support packages have some unsafe code in them, sure, but it's a misconception that this defeats the purpose of Rust. Even unsafe code has to uphold borrow checker semantics. Unsafe doesn't turn them off, you can't take two mutable references to the same variable in unsafe block, it won't compile. But you can use raw pointers and it's developer's job to make sure that pointer math is correct. This way your application code calling these low level bits of unsafe code doesn't have to do anything to benefit from the regular Rust guarantees. It's a "make things correct once, benefit always" sort of a deal.
3. In general Rust build times aren't great but I can't say they are worse than working with TI's CCS. Extended compile times on desktop are noticeable but I can't say this is true to the same extent on bare metal.