-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Detect multiple versions of crates with global state, which can result in bugs. #2363
Comments
This would probably be much simpler as an unstable lint plugin running in crater (or even a completely new dedicated crates.io pass), now that I think about it. |
I suspect this would probably work much better as an opt-in rather than an auto-detection scenario, but definitely seems like a legitimate thing to worry about |
@eddyb It's worth noting that not all lazy/static/etc is relevant — for example, in libfringe, I cache the page size (with loose ordering), which isn't global state and can run multiple times just fine, since it's just an optimisation. |
@edef1c In that case I would expect you to suppress a warning, if it ends up being a built-in lint. |
In https://github.com/rust-locale/rust-locale I intend to work around this issue by extracting the globals into a helper crate and have the main crate depend on any version of it ( However, |
Also there is another situation where multiple versions cause a problem: If crates A and B implement some trait provided by crate C, but they chose different versions of it, then the crate including them will not be able to pass types from both to functions from C requiring that trait. This is also problem for This problem is less dangerous, but more serious, because when it happens, it breaks compilation. |
I'm going to close this issue, because I think the problems discussed can be solved with one of: Please reopen if I'm wrong! |
Generally, in the absence of global state, via
static
or linking to C libraries, multiple instances of the same crate should be harmless, and the same-version case is already getting deduplicated.As thread-local support and
lazy_static
usestatic
internally, they should get caught as well.I'm not sure what the best way for detecting this is, short of using
--pretty=expanded
and searching forstatic
and link attributes.As far as I'm aware, this has caused issues in the past with the
log
crate, whereenv_logger
would have a visible effect only for some crates and not others.It could have worse consequences, if a crate is using some static flag to guard initialization/uses of a C library, and multiple versions of that crate use the same C library (e.g. system-wide
OpenGL
), potentially allowing data races and other memory unsafe behavior.In those instances, it might be even better to have an option in the
Cargo.toml
of such crates to deny having multiple versions downstream, with thestatic
& linkage detection as a lint suggesting that the option be enabled.cc @whitequark @edef1c
The text was updated successfully, but these errors were encountered: