|
|
|
|
|
by afdbcreid
1638 days ago
|
|
The borrow checker does not affect code generation. Lifetimes are completely elided when codegen'ing. What _does_ affect code generation is Rust's rules about borrowing and so. If borrowck was affecting codegen, stuff like `RefCell` wasn't possible. |
|
But in the end most times people (outside of the rusty community) speak about rusts borrow checking it's about the combination of checking lifetime, "pointe" aliasing rules and the (not fully specified) memory model. I.e it's ownership model.
And while lifetimes get eliminated at some point in compilation this is after making sure they are correct, which enables rust to use a "pointer" aliasing model for it's references which is subtle different from C-pointers in ways which affects code generation.
I.e. they implicitly affect code generation in the way they affect what the rust language/compiler can do/can rely on (like relying on being often able to mark &Mut as noalias).
I.e. if you write unsafe code assuming lifetimes are just about making sure memory is freed correctly you will produce unsound code.