|
|
|
|
|
by Ygg2
9 days ago
|
|
> True, but unsafe let's you conjure up any lifetime you want The only thing unsafe does is let you have an unbounded lifetime. As I said, it doesn't check those: fn get_str<'a>(s: *const String) -> &'a str {
unsafe { &*s }
}
https://doc.rust-lang.org/nomicon/unbounded-lifetimes.html> if you generously sprinkle pointer dereferences in unsafe code, you effectively disable the protection provided by the borrow checker You don't disable anything. You wrote a "trust me compiler" block, and compiler trusted you. Rust won't ever protect from all possible problems, just the ones the compiler handles. |
|
That’s the same thing.