rust-lang / rust-lang/rust

`impl ... for Box<CoreType>` in alloc should not require `#[cfg(not(test))]`

Open
#135,100 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-docs C-bug E-needs-investigation T-bootstrap T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

library/alloc/src/ffi/c_str.rs has:

#[cfg(not(test))]
#[stable(feature = "box_from_c_str", since = "1.17.0")]
impl From<&CStr> for Box<CStr> {

As far as I can tell, #[cfg(not(test))] is a workaround for something like https://github.com/rust-lang/rust/issues/87534, as evidenced by error messages like:
note: the crate `alloc` is compiled multiple times, possibly with different configurations

alloc is being compiled a second time as part of tests, and the two compilations are conflicting.

  1. This workaround shouldn't be necessary.

  2. This should be much better documented, so it doesn't send people on multi-hour debugging adventures when they try to write new trait impls in alloc.

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

Read library/alloc/src/ffi/c_str.rs and the surrounding #[cfg(not(test))] impl; then trace how alloc is compiled during tests and compare the issue-87534 behavior. Done means the impl no longer needs the workaround and the multi-configuration failure is either resolved or documented clearly for new alloc trait implementations.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers, testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.