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 themacro_use
prelude, and all macros exported from the standard library are still included in themacro_use
prelude. Starting in the 2018 edition, it will remove themacro_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