Skip to content

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

Open
@joshtriplett

Description

@joshtriplett
Member

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 #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.

Activity

added
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Jan 4, 2025
added
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Jan 4, 2025
added
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and tools
C-bugCategory: This is a bug.
E-needs-investigationCall for partcipation: This issues needs some investigation to determine current status
T-bootstrapRelevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
and removed
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Jan 4, 2025
bjorn3

bjorn3 commented on Jan 4, 2025

@bjorn3
Member

This workaround shouldn't be necessary.

This is also necessary for all lang item definitions outside of libcore. For libcore it isn't necessary because all "unit" tests have been moved into a separate crate in library/core/tests (core_tests). For liballoc and libstd some are in library/alloc/tests and library/std/tests, but others are in liballoc and libstd directly because they are testing non-public functions and accessing non-public fields.

By the way the current construction also has other issues. We are depending on cargo compiling the libcore that is a direct dependency with the exact same flags and rustc version as the one libtest from the sysroot depends on to avoid getting an error about duplicate lang items. With rustbuild in practice this works fine, but I haven't been able to exactly match the flags in cg_clif's test suite. As such I had to patch core_tests to be an entirely separate cargo package which doesn't depend on libcore and I can't run liballoc's and libstd's test suite at all.

86 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-bugCategory: This is a bug.E-needs-investigationCall for partcipation: This issues needs some investigation to determine current statusT-bootstrapRelevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @joshtriplett@bjorn3@jieyouxu@rustbot

        Issue actions

          `impl ... for Box<CoreType>` in alloc should not require `#[cfg(not(test))]` · Issue #135100 · rust-lang/rust