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;
23
23
pub ( crate ) mod coerce_pointee;
24
24
pub ( crate ) mod debug;
25
25
pub ( crate ) mod default;
26
+ pub ( crate ) mod from;
26
27
pub ( crate ) mod hash;
27
28
28
29
#[ 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) {
139
139
PartialEq : partial_eq:: expand_deriving_partial_eq,
140
140
PartialOrd : partial_ord:: expand_deriving_partial_ord,
141
141
CoercePointee : coerce_pointee:: expand_deriving_coerce_pointee,
142
+ From : from:: expand_deriving_from,
142
143
}
143
144
144
145
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 {
1767
1767
pub macro deref( $pat: pat) {
1768
1768
builtin # deref( $pat)
1769
1769
}
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
+ }
1770
1781
}
Original file line number Diff line number Diff line change @@ -117,3 +117,10 @@ pub use crate::macros::builtin::deref;
117
117
reason = "`type_alias_impl_trait` has open design concerns"
118
118
) ]
119
119
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 ;
You can’t perform that action at this time.
0 commit comments