3 ms·
Unsafe code allows programmers to write code the compiler can’t check. Unsafe code is expected to uphold the safety invariants, but humans can make mistakes. M
by steveklabnik 9y ago
Unsafe code allows programmers to write code the compiler can’t check. Unsafe code is expected to uphold the safety invariants, but humans can make mistakes.
Most people mean “safe Rust” when they say “Rust.”
Leaks are memory safe though. They’re hard, but not impossible, to get.
- sidlls 9y ago> Most people mean “safe Rust” when they say “Rust.” I disagree. I think they mean Rust code they see in use that has no explicit "unsafe" blocks. For example, most people are going to say "let mut v = Vec::<i32>::new(); v.push(0)" is "safe Rust." It is, in the sense that all the rules of Rust safety apply to the specific code quoted as-is. It also isn't, because 'Vec' is littered with unsafe.
- steveklabnik 9y agoThat’s what I mean by “safe Rust”, so we agree.
- sidlls 9y agoWe don't, though. The quoted code isn't safe. It has implicit unsafe blocks in it. You can't claim there are two dialects of Rust if you inlcude the "unsafe" dialect in your definition of "safe" as long as there isn't an explicit "unsafe" block present. It's misleading
- steveklabnik 9y agoThat's not a useful definition, though, as that means that all code everywhere is unsafe, since the hardware is.
- dbaupp 9y agoIf you're wearing x-ray glasses to look at the implementation details, no language is safe (e.g. CPython's vectors/lists are written in C). It isn't a useful contention.