-
Notifications
You must be signed in to change notification settings - Fork 13.8k
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 |
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)
fd2bbf9
to
df215cc
Compare
This PR was rebased onto a different master 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. |
@rustbot ready |
This likely needs a crater run. @bors try |
This comment has been minimized.
This comment has been minimized.
…ros, r=<try> Explicitly export core and std macros
@craterbot check |
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
🎉 Experiment
Footnotes
|
I had a quick look at the regressions. A lot of them are use std::prelude::v1::*; This causes macros like Example crate: https://github.com/Noratrieb/rustv32i/blob/main/rvdc/src/lib.rs#L1954 |
Given that Here is a minimal reproducer for the issue: #![no_std]
extern crate std;
use std::prelude::v1::*;
fn xx() {
panic!(&String::new()); // resolves to core::panic
} The old behavior can be restored by adding That said, breaking 10% of crates isn't great, even if it is only 95 root crates. |
It might be worth going ahead and making the PRs to these 95 crates. Even if we don't break them (for now at least), they're relying on a resolution which is rather surprising, so they'd be better off in any world doing this explicitly. That might later give us more options. |
Good point, I'll do that. |
Note that The main difference between them is that on older editions |
In broad strokes, this also seems related to: In this case, the two |
I don't think this should be blocked on resolving #141043. This is an issue of name resolution priority: currently, prelude macros have a higher priority than glob-imported macros. We need to preserve this property for macros imported via glob imports marked with Here's a different example:
|
While that's not 100% correct, given that Rust 2018 Thinking a bit longer about the idea of sending patches to various projects that have the unintuitive I agree with @Amanieu that we should fix this in the resolver. |
Unfortunately I think this boils back down to the original issue that this PR has been trying to avoid, which is prioritization between glob imports and prelude macros. @petrochenkov Any thoughts on how we might be able to fix this? |
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