-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The content of the lazy static should require RefUnwindSafe #53
Comments
Related comment: rust-lang/rust#37136 (comment) |
Hi, I'm sincerely sorry for taking so long to respond. Could you elaborate a bit on which kind of modification is the problem here? I'm not sure if the issue refers to the |
It's about the content of the static having internal mutability. Imagine you call a method on the static object. This method takes a Later another piece of code accesses the same static object and observes this invalid state. However keep in mind that the situation about panic safety is a bit blurry in Rust right now. The |
Ah, I see. Am I right in thinking that this issue can in theory happen with a plain old If so then I would just mirror what is done in that case - and afaik I'll leave this open until the situation around panic safety becomes more clear. (Also, adding the bound would be a breaking change as well, so I'd rather not experiment needlessly :)) |
Well, I don't see how you could modify the content of a non-mut static. |
A plain non-mut static can contain internal mutability types, like for example the atomics from the std lib. |
I may not be up to date, but I thought that anything requiring a constructor (eg. a Mutex) couldn't be put in a static. |
It's still a unstable feature, but its allowed now. See here. The main issue is more the initialization code needed might exceed what is possible within a constant or constexpr, but thats an issue about being able to initialize the thing, not about the unwind semantic if it where constructed in a static. |
My understanding here is that we don't need to worry about the unwind safety during initialization because For the value itself, we inherit its unwind safety from the standard library: impl<'a, T: RefUnwindSafe + ?Sized> UnwindSafe for &'a T {}
impl<T: RefUnwindSafe + ?Sized> UnwindSafe for *const T {}
impl<T: RefUnwindSafe + ?Sized> UnwindSafe for *mut T {} If the value So I think the current state of affairs is ok? |
The problem is not using unwind-unsafe values inside |
@tomaka Hmm, you can't get in a situation where you use the value after you've caught and ignored the panic, because you can't catch and ignore the panic in the first place unless the value is unwind safe, right? |
Oh, you're saying that you can't access the lazy_static in the first place if it's not |
That's right, unless you clobber it using So I think we're doing the right thing here in |
It is possible that a panic happens while a lazy static is being modified, and leave the lazy static in an invalid state.
The user could then catch the unwind and continue to use the object in its invalid state.
That's the reason why the
UnwindSafe
andRefUnwindSafe
traits were invented.The text was updated successfully, but these errors were encountered: