When building `alloc` with `no_global_oom_handling`, numerous disabled `impl`s for `Box`, `Vec`, `Rc`, `Arc` can be written by downstream code for local types
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
In https://github.com/rust-lang/rust/pull/157428/changes#r3620330696, @theemathas and I found that the Clone impl of Box is behind cfg(not(no_global_oom_handling)). This is weird, because Box is #[fundamental]. Downstream users can do this:
#![no_std]
use alloc::boxed::Box;
extern crate alloc;
#[derive(Clone)]
struct LocalType;
impl Clone for Box<LocalType> {
fn clone(&self) -> Self {
panic!("wat")
}
}
This successfully builds with RUSTFLAGS="--cfg no_global_oom_handling -Cpanic=abort" cargo +nightly build -Z build-std=core,alloc.
Fullish list of affected impls under the orphan rule (using #\[cfg\(.*\)\]\n(\s*#\[.*\]\n)*\s*impl):
Clone for Box<T, A>FromIterator<T> for Rc<[T]>/Arc<[T]>/Vec<T>/Box<[T]>From<Box<T, A>> for Rc<T, A>/Arc<T, A>From<T> for Rc<T>/Arc<T>/Box<T>Default for Box<T>Default for Pin<Box<T>>Extend<T> for Vec<T, A>Extend<&'a T> for Vec<T, A>Concat<T> for [T]Join<&T> for [T]From<E> for Box<dyn Error + 'a>From<E> for Box<dyn Error + Send + Sync + 'a>From<T> for ThinBox<T>(withthin_boxfeature)ToString for T
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Review the cfg-gated impls for Box, Vec, Rc, Arc, Pin, ThinBox, and slices, using the linked pull request discussion and affected-impl list to define the scope. Reproduce the downstream example with the shown no_std cargo build command; done means the listed disabled impls no longer remain available for downstream local types under no_global_oom_handling.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100