rust-lang / rust-lang/rust

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

Open
#159,644 15 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-coherence A-trait-system C-discussion requires-nightly T-libs T-types
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> (with thin_box feature)
  • ToString for T

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.