-
Notifications
You must be signed in to change notification settings - Fork 14k
Explicitly export core and std macros #139493
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Explicitly export core and std macros #139493
Conversation
|
r? @ChrisDenton rustbot has assigned @ChrisDenton. Use |
|
r? @Amanieu |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@Amanieu the tidy issue highlights an annoying and unforeseen side-effect of this change. The fn xx(i: vec::IntoIter<i32>) {
let _ = i.as_slice();
}
fn main() {}that currently doesn't compile on stable would now compile. Initially I thought this would cause name collisions if users define their own |
|
There's an issue for this change - #53977. |
|
@Voultapher, avoiding the vec module re-export can be done like this: #[macro_export]
macro_rules! myvec {
() => {};
}
pub mod myvec {
pub struct Vec;
}
pub mod prelude {
// Bad: re-exports both macro and type namespace
// pub use crate::myvec;
mod vec_macro_only {
#[allow(hidden_glob_reexports)]
mod myvec {}
pub use crate::*;
}
pub use self::vec_macro_only::myvec;
}
fn main() {
prelude::myvec!();
let _: prelude::myvec::Vec; // error
} |
|
|
This comment has been minimized.
This comment has been minimized.
|
@Voultapher Based on the CI failure I think that a try build would fail now. |
|
Ok, I'll try to get the CI passing first. |
|
@petrochenkov I went through all macros and searched the docs and |
This comment has been minimized.
This comment has been minimized.
|
@Amanieu this program previously worked: use std::*;
fn main() {
panic!("panic works")
}and now runs into: I don't see how we can resolve that without changing language import rules and or special casing the prelude import. |
|
@petrochenkov Do you have any ideas about that? |
|
Could you add a test making sure that the modules |
The ambiguity wouldn't happen if it was the same panic in std root and in the stdlib prelude. Previously |
Missing `#[doc(no_inline)]` for ambiguous_macro_only_std resulted in new and broken doc html files.
An incorrect merge conflict resolution had deleted a relevant new line.
While this is undesired, blocking explicit macro export and assert_matches for this bug that already exists in a smaller fashion was deemed not worth it. See rust-lang#145577 and rust-lang#139493 (comment)
This turns the ambiguous panic import error into a warning to avoid breaking large parts of the Rust crate ecosystem.
I'm not sure that's the case any more than previously discussed in that it turns an error into a warning. The content implications are the exact same as discussed with the lint, since it is the lint. So not sure how to mention that without it becoming confusing. |
3ff59e0 to
ed65c75
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
|
I've updated the PR description and changed to |
Currently all core and std macros are automatically added to the prelude via #[macro_use]. However a situation arose where we want to add a new macro
assert_matchesbut don't want to pull it into the standard prelude for compatibility reasons. By explicitly exporting the macros found in the core and std crates we get to decide on a per macro basis and can later add them via the rust_20xx preludes.Closes #53977
Unlocks #137487
Reference PR:
Stabilization report lib
Everything N/A or already covered by lang report except, breaking changes: The unstable and never intended for public use
format_args_nlmacro is no longer publicly accessible as requested by @petrochenkov. Affects <10 crates including dependencies.Stabilization report lang
Summary
Explicitly export core and std macros.
This change if merged would change the code injected into user crates to no longer include #[macro_use] on extern crate core and extern crate std. This change is motivated by a near term goal and a longer term goal. The near term goal is to allow a macro to be defined at the std or core crate root but not have it be part of the implicit prelude. Such macros can then be separately promoted to the prelude in a new edition. Specifically this is blocking the stabilization of assert_matches #137487. The longer term goal is to gradually deprecate #[macro_use]. By no longer requiring it for standard library usage, this serves as a step towards that goal. For more information see #53977.
PR link: #139493
Tracking:
ambiguous_panic_imports#147319Reference PRs:
cc @rust-lang/lang @rust-lang/lang-advisors
What is stabilized
Stabilization:
Design
N/A
Reference
RFC history
N/A
Answers to unresolved questions
N/A
Post-RFC changes
N/A
Key points
Nightly extensions
N/A
Doors closed
No known doors are closed.
Feedback
Call for testing
No.
Nightly use
N/A
Implementation
Major parts
The key change is compiler/rustc_builtin_macros/src/standard_library_imports.rs removing the macro_use inject and the
v1.rspreludes now explicitlypub useing the macros https://github.com/rust-lang/rust/pull/139493/files#diff-a6f9f476d41575b19b399c6d236197355556958218fd035549db6d584dbdea1d + https://github.com/rust-lang/rust/pull/139493/files#diff-49849ff961ebc978f98448c8990cf7aae8e94cb03db44f016011aa8400170587.Coverage
A variety of UI tests including edge cases have been added.
Outstanding bugs
An old bug is made more noticeable by this change #145577 but it was recommended to not block on it #139493 (comment).
Outstanding FIXMEs
https://github.com/rust-lang/rust/pull/139493/files#diff-c046507afdba3b0705638f53fffa156cbad72ed17aa01d96d7bd1cc10b8d9bce
Tool changes
rustfmtrust-analyzerrustdoc (both JSON and HTML)cargoclippyrustupdocs.rsNo known changes needed or expected.
Breaking changes
Breaking changes:
Crater report:
Crater analysis:
PRs to affected crates:
Type system, opsem
Compile-time checks
N/A
Type system rules
N/A
Sound by default?
N/A
Breaks the AM?
N/A
Common interactions
Temporaries
N/A
Drop order
N/A
Pre-expansion / post-expansion
N/A
Edition hygiene
N/A
SemVer implications
No.
Exposing other features
No.
History
assert_matchesand move it tocore::macros#137487 (comment)Acknowledgments
More or less solo developed by @Voultapher with some help from @petrochenkov.
Open items
None.