2
2
3
3
use rustc_data_structures:: sync:: Lrc ;
4
4
use syntax:: ast:: { self , MetaItem } ;
5
+ use syntax:: attr:: Deprecation ;
5
6
use syntax:: edition:: Edition ;
6
7
use syntax:: ext:: base:: { Annotatable , ExtCtxt , Resolver , MultiItemModifier } ;
7
8
use syntax:: ext:: base:: { SyntaxExtension , SyntaxExtensionKind } ;
@@ -60,7 +61,7 @@ impl MultiItemModifier for BuiltinDerive {
60
61
}
61
62
62
63
macro_rules! derive_traits {
63
- ( $( $name: expr => $func: path, ) +) => {
64
+ ( $( [ $deprecation : expr ] $name: expr => $func: path, ) +) => {
64
65
pub fn is_builtin_trait( name: ast:: Name ) -> bool {
65
66
match & * name. as_str( ) {
66
67
$( $name ) |+ => true ,
@@ -81,6 +82,10 @@ macro_rules! derive_traits {
81
82
resolver. add_builtin(
82
83
ast:: Ident :: with_empty_ctxt( Symbol :: intern( $name) ) ,
83
84
Lrc :: new( SyntaxExtension {
85
+ deprecation: $deprecation. map( |msg| Deprecation {
86
+ since: Some ( Symbol :: intern( "1.0.0" ) ) ,
87
+ note: Some ( Symbol :: intern( msg) ) ,
88
+ } ) ,
84
89
allow_internal_unstable: allow_internal_unstable. clone( ) ,
85
90
..SyntaxExtension :: default (
86
91
SyntaxExtensionKind :: LegacyDerive ( Box :: new( BuiltinDerive ( $func) ) ) ,
@@ -94,44 +99,43 @@ macro_rules! derive_traits {
94
99
}
95
100
96
101
derive_traits ! {
102
+ [ None ]
97
103
"Clone" => clone:: expand_deriving_clone,
98
104
105
+ [ None ]
99
106
"Hash" => hash:: expand_deriving_hash,
100
107
108
+ [ None ]
101
109
"RustcEncodable" => encodable:: expand_deriving_rustc_encodable,
102
110
111
+ [ None ]
103
112
"RustcDecodable" => decodable:: expand_deriving_rustc_decodable,
104
113
114
+ [ None ]
105
115
"PartialEq" => partial_eq:: expand_deriving_partial_eq,
116
+ [ None ]
106
117
"Eq" => eq:: expand_deriving_eq,
118
+ [ None ]
107
119
"PartialOrd" => partial_ord:: expand_deriving_partial_ord,
120
+ [ None ]
108
121
"Ord" => ord:: expand_deriving_ord,
109
122
123
+ [ None ]
110
124
"Debug" => debug:: expand_deriving_debug,
111
125
126
+ [ None ]
112
127
"Default" => default :: expand_deriving_default,
113
128
129
+ [ None ]
114
130
"Copy" => bounds:: expand_deriving_copy,
115
131
116
132
// deprecated
133
+ [ Some ( "derive(Encodable) is deprecated in favor of derive(RustcEncodable)" ) ]
117
134
"Encodable" => encodable:: expand_deriving_encodable,
135
+ [ Some ( "derive(Decodable) is deprecated in favor of derive(RustcDecodable)" ) ]
118
136
"Decodable" => decodable:: expand_deriving_decodable,
119
137
}
120
138
121
- #[ inline] // because `name` is a compile-time constant
122
- fn warn_if_deprecated ( ecx : & mut ExtCtxt < ' _ > , sp : Span , name : & str ) {
123
- if let Some ( replacement) = match name {
124
- "Encodable" => Some ( "RustcEncodable" ) ,
125
- "Decodable" => Some ( "RustcDecodable" ) ,
126
- _ => None ,
127
- } {
128
- ecx. span_warn ( sp,
129
- & format ! ( "derive({}) is deprecated in favor of derive({})" ,
130
- name,
131
- replacement) ) ;
132
- }
133
- }
134
-
135
139
/// Construct a name for the inner type parameter that can't collide with any type parameters of
136
140
/// the item. This is achieved by starting with a base and then concatenating the names of all
137
141
/// other type parameters.
0 commit comments