rust-lang / rust-lang/rust

`#![no_implicit_prelude]` does not disable macros

Open
#138,756 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-macros A-maybe-future-edition C-bug T-compiler T-edition T-lang
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I tried this code:

// edition 2018, 2021, or 2024
#![no_implicit_prelude]

fn main() {
    assert!(true);
}

I expected to see this happen: Compilation error, according to the language reference:

The no_implicit_prelude attribute may be applied at the crate level or on a module to indicate that it should not automatically bring the standard library prelude, extern prelude, or tool prelude into scope for that module or any of its descendants.

This attribute does not affect the language prelude.

Edition differences: In the 2015 edition, the no_implicit_prelude attribute does not affect the macro_use prelude, and all macros exported from the standard library are still included in the macro_use prelude. Starting in the 2018 edition, it will remove the macro_use prelude.

In particular, both the macro_use prelude and the standard library prelude should not be in scope, and assert! is not a member of the language prelude, so assert! should not be in scope.

Instead, this happened: The code compiles. The macro is still in scope.

Meta

Tested with stable 1.85.1 and nightly 1.87.0-nightly (2025-03-19 1aeb99d248e1b0069110).
I do not know whether this ever worked.

Prompted by a discussion in the Rust Community Discord server.

@rustbot label +A-macros

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

Start by compiling the minimal Rust example in the issue and compare its behavior with the quoted no_implicit_prelude language-reference rules across the 2018, 2021, and 2024 editions. Done means the assert! macro is not in scope under the documented editions, with regression coverage for the behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.