Skip to content

When building alloc with no_global_oom_handling, numerous disabled impls for Box, Vec, Rc, Arc can be written by downstream code for local types  #159644

Description

@maxdexh

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-coherenceArea: CoherenceA-trait-systemArea: Trait systemC-discussionCategory: Discussion or questions that doesn't represent real issues.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions