Skip to content

Make box covariant#304

Open
ElchananHaas wants to merge 1 commit intofitzgen:mainfrom
ElchananHaas:covariantbox
Open

Make box covariant#304
ElchananHaas wants to merge 1 commit intofitzgen:mainfrom
ElchananHaas:covariantbox

Conversation

@ElchananHaas
Copy link

@ElchananHaas ElchananHaas commented Feb 13, 2026

This CR makes the box covariant in 'a to allow for more use cases. This addresses #170.

Making it covariant should be OK for the same reasons as the standard library box is safe. Quoting the RustNomicon (https://doc.rust-lang.org/nomicon/subtyping.html)

As it turns out, the argument for why it's ok for Box (and Vec, HashMap, etc.) to be covariant is pretty similar to the argument for why it's ok for lifetimes to be covariant: as soon as you try to stuff them in something like a mutable reference, they inherit invariance and you're prevented from doing anything bad.

The Bumpalo Vec is already covariant.

I tested this code by running

cargo test --features boxed 

I checked that all tests passed. I also added a unit test for covariance. I wasn't able to come up with a great test, but I verified that the test fails if I make the lifetime invariant.

I additionally ran

cargo miri test --features boxed

miri passed all tests. It complains about some memory leaks in raw_vec, but that should be unrelated.

@ElchananHaas
Copy link
Author

The build is failing

  [0](https://github.com/fitzgen/bumpalo/actions/runs/21973607396/job/63480335544?pr=304#step:5:21)
  error: failed to download replaced source registry `crates-io`
  
  Caused by:
    failed to parse manifest at `/home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rand_core-0.10.0/Cargo.toml`
  
  Caused by:
    failed to parse the `edition` key
  
  Caused by:
    this version of Cargo is older than the `2024` edition, and only supports `2015`, `2018`, and `2021` editions.
  Error: Process completed with exit code 101.

I think this is unrelated.

@ElchananHaas
Copy link
Author

I did some digging and it turns out the issue is quickcheck = "1.0.3" is getting upgraded to quickcheck = "1.1.0" which in turn pulls in rand = "0.10.0". That version of rand is incompatible with Bumpalo's MSRV. Should I pin quickcheck = "=1.0.3" in this PR or raise a separate PR?

@ElchananHaas ElchananHaas mentioned this pull request Feb 13, 2026
@ElchananHaas
Copy link
Author

I fixed the build issue in #306

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

Successfully merging this pull request may close these issues.

1 participant