File tree Expand file tree Collapse file tree 5 files changed +33
-0
lines changed
compiler/rustc_builtin_macros/src Expand file tree Collapse file tree 5 files changed +33
-0
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ pub(crate) mod clone;
2424pub ( crate ) mod coerce_pointee;
2525pub ( crate ) mod debug;
2626pub ( crate ) mod default;
27+ pub ( crate ) mod from;
2728pub ( crate ) mod hash;
2829
2930#[ path = "cmp/eq.rs" ]
Original file line number Diff line number Diff 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) ;
Original file line number Diff line number Diff line change @@ -1767,4 +1767,15 @@ pub(crate) mod builtin {
17671767 pub macro deref( $pat: pat) {
17681768 builtin # deref( $pat)
17691769 }
1770+
1771+ /// Derive macro generating an impl of the trait `From`.
1772+ /// Currently, it can only be used on single-field structs.
1773+ // Note that the macro is in a different module than the `From` trait,
1774+ // to avoid triggering an unstable feature being used if someone imports
1775+ // `std::convert::From`.
1776+ #[ rustc_builtin_macro]
1777+ #[ unstable ( feature = "derive_from" , issue = "144889" ) ]
1778+ pub macro From ( $item: item) {
1779+ /* compiler built-in */
1780+ }
17701781}
Original file line number Diff line number Diff line change @@ -117,3 +117,10 @@ pub use crate::macros::builtin::deref;
117117 reason = "`type_alias_impl_trait` has open design concerns"
118118) ]
119119pub 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 ;
You can’t perform that action at this time.
0 commit comments