3 ms·
Which makes me wonder : 1/ could you build the same unsafe behiavor in Rust if you wanted to by not specifying lifetime constraints ? 2/ If yes, shouldn't lif
by bsaul 12y ago
Which makes me wonder :
1/ could you build the same unsafe behiavor in Rust if you wanted to by not specifying lifetime constraints ?
2/ If yes, shouldn't lifetime constraints be mandatory ?
- dbaupp 12y agoThe compiler will not compile code it cannot verify as safe (outside an `unsafe` block), meaning it will complain about lifetime constraints that are missing, e.g. it is a compile-time error to not propagate the lifetime information out of the enum. http://play.rust-lang.org/?run=1&code=enum%20Token%20{%0A%20%20%20%20Word%28%26str%29%2C%0A%20%20%20%20Other%28%26str%29%0A}%0A%0Afn%20main%28%29%20{} http://play.rust-lang.org/?run=1&code=enum%20Token%20{%0A%20...
- nikic 12y agoThe lifetime constraint in the enum is mandatory, the code won't compile without it. The tokenization function itself doesn't have to explicitly specify lifetimes like it does in the blog post. It would also work without them and Rust would still ensure that you don't end up with a use-after-free.