diff options
| author | Stuart Cook <Zalathar@users.noreply.github.com> | 2025-08-19 14:18:27 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-19 14:18:27 +1000 |
| commit | f44f963b03ce177a2037386244b344234048074e (patch) | |
| tree | 321b39cbbced5cc4299fb2d6f4323332af2f7c37 /library/std/src/lib.rs | |
| parent | cf2f50e332fc57ada7c667080df3df414ef6bd5f (diff) | |
| parent | a6a760edaf16d4b00ab4d3c607f6d85a6d193c0b (diff) | |
| download | rust-f44f963b03ce177a2037386244b344234048074e.tar.gz rust-f44f963b03ce177a2037386244b344234048074e.zip | |
Rollup merge of #145563 - Kobzol:remove-from-from-prelude, r=petrochenkov
Remove the `From` derive macro from prelude
The new `#[derive(From)]` functionality (implemented in https://github.com/rust-lang/rust/pull/144922) caused name resolution ambiguity issues (https://github.com/rust-lang/rust/issues/145524). The reproducer looks e.g. like this:
```rust
mod foo {
pub use derive_more::From;
}
use foo::*;
#[derive(From)] // ERROR: `From` is ambiguous
struct S(u32);
```
It's pretty unfortunate that it works like this, but I guess that there's not much to be done here, and we'll have to wait for the next edition to put the `From` macro into the prelude. That will probably require https://github.com/rust-lang/rust/pull/139493 to land.
I created a new module in core (and re-exported it in std) called `from`, where I re-exported the `From` macro. I *think* that since this is a new module, it should not have the same backwards incompatibility issue.
Happy to hear suggestions about the naming - maybe it would make sense as `core::macros::from::From`? But we already had a precedent in the `core::assert_matches` module, so I just followed suit.
Fixes: https://github.com/rust-lang/rust/issues/145524
r? ``@petrochenkov``
Diffstat (limited to 'library/std/src/lib.rs')
| -rw-r--r-- | library/std/src/lib.rs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index c27167767a2..ab417b6c72f 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -738,6 +738,14 @@ pub use core::{ unreachable, write, writeln, }; +// Re-export unstable derive macro defined through core. +#[unstable(feature = "derive_from", issue = "144889")] +/// Unstable module containing the unstable `From` derive macro. +pub mod from { + #[unstable(feature = "derive_from", issue = "144889")] + pub use core::from::From; +} + // Include a number of private modules that exist solely to provide // the rustdoc documentation for primitive types. Using `include!` // because rustdoc only looks for these modules at the crate level. |
