-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Update vec.rs #27068
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
Update vec.rs #27068
Conversation
Check the capacity of `Vec<T>` that is more than or equal to length.
r? @huonw (rust_highfive has picked a reviewer for you, use r? to override) |
This looks good to me - I think this invariant is strongly-implied by the existing docs. But it is not stated explicitly, do you mind adding a bullet to the 'Unsafety' section stating this invariant? @alexcrichton does this debug assert seem appropriate to you? Do we have other debug asserts enforcing invariants like this in std? |
Hm, note that nobody will ever hit this because std is never compiled with debug asserts. This mostly serves as code docs. |
@brson std is never compiled with debug asserts? Even with a |
@pnkfelix oh, 'never' is too strong of course. More like users never see debug asserts in std. |
@brson I just wanted this to be working in debug mode for the users, wondering if it won't work (libcollections is not compiled with support of |
The |
This also has exception-safety implications. e.g. if someone doesn't expect this to panic, but it suddenly does in debug, that's not great... although on the other hand it's basically UB to hit this assert anyway. Also as has been noted, this will literally only run if someone builds their own custom compiler with debug assertions turned on. Using a stable/beta/nightly build this assertion will be stripped. |
@rick68 Unfortunately, because 'std' itself is compiled in release mode, even when users of std compile their projects in debug mode they will not get debug assertions that originate in std. |
Thinking about generics, But this is the risk what I have to take if I want to use |
@rick68 yes most collections are generally unsafe. Anyway, it seems like we agree this should be closed. |
Check the capacity of
Vec<T>
that is more than or equal to length.