Skip to content

Commit e935a15

Browse files
committed
Create unstable From builtin macro and register it
1 parent f39085b commit e935a15

File tree

5 files changed

+33
-0
lines changed

5 files changed

+33
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use rustc_ast as ast;
2+
use rustc_expand::base::{Annotatable, ExtCtxt};
3+
use rustc_span::{Span, sym};
4+
5+
pub(crate) fn expand_deriving_from(
6+
cx: &ExtCtxt<'_>,
7+
span: Span,
8+
mitem: &ast::MetaItem,
9+
item: &Annotatable,
10+
push: &mut dyn FnMut(Annotatable),
11+
is_const: bool,
12+
) {
13+
}

compiler/rustc_builtin_macros/src/deriving/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub(crate) mod clone;
2323
pub(crate) mod coerce_pointee;
2424
pub(crate) mod debug;
2525
pub(crate) mod default;
26+
pub(crate) mod from;
2627
pub(crate) mod hash;
2728

2829
#[path = "cmp/eq.rs"]

compiler/rustc_builtin_macros/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) {
139139
PartialEq: partial_eq::expand_deriving_partial_eq,
140140
PartialOrd: partial_ord::expand_deriving_partial_ord,
141141
CoercePointee: coerce_pointee::expand_deriving_coerce_pointee,
142+
From: from::expand_deriving_from,
142143
}
143144

144145
let client = rustc_proc_macro::bridge::client::Client::expand1(rustc_proc_macro::quote);

library/core/src/macros/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,4 +1768,15 @@ pub(crate) mod builtin {
17681768
pub macro deref($pat:pat) {
17691769
builtin # deref($pat)
17701770
}
1771+
1772+
/// Derive macro generating an impl of the trait `From`.
1773+
/// Currently, it can only be used on single-field structs.
1774+
// Note that the macro is in a different module than the `From` trait,
1775+
// to avoid triggering an unstable feature being used if someone imports
1776+
// `std::convert::From`.
1777+
#[rustc_builtin_macro]
1778+
#[unstable(feature = "derive_from", issue = "144889")]
1779+
pub macro From($item: item) {
1780+
/* compiler built-in */
1781+
}
17711782
}

library/core/src/prelude/v1.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,10 @@ 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;

0 commit comments

Comments
 (0)