Repository navigation
Conversation
|
r? @clarfonthey rustbot has assigned @clarfonthey. Use Why was this reviewer chosen?The reviewer was selected based on:
|
| // thread: if it is not yet initialized, and if the argument is `Some(&mut Some(val))`, the | ||
| // inner `val` should be `take`en out and used as the initial value instead of the default. This | ||
| // is purely an optimization for the case where the value will be immediately overwritten; it is | ||
| // okay for `inner` to always ignore `init`. |
There was a problem hiding this comment.
That's not always true, this only applies in the case of const-initialisers. In other cases, init must not be ignored as LocalKey::set guarantees that it will succeed even if the initialiser panics.
There was a problem hiding this comment.
Ah! The contract is quite subtle then. I updated the comment.
FWIW, if the destructor of the default value panics, that could still cause LocalKey::set to panic.
There was a problem hiding this comment.
Hmm, true. This seems almost impossible to prevent, and such behaviour isn't that surprising – but we should probably document it...
There was a problem hiding this comment.
Well we could prevent the unwind part of that panic with rust-lang/rfcs#3288... but some sort of failure (like abort) cannot really be prevented, yeah. It's also normal in Rust that seting a value drops the old value which can fail.
7280921 to
c9c2f66
Compare
c9c2f66 to
e62fd11
Compare
|
r? joboet since you seem to understand this better than I do. I'd just be guessing like Ralf is. |
|
|
#92123 gave this function an argument, but without documenting what the argument means or does. I hope I reverse engineered this correctly.
Cc @m-ou-se @joboet