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 @@ -23,6 +23,7 @@ pub(crate) mod clone;
2323pub ( crate ) mod coerce_pointee;
2424pub ( crate ) mod debug;
2525pub ( crate ) mod default;
26+ pub ( crate ) mod from;
2627pub ( crate ) mod hash;
2728
2829#[ 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 @@ -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}
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