Skip to content

Commit bcb8a5b

Browse files
committed
Remove the From derive macro from prelude
To avoid backwards compatibility problems.
1 parent 425a9c0 commit bcb8a5b

File tree

8 files changed

+45
-19
lines changed

8 files changed

+45
-19
lines changed

library/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.

library/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;

library/std/src/lib.rs

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

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

tests/ui/deriving/deriving-all-codegen.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#![allow(deprecated)]
1919
#![feature(derive_from)]
2020

21+
use std::from::From;
22+
2123
// Empty struct.
2224
#[derive(Clone, Copy, Debug, Default, Hash, PartialEq, Eq, PartialOrd, Ord)]
2325
struct Empty;
@@ -51,7 +53,14 @@ struct SingleField {
5153
// `clone` implemention that just does `*self`.
5254
#[derive(Clone, Copy, Debug, Default, Hash, PartialEq, Eq, PartialOrd, Ord)]
5355
struct Big {
54-
b1: u32, b2: u32, b3: u32, b4: u32, b5: u32, b6: u32, b7: u32, b8: u32,
56+
b1: u32,
57+
b2: u32,
58+
b3: u32,
59+
b4: u32,
60+
b5: u32,
61+
b6: u32,
62+
b7: u32,
63+
b8: u32,
5564
}
5665

5766
// It is more efficient to compare scalar types before non-scalar types.
@@ -126,7 +135,7 @@ enum Enum0 {}
126135
// A single-variant enum.
127136
#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
128137
enum Enum1 {
129-
Single { x: u32 }
138+
Single { x: u32 },
130139
}
131140

132141
// A C-like, fieldless enum with a single variant.
@@ -152,7 +161,10 @@ enum Mixed {
152161
P,
153162
Q,
154163
R(u32),
155-
S { d1: Option<u32>, d2: Option<i32> },
164+
S {
165+
d1: Option<u32>,
166+
d2: Option<i32>,
167+
},
156168
}
157169

158170
// When comparing enum variant it is more efficient to compare scalar types before non-scalar types.

tests/ui/deriving/deriving-all-codegen.stdout

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ extern crate std;
2323
#[prelude_import]
2424
use std::prelude::rust_2021::*;
2525

26+
use std::from::From;
27+
2628
// Empty struct.
2729
struct Empty;
2830
#[automatically_derived]

tests/ui/deriving/deriving-from-wrong-target.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#![feature(derive_from)]
55
#![allow(dead_code)]
66

7+
use std::from::From;
8+
79
#[derive(From)]
810
//~^ ERROR `#[derive(From)]` used on a struct with no fields
911
struct S1;

tests/ui/deriving/deriving-from-wrong-target.stderr

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: `#[derive(From)]` used on a struct with no fields
2-
--> $DIR/deriving-from-wrong-target.rs:7:10
2+
--> $DIR/deriving-from-wrong-target.rs:9:10
33
|
44
LL | #[derive(From)]
55
| ^^^^
@@ -10,7 +10,7 @@ LL | struct S1;
1010
= note: `#[derive(From)]` can only be used on structs with exactly one field
1111

1212
error: `#[derive(From)]` used on a struct with no fields
13-
--> $DIR/deriving-from-wrong-target.rs:11:10
13+
--> $DIR/deriving-from-wrong-target.rs:13:10
1414
|
1515
LL | #[derive(From)]
1616
| ^^^^
@@ -21,7 +21,7 @@ LL | struct S2 {}
2121
= note: `#[derive(From)]` can only be used on structs with exactly one field
2222

2323
error: `#[derive(From)]` used on a struct with multiple fields
24-
--> $DIR/deriving-from-wrong-target.rs:15:10
24+
--> $DIR/deriving-from-wrong-target.rs:17:10
2525
|
2626
LL | #[derive(From)]
2727
| ^^^^
@@ -32,7 +32,7 @@ LL | struct S3(u32, bool);
3232
= note: `#[derive(From)]` can only be used on structs with exactly one field
3333

3434
error: `#[derive(From)]` used on a struct with multiple fields
35-
--> $DIR/deriving-from-wrong-target.rs:19:10
35+
--> $DIR/deriving-from-wrong-target.rs:21:10
3636
|
3737
LL | #[derive(From)]
3838
| ^^^^
@@ -43,7 +43,7 @@ LL | struct S4 {
4343
= note: `#[derive(From)]` can only be used on structs with exactly one field
4444

4545
error: `#[derive(From)]` used on an enum
46-
--> $DIR/deriving-from-wrong-target.rs:26:10
46+
--> $DIR/deriving-from-wrong-target.rs:28:10
4747
|
4848
LL | #[derive(From)]
4949
| ^^^^
@@ -54,7 +54,7 @@ LL | enum E1 {}
5454
= note: `#[derive(From)]` can only be used on structs with exactly one field
5555

5656
error[E0277]: the size for values of type `T` cannot be known at compilation time
57-
--> $DIR/deriving-from-wrong-target.rs:30:10
57+
--> $DIR/deriving-from-wrong-target.rs:32:10
5858
|
5959
LL | #[derive(From)]
6060
| ^^^^ doesn't have a size known at compile-time
@@ -71,7 +71,7 @@ LL + struct SUnsizedField<T> {
7171
|
7272

7373
error[E0277]: the size for values of type `T` cannot be known at compilation time
74-
--> $DIR/deriving-from-wrong-target.rs:30:10
74+
--> $DIR/deriving-from-wrong-target.rs:32:10
7575
|
7676
LL | #[derive(From)]
7777
| ^^^^ doesn't have a size known at compile-time
@@ -80,7 +80,7 @@ LL | struct SUnsizedField<T: ?Sized> {
8080
| - this type parameter needs to be `Sized`
8181
|
8282
note: required because it appears within the type `SUnsizedField<T>`
83-
--> $DIR/deriving-from-wrong-target.rs:33:8
83+
--> $DIR/deriving-from-wrong-target.rs:35:8
8484
|
8585
LL | struct SUnsizedField<T: ?Sized> {
8686
| ^^^^^^^^^^^^^
@@ -92,7 +92,7 @@ LL + struct SUnsizedField<T> {
9292
|
9393

9494
error[E0277]: the size for values of type `T` cannot be known at compilation time
95-
--> $DIR/deriving-from-wrong-target.rs:34:11
95+
--> $DIR/deriving-from-wrong-target.rs:36:11
9696
|
9797
LL | struct SUnsizedField<T: ?Sized> {
9898
| - this type parameter needs to be `Sized`

tests/ui/deriving/deriving-from.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#![feature(derive_from)]
55

6+
use core::from::From;
7+
68
#[derive(From)]
79
struct TupleSimple(u32);
810

0 commit comments

Comments
 (0)