about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJakub Beránek <berykubik@gmail.com>2025-08-18 12:18:44 +0200
committerJakub Beránek <berykubik@gmail.com>2025-08-18 13:12:19 +0200
commita6a760edaf16d4b00ab4d3c607f6d85a6d193c0b (patch)
treea399d1507321b76c4737f01aec703787b32973ff
parent425a9c0a0e365c0b8c6cfd00c2ded83a73bed9a0 (diff)
downloadrust-a6a760edaf16d4b00ab4d3c607f6d85a6d193c0b.tar.gz
rust-a6a760edaf16d4b00ab4d3c607f6d85a6d193c0b.zip
Remove the `From` derive macro from prelude
To avoid backwards compatibility problems.
-rw-r--r--library/core/src/lib.rs7
-rw-r--r--library/core/src/prelude/v1.rs7
-rw-r--r--library/std/src/lib.rs8
-rw-r--r--tests/ui/deriving/deriving-all-codegen.rs18
-rw-r--r--tests/ui/deriving/deriving-all-codegen.stdout2
-rw-r--r--tests/ui/deriving/deriving-from-wrong-target.rs3
-rw-r--r--tests/ui/deriving/deriving-from-wrong-target.stderr18
-rw-r--r--tests/ui/deriving/deriving-from.rs2
-rw-r--r--tests/ui/feature-gates/feature-gate-derive-from.rs2
-rw-r--r--tests/ui/feature-gates/feature-gate-derive-from.stderr12
10 files changed, 57 insertions, 22 deletions
diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs
index 6396b8524f2..71abd707374 100644
--- a/library/core/src/lib.rs
+++ b/library/core/src/lib.rs
@@ -226,6 +226,13 @@ pub mod assert_matches {
     pub use crate::macros::{assert_matches, debug_assert_matches};
 }
 
+#[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 crate::macros::builtin::From;
+}
+
 // We don't export this through #[macro_export] for now, to avoid breakage.
 #[unstable(feature = "autodiff", issue = "124509")]
 /// Unstable module containing the unstable `autodiff` macro.
diff --git a/library/core/src/prelude/v1.rs b/library/core/src/prelude/v1.rs
index d8d82afb0e6..a4be66b90ca 100644
--- a/library/core/src/prelude/v1.rs
+++ b/library/core/src/prelude/v1.rs
@@ -117,10 +117,3 @@ pub use crate::macros::builtin::deref;
     reason = "`type_alias_impl_trait` has open design concerns"
 )]
 pub use crate::macros::builtin::define_opaque;
-
-#[unstable(
-    feature = "derive_from",
-    issue = "144889",
-    reason = "`derive(From)` is unstable"
-)]
-pub use crate::macros::builtin::From;
diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs
index f111fcb4a47..95d4b38331a 100644
--- a/library/std/src/lib.rs
+++ b/library/std/src/lib.rs
@@ -737,6 +737,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.
diff --git a/tests/ui/deriving/deriving-all-codegen.rs b/tests/ui/deriving/deriving-all-codegen.rs
index 00a269ccb5c..db58f12d60c 100644
--- a/tests/ui/deriving/deriving-all-codegen.rs
+++ b/tests/ui/deriving/deriving-all-codegen.rs
@@ -18,6 +18,8 @@
 #![allow(deprecated)]
 #![feature(derive_from)]
 
+use std::from::From;
+
 // Empty struct.
 #[derive(Clone, Copy, Debug, Default, Hash, PartialEq, Eq, PartialOrd, Ord)]
 struct Empty;
@@ -51,7 +53,14 @@ struct SingleField {
 // `clone` implemention that just does `*self`.
 #[derive(Clone, Copy, Debug, Default, Hash, PartialEq, Eq, PartialOrd, Ord)]
 struct Big {
-    b1: u32, b2: u32, b3: u32, b4: u32, b5: u32, b6: u32, b7: u32, b8: u32,
+    b1: u32,
+    b2: u32,
+    b3: u32,
+    b4: u32,
+    b5: u32,
+    b6: u32,
+    b7: u32,
+    b8: u32,
 }
 
 // It is more efficient to compare scalar types before non-scalar types.
@@ -126,7 +135,7 @@ enum Enum0 {}
 // A single-variant enum.
 #[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
 enum Enum1 {
-    Single { x: u32 }
+    Single { x: u32 },
 }
 
 // A C-like, fieldless enum with a single variant.
@@ -152,7 +161,10 @@ enum Mixed {
     P,
     Q,
     R(u32),
-    S { d1: Option<u32>, d2: Option<i32> },
+    S {
+        d1: Option<u32>,
+        d2: Option<i32>,
+    },
 }
 
 // When comparing enum variant it is more efficient to compare scalar types before non-scalar types.
diff --git a/tests/ui/deriving/deriving-all-codegen.stdout b/tests/ui/deriving/deriving-all-codegen.stdout
index 78b93f39b9e..4c60b1cf427 100644
--- a/tests/ui/deriving/deriving-all-codegen.stdout
+++ b/tests/ui/deriving/deriving-all-codegen.stdout
@@ -23,6 +23,8 @@ extern crate std;
 #[prelude_import]
 use std::prelude::rust_2021::*;
 
+use std::from::From;
+
 // Empty struct.
 struct Empty;
 #[automatically_derived]
diff --git a/tests/ui/deriving/deriving-from-wrong-target.rs b/tests/ui/deriving/deriving-from-wrong-target.rs
index 57e009cae69..37c9300e28b 100644
--- a/tests/ui/deriving/deriving-from-wrong-target.rs
+++ b/tests/ui/deriving/deriving-from-wrong-target.rs
@@ -1,9 +1,10 @@
-//@ edition: 2021
 //@ check-fail
 
 #![feature(derive_from)]
 #![allow(dead_code)]
 
+use std::from::From;
+
 #[derive(From)]
 //~^ ERROR `#[derive(From)]` used on a struct with no fields
 struct S1;
diff --git a/tests/ui/deriving/deriving-from-wrong-target.stderr b/tests/ui/deriving/deriving-from-wrong-target.stderr
index 13593c95973..63eb8ec7b6e 100644
--- a/tests/ui/deriving/deriving-from-wrong-target.stderr
+++ b/tests/ui/deriving/deriving-from-wrong-target.stderr
@@ -1,5 +1,5 @@
 error: `#[derive(From)]` used on a struct with no fields
-  --> $DIR/deriving-from-wrong-target.rs:7:10
+  --> $DIR/deriving-from-wrong-target.rs:8:10
    |
 LL | #[derive(From)]
    |          ^^^^
@@ -10,7 +10,7 @@ LL | struct S1;
    = note: `#[derive(From)]` can only be used on structs with exactly one field
 
 error: `#[derive(From)]` used on a struct with no fields
-  --> $DIR/deriving-from-wrong-target.rs:11:10
+  --> $DIR/deriving-from-wrong-target.rs:12:10
    |
 LL | #[derive(From)]
    |          ^^^^
@@ -21,7 +21,7 @@ LL | struct S2 {}
    = note: `#[derive(From)]` can only be used on structs with exactly one field
 
 error: `#[derive(From)]` used on a struct with multiple fields
-  --> $DIR/deriving-from-wrong-target.rs:15:10
+  --> $DIR/deriving-from-wrong-target.rs:16:10
    |
 LL | #[derive(From)]
    |          ^^^^
@@ -32,7 +32,7 @@ LL | struct S3(u32, bool);
    = note: `#[derive(From)]` can only be used on structs with exactly one field
 
 error: `#[derive(From)]` used on a struct with multiple fields
-  --> $DIR/deriving-from-wrong-target.rs:19:10
+  --> $DIR/deriving-from-wrong-target.rs:20:10
    |
 LL | #[derive(From)]
    |          ^^^^
@@ -43,7 +43,7 @@ LL | struct S4 {
    = note: `#[derive(From)]` can only be used on structs with exactly one field
 
 error: `#[derive(From)]` used on an enum
-  --> $DIR/deriving-from-wrong-target.rs:26:10
+  --> $DIR/deriving-from-wrong-target.rs:27:10
    |
 LL | #[derive(From)]
    |          ^^^^
@@ -54,7 +54,7 @@ LL | enum E1 {}
    = note: `#[derive(From)]` can only be used on structs with exactly one field
 
 error[E0277]: the size for values of type `T` cannot be known at compilation time
-  --> $DIR/deriving-from-wrong-target.rs:30:10
+  --> $DIR/deriving-from-wrong-target.rs:31:10
    |
 LL | #[derive(From)]
    |          ^^^^ doesn't have a size known at compile-time
@@ -71,7 +71,7 @@ LL + struct SUnsizedField<T> {
    |
 
 error[E0277]: the size for values of type `T` cannot be known at compilation time
-  --> $DIR/deriving-from-wrong-target.rs:30:10
+  --> $DIR/deriving-from-wrong-target.rs:31:10
    |
 LL | #[derive(From)]
    |          ^^^^ doesn't have a size known at compile-time
@@ -80,7 +80,7 @@ LL | struct SUnsizedField<T: ?Sized> {
    |                      - this type parameter needs to be `Sized`
    |
 note: required because it appears within the type `SUnsizedField<T>`
-  --> $DIR/deriving-from-wrong-target.rs:33:8
+  --> $DIR/deriving-from-wrong-target.rs:34:8
    |
 LL | struct SUnsizedField<T: ?Sized> {
    |        ^^^^^^^^^^^^^
@@ -92,7 +92,7 @@ LL + struct SUnsizedField<T> {
    |
 
 error[E0277]: the size for values of type `T` cannot be known at compilation time
-  --> $DIR/deriving-from-wrong-target.rs:34:11
+  --> $DIR/deriving-from-wrong-target.rs:35:11
    |
 LL | struct SUnsizedField<T: ?Sized> {
    |                      - this type parameter needs to be `Sized`
diff --git a/tests/ui/deriving/deriving-from.rs b/tests/ui/deriving/deriving-from.rs
index ff4c5b4c426..75988ba974d 100644
--- a/tests/ui/deriving/deriving-from.rs
+++ b/tests/ui/deriving/deriving-from.rs
@@ -3,6 +3,8 @@
 
 #![feature(derive_from)]
 
+use core::from::From;
+
 #[derive(From)]
 struct TupleSimple(u32);
 
diff --git a/tests/ui/feature-gates/feature-gate-derive-from.rs b/tests/ui/feature-gates/feature-gate-derive-from.rs
index 12440356ddf..0e8c5e4af37 100644
--- a/tests/ui/feature-gates/feature-gate-derive-from.rs
+++ b/tests/ui/feature-gates/feature-gate-derive-from.rs
@@ -1,4 +1,4 @@
-//@ edition: 2021
+use std::from::From; //~ ERROR use of unstable library feature `derive_from
 
 #[derive(From)] //~ ERROR use of unstable library feature `derive_from`
 struct Foo(u32);
diff --git a/tests/ui/feature-gates/feature-gate-derive-from.stderr b/tests/ui/feature-gates/feature-gate-derive-from.stderr
index d58dcdd7541..63216a4cccd 100644
--- a/tests/ui/feature-gates/feature-gate-derive-from.stderr
+++ b/tests/ui/feature-gates/feature-gate-derive-from.stderr
@@ -8,6 +8,16 @@ LL | #[derive(From)]
    = help: add `#![feature(derive_from)]` to the crate attributes to enable
    = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
 
-error: aborting due to 1 previous error
+error[E0658]: use of unstable library feature `derive_from`
+  --> $DIR/feature-gate-derive-from.rs:1:5
+   |
+LL | use std::from::From;
+   |     ^^^^^^^^^^^^^^^
+   |
+   = note: see issue #144889 <https://github.com/rust-lang/rust/issues/144889> for more information
+   = help: add `#![feature(derive_from)]` to the crate attributes to enable
+   = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
+
+error: aborting due to 2 previous errors
 
 For more information about this error, try `rustc --explain E0658`.