-
Notifications
You must be signed in to change notification settings - Fork 13.5k
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: master
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 |
Reminder, once the PR becomes ready for a review, use |
I'll try to get to it next week. |
87be0d7
to
46800d5
Compare
#![feature(custom_inner_attributes)]
#![rustfmt::skip]
use std::fmt::Debug;
fn in_parameters(_: impl Debug) { todo!() }
fn main() {}
EDIT: This is likely a red herring for another issue. Ignore it for now. |
This comment has been minimized.
This comment has been minimized.
☔ The latest upstream changes (presumably #143057) made this pull request unmergeable. Please resolve the merge conflicts. |
There was another issue with the alloctests, that I managed to resolve, the where-allowed and potentially unrelated |
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_matches` but 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.
f5936bc
to
6e59600
Compare
This comment has been minimized.
This comment has been minimized.
Missing `#[doc(no_inline)]` for ambiguous_macro_only_std resulted in new and broken doc html files.
This comment has been minimized.
This comment has been minimized.
cc @Amanieu, @folkertdev, @sayantn |
The job Click to see the possible cause of the failure (guessed by this bot)
|
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_matches
but 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