Skip to content
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

Hashbrown fails to compile if 0.14.x and 0.15.x are in the same project, only one with the nightly feature #564

Open
orlp opened this issue Oct 3, 2024 · 5 comments

Comments

@orlp
Copy link

orlp commented Oct 3, 2024

If a project (most likely indirectly through dependencies) depends on both version 0.14.x and 0.15.x of hashbrown, and only one of the two dependencies has the nightly feature flag set, the project will fail to compile due to using the allocator_api without enabling the unstable feature for it:

error[E0658]: use of unstable library feature 'allocator_api'
    --> /Users/orlp/.cargo/registry/src/index.crates.io-6f17d22bba15001f/hashbrown-0.14.5/src/raw/mod.rs:4329:23
     |
4329 |                 alloc.deallocate(ptr, layout);
     |                       ^^^^^^^^^^
     |
     = note: see issue #32838 <https://github.com/rust-lang/rust/issues/32838> for more information
     = help: add `#![feature(allocator_api)]` to the crate attributes to enable
     = note: this compiler was built on 2024-10-02; consider upgrading it if it is out of date

This can be reproduced by making a clean new project and adding the following two lines to Cargo.toml:

hashbrown_14 = { package = "hashbrown", version = "=0.14.5", features = [] }
hashbrown_15 = { package = "hashbrown", version = "=0.15.0", features = ["nightly"] }

If it's just one of the two the project compiles fine, regardless of the nightly feature flag. If neither or both have the nightly feature flag everything compiles fine as well. However if one has the nightly feature flag and the other does not, the project doesn't compile.

@orlp orlp changed the title Hashbrown fails to compile if 0.14.x and 0.15.x are in the same project, one with nightly feature Hashbrown fails to compile if 0.14.x and 0.15.x are in the same project, only one with the nightly feature Oct 3, 2024
@orlp
Copy link
Author

orlp commented Oct 3, 2024

The problem appears to be that allocator-api2's recommended usage is inherently flawed:

Your library MAY provide a feature that will enable "allocator-api2/nightly". When this feature is enabled, your library MUST enable unstable #![feature(allocator_api)] or it may not compile. If feature is not provided, your library may not be compatible with the rest of the users and cause compilation errors on nightly channel when some other crate enables "allocator-api2/nightly" feature.

Feature unification makes the requirement "When this feature is enabled your library MUST enable unstable #![feature(allocator_api)] or it may not compile" fundamentally impossible to fulfill.

@Amanieu
Copy link
Member

Amanieu commented Oct 3, 2024

I'm not sure there's anything actionable we can do on hashbrown's side...

@cuviper
Copy link
Member

cuviper commented Oct 3, 2024

allocator-api2/nightly re-exports from alloc, but hashbrown/nightly is already using alloc directly -- so I think there's no reason to forward the nightly feature at all. That will mean its Allocator won't match that from allocator-api2 (without nightly), but really, it's already a breaking change that these features change the types in public API.

vmagro added a commit to facebookincubator/antlir that referenced this issue Oct 11, 2024
Summary:
Use nightly Rust compiler and enable the `nightly` feature of `hashbrown` so
that it compiles (see rust-lang/hashbrown#564)

This wouldn't really be a problem if we correctly copied the internally used
versions of Rust libraries, but we miss crate versions in most cases so
sometimes skew causes problems like this.

Disable broken sendstream test

Fix #219

Test Plan: Export to PR

Differential Revision: D64256300
vmagro added a commit to facebookincubator/antlir that referenced this issue Oct 11, 2024
Summary:
Pull Request resolved: #264

Use nightly Rust compiler and enable the `nightly` feature of `hashbrown` so
that it compiles (see rust-lang/hashbrown#564)

This wouldn't really be a problem if we correctly copied the internally used
versions of Rust libraries, but we miss crate versions in most cases so
sometimes skew causes problems like this.

Disable broken sendstream test

Fix #219

Test Plan: Export to PR

Differential Revision: D64256300
vmagro added a commit to facebookincubator/antlir that referenced this issue Oct 11, 2024
Summary:
Pull Request resolved: #264

Use nightly Rust compiler and enable the `nightly` feature of `hashbrown` so
that it compiles (see rust-lang/hashbrown#564)

This wouldn't really be a problem if we correctly copied the internally used
versions of Rust libraries, but we miss crate versions in most cases so
sometimes skew causes problems like this.

Disable broken sendstream test

Fix #219

Test Plan: Export to PR

Differential Revision: D64256300
vmagro added a commit to facebookincubator/antlir that referenced this issue Oct 11, 2024
Summary:
Pull Request resolved: #264

Use nightly Rust compiler and enable the `nightly` feature of `hashbrown` so
that it compiles (see rust-lang/hashbrown#564)

This wouldn't really be a problem if we correctly copied the internally used
versions of Rust libraries, but we miss crate versions in most cases so
sometimes skew causes problems like this.

Disable broken sendstream test

Fix #219

Test Plan: Export to PR

Differential Revision: D64256300
facebook-github-bot pushed a commit to facebookincubator/antlir that referenced this issue Oct 11, 2024
Summary:
Pull Request resolved: #264

Use nightly Rust compiler and enable the `nightly` feature of `hashbrown` so
that it compiles (see rust-lang/hashbrown#564)

This wouldn't really be a problem if we correctly copied the internally used
versions of Rust libraries, but we miss crate versions in most cases so
sometimes skew causes problems like this.

Disable broken sendstream test

Fix #219

Test Plan: Export to PR

Reviewed By: justintrudell

Differential Revision: D64256300

fbshipit-source-id: 2d9965e3065dd9e8632a65b606d2b1210014777c
@BlinkyStitt
Copy link

I just ran into this because of dependencies of my dependencies using hasbrown 14 but my code having 15. I think the best action for hashbrown here is to document this so it comes up in search easily. The error message was confusing but thankfully searching the issue tracker for "allocator_api" brought me here.

@sassman
Copy link

sassman commented Dec 13, 2024

seems to be the same or similar as #483

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants