diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 6396b8524f2ed..71abd707374cf 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 d8d82afb0e625..a4be66b90cab3 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 f111fcb4a4712..95d4b38331a04 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 00a269ccb5cfa..db58f12d60c2d 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, d2: Option }, + S { + d1: Option, + d2: Option, + }, } // 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 78b93f39b9ea1..4c60b1cf4275f 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 57e009cae69eb..37c9300e28b3c 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 13593c95973e4..63eb8ec7b6eeb 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 { | 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 { | - this type parameter needs to be `Sized` | note: required because it appears within the type `SUnsizedField` - --> $DIR/deriving-from-wrong-target.rs:33:8 + --> $DIR/deriving-from-wrong-target.rs:34:8 | LL | struct SUnsizedField { | ^^^^^^^^^^^^^ @@ -92,7 +92,7 @@ LL + struct SUnsizedField { | 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 { | - this type parameter needs to be `Sized` diff --git a/tests/ui/deriving/deriving-from.rs b/tests/ui/deriving/deriving-from.rs index ff4c5b4c426a6..75988ba974d59 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 12440356ddf25..0e8c5e4af379a 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 d58dcdd754111..63216a4cccd84 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 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`.