Skip to content

Commit 870e8a0

Browse files
authored
Rollup merge of rust-lang#145563 - Kobzol:remove-from-from-prelude, r=petrochenkov
Remove the `From` derive macro from prelude The new `#[derive(From)]` functionality (implemented in rust-lang#144922) caused name resolution ambiguity issues (rust-lang#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 rust-lang#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: rust-lang#145524 r? ``@petrochenkov``
2 parents 1ee60af + fd2ef7d commit 870e8a0

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

core/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,13 @@ pub mod assert_matches {
226226
pub use crate::macros::{assert_matches, debug_assert_matches};
227227
}
228228

229+
#[unstable(feature = "derive_from", issue = "144889")]
230+
/// Unstable module containing the unstable `From` derive macro.
231+
pub mod from {
232+
#[unstable(feature = "derive_from", issue = "144889")]
233+
pub use crate::macros::builtin::From;
234+
}
235+
229236
// We don't export this through #[macro_export] for now, to avoid breakage.
230237
#[unstable(feature = "autodiff", issue = "124509")]
231238
/// Unstable module containing the unstable `autodiff` macro.

core/src/prelude/v1.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,3 @@ pub use crate::macros::builtin::deref;
117117
reason = "`type_alias_impl_trait` has open design concerns"
118118
)]
119119
pub use crate::macros::builtin::define_opaque;
120-
121-
#[unstable(
122-
feature = "derive_from",
123-
issue = "144889",
124-
reason = "`derive(From)` is unstable"
125-
)]
126-
pub use crate::macros::builtin::From;

std/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,14 @@ pub use core::{
738738
unreachable, write, writeln,
739739
};
740740

741+
// Re-export unstable derive macro defined through core.
742+
#[unstable(feature = "derive_from", issue = "144889")]
743+
/// Unstable module containing the unstable `From` derive macro.
744+
pub mod from {
745+
#[unstable(feature = "derive_from", issue = "144889")]
746+
pub use core::from::From;
747+
}
748+
741749
// Include a number of private modules that exist solely to provide
742750
// the rustdoc documentation for primitive types. Using `include!`
743751
// because rustdoc only looks for these modules at the crate level.

0 commit comments

Comments
 (0)