-
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 |
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? |
Not really. Are there regressions not related to |
Most of the failures are due to
If we can find a solution for the |
However just not re-exporting |
It could use |
Before bringing in |
Adding a warning about the unintuitive resolution might be good idea. It would move actively developed crates towards an explicit import, allowing for an eventual removal of the |
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…ros, r=<try> Explicitly export core and std macros
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (f65cc8e): comparison URL. Overall result: ❌✅ regressions and improvements - BENCHMARK(S) FAILEDBenchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @bors rollup=never ❗ ❗ ❗ ❗ ❗
❗ ❗ ❗ ❗ ❗ Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary 1.0%, secondary 0.6%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary -2.4%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary 0.0%, secondary 0.0%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 471.619s -> 472.552s (0.20%) |
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