Skip to content

Macros exported by compiler_builtins should not be in the prelude #113533

Description

@Amanieu

compiler_builtins exports some macros for use by its tests, but rustc seems to make these available to any code as if they were part of the prelude. While compiler_builtins should be fixed to not export these, it is also strange that the prelude includes these macros.

// Compile with: rustc foo.rs --target aarch64-unknown-linux-gnu --crate-type lib
#![no_std]

foreach_cas16!();
error: unexpected end of macro invocation
 --> src/lib.rs:3:1
  |
3 | foreach_cas16!();
  | ^^^^^^^^^^^^^^^^ missing tokens in macro arguments
  |
note: while trying to match meta-variable `$r#macro:path`
 --> /home/amanieu/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/obj/build/x86_64-unknown-linux-gnu/stage1-std/aarch64-unknown-linux-gnu/release/build/compiler_builtins-0862f16702efa101/out/outlined_atomics.rs:103:51

error: aborting due to previous error

Activity

  1. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Jul 10, 2023
  2. added
    T-libsRelevant to the library team, which will review and decide on the PR/issue.
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Jul 10, 2023
  3. lukas-code commented on Jul 10, 2023

    @lukas-code
    Contributor

    The prelude for no_std crates currently looks like this:

    #![feature(prelude_import)]
    #![no_std]
    #[prelude_import]
    use core::prelude::rust_2021::*;
    #[macro_use]
    extern crate core;
    #[macro_use]
    extern crate compiler_builtins;

    The #[macro_use] on compiler_builtins comes from here:

    thin_vec![cx.attr_word(sym::macro_use, span)],

  4. Amanieu commented on Jul 10, 2023

    @Amanieu
    MemberAuthor

    In #113557 I changed this to:

    // No #[macro_use]
    extern crate compiler_builtins as  _;

    The API of compiler-builtins is not stable and should not be exposed in the prelude. It's only needed there because compiler_builtins is required at link-time.

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

    T-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions