| ▲ | thinkharderdev 2 hours ago | |||||||||||||||||||||||||
Rust is supposed to guarantee statically that a reference cannot outlive its referent. The `T: 'static` bound means that the value that Q holds must have a 'static lifetime (e.g. either be an owned value or a reference to a static value). So this program should not compile since a reference to l is not 'static. This code is unsound because rust will drop the string l before q so when the Q destructor runs the underlying string has already been freed yet we have a valid reference to it. | ||||||||||||||||||||||||||
| ▲ | biorach an hour ago | parent | next [-] | |||||||||||||||||||||||||
> rust will drop the string l before q Why? | ||||||||||||||||||||||||||
| ||||||||||||||||||||||||||
| ▲ | 1718627440 2 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||
So the equivalent in C would be:
(The equivalent warning is main.c:47) | ||||||||||||||||||||||||||
| ||||||||||||||||||||||||||
| ▲ | 1718627440 2 hours ago | parent | prev [-] | |||||||||||||||||||||||||
What does "q.0" and "Some(...)" mean? | ||||||||||||||||||||||||||
| ||||||||||||||||||||||||||