-
Notifications
You must be signed in to change notification settings - Fork 1
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
Meaning of validity after a mutator panic #1
Comments
Thanks! that's a very interesting point. I think some update to the documentation is in order, because the current At the moment, the only hard "promises" are that the invariant is asserted after construction and on mutation exit. That said, I'm working on a |
Note that it does not hinge on the validator alone. Indeed, we can panic exit within the mutator to trigger the same issue: // Setup code like above
let mut obs = Observer(Letter::new('a').unwrap());
obs.0.mutate(|l| {
*l = '0';
panic!("Avoid ever checking the validator")
}); |
Seems then like this is mainly a problem with the I will probably leave The |
The protecting code of mutators does not protect the (implicit) panic exit point with assertions of the invariant holding. This makes it possible to observe an instace of a tightness-defined type whose invariant is in fact violated.
However, for usual validity invariants such as those upheld by
str
orNonZeroU8
etc. even this kind of observation is forbidden. This may be a concious design decision as the only 'correct' way to handle this would be an immediate program abort instead of a usual panic. For the fallbackmutate_or
it is at least theoretically possible to handle it correctly while continuing to panic but you need to assign toself
through a drop-guard instead of a code path that is never reached on panic unwinding.The text was updated successfully, but these errors were encountered: