Stabilize assert_matches and move it to core::macros by Voultapher · Pull Request #137487 · rust-lang/rust (original) (raw)

I don't think a macros module is the right way to go around this. What we really want is for assert_matches to live in the same place as all the other macros in the standard library, which is currently the crate root (macros are imported with use std::assert;).

Fundamentally the breakage comes from the fact that assert_matches is in the prelude and the way macro name resolution works means that we can't prioritize prelude macros lower than glob-imported macros (#82775 (comment)). However we can avoid this problem by exporting assert_matches from the crate root just like other macros but not including it in the prelude. It can be included in the prelude in a future edition.

Now, the standard library prelude is imported by injecting this code into each crate:

#[prelude_import] use ::std::prelude::rust_2024::*; #[macro_use] extern crate std;

Instead of importing all macros from std with #[macro_use], we can explicitly re-export all macros in the rust_20xx prelude and remove #[macro_use] from the implicit prelude. This allows new macros to be added to the standard library without being a breaking change, while adding them to the prelude can be deferred to a future edition.