Skip to content

#![no_implicit_prelude] does not disable macros #138756

Open
@kpreid

Description

@kpreid

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 1aeb99d).
I do not know whether this ever worked.

Prompted by a discussion in the Rust Community Discord server.

@rustbot label +A-macros

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)A-maybe-future-editionSomething we may consider for a future edition.C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-editionRelevant to the edition team.T-langRelevant to the language 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