Skip to content

BTreeMap uses Global allocator in it's PhantomData even when instantiated with custom Allocator #121797

Closed
@shamatar

Description

@shamatar

I'm referring to this particular line

_marker: PhantomData<crate::boxed::Box<(K, V)>>,

Even though in no_std environments Global as a structure exists and is defined, and it only shows up in PhantomData, the use of the structure is most likely undefined if #[global_allocator] attribute is never used. Yes, there will be no calls to Global as it's only a phantom, and execution will not be affected, but just seems ill-defined at least.

For completeness: compilation of code that uses alloc::collection::BTreeMap with custom allocator under #![feature(btreemap_alloc)] is not affected, and there is no sign of runtime bugs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-allocatorsArea: Custom and system allocatorsA-collectionsArea: `std::collections`C-bugCategory: This is a bug.T-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions