@@ -92,7 +92,7 @@ use crate::deriving::pathvec_std;
92
92
use rustc_ast:: ast:: { Expr , ExprKind , MetaItem , Mutability } ;
93
93
use rustc_ast:: ptr:: P ;
94
94
use rustc_expand:: base:: { Annotatable , ExtCtxt } ;
95
- use rustc_span:: symbol:: { sym, Symbol } ;
95
+ use rustc_span:: symbol:: { sym, Ident , Symbol } ;
96
96
use rustc_span:: Span ;
97
97
98
98
pub fn expand_deriving_rustc_encodable (
@@ -102,13 +102,13 @@ pub fn expand_deriving_rustc_encodable(
102
102
item : & Annotatable ,
103
103
push : & mut dyn FnMut ( Annotatable ) ,
104
104
) {
105
- let krate = " rustc_serialize" ;
106
- let typaram = " __S" ;
105
+ let krate = sym :: rustc_serialize;
106
+ let typaram = sym :: __S;
107
107
108
108
let trait_def = TraitDef {
109
109
span,
110
110
attributes : Vec :: new ( ) ,
111
- path : Path :: new_ ( vec ! [ krate, " Encodable" ] , None , vec ! [ ] , PathKind :: Global ) ,
111
+ path : Path :: new_ ( vec ! [ krate, sym :: Encodable ] , None , vec ! [ ] , PathKind :: Global ) ,
112
112
additional_bounds : Vec :: new ( ) ,
113
113
generics : Bounds :: empty ( ) ,
114
114
is_unsafe : false ,
@@ -118,21 +118,26 @@ pub fn expand_deriving_rustc_encodable(
118
118
generics: Bounds {
119
119
bounds: vec![ (
120
120
typaram,
121
- vec![ Path :: new_( vec![ krate, " Encoder" ] , None , vec![ ] , PathKind :: Global ) ] ,
121
+ vec![ Path :: new_( vec![ krate, sym :: Encoder ] , None , vec![ ] , PathKind :: Global ) ] ,
122
122
) ] ,
123
123
} ,
124
124
explicit_self: borrowed_explicit_self( ) ,
125
125
args: vec![ (
126
126
Ptr ( Box :: new( Literal ( Path :: new_local( typaram) ) ) , Borrowed ( None , Mutability :: Mut ) ) ,
127
- "s" ,
127
+ // FIXME: we could use `sym::s` here, but making `s` a static
128
+ // symbol changes the symbol index ordering in a way that makes
129
+ // ui/lint/rfc-2457-non-ascii-idents/lint-confusable-idents.rs
130
+ // fail. The linting code should be fixed so that its output
131
+ // does not depend on the symbol index ordering.
132
+ Symbol :: intern( "s" ) ,
128
133
) ] ,
129
134
ret_ty: Literal ( Path :: new_(
130
135
pathvec_std!( result:: Result ) ,
131
136
None ,
132
137
vec![
133
138
Box :: new( Tuple ( Vec :: new( ) ) ) ,
134
139
Box :: new( Literal ( Path :: new_(
135
- vec![ typaram, " Error" ] ,
140
+ vec![ typaram, sym :: Error ] ,
136
141
None ,
137
142
vec![ ] ,
138
143
PathKind :: Local ,
@@ -157,24 +162,24 @@ fn encodable_substructure(
157
162
cx : & mut ExtCtxt < ' _ > ,
158
163
trait_span : Span ,
159
164
substr : & Substructure < ' _ > ,
160
- krate : & ' static str ,
165
+ krate : Symbol ,
161
166
) -> P < Expr > {
162
167
let encoder = substr. nonself_args [ 0 ] . clone ( ) ;
163
168
// throw an underscore in front to suppress unused variable warnings
164
- let blkarg = cx . ident_of ( "_e" , trait_span) ;
169
+ let blkarg = Ident :: new ( sym :: _e , trait_span) ;
165
170
let blkencoder = cx. expr_ident ( trait_span, blkarg) ;
166
171
let fn_path = cx. expr_path ( cx. path_global (
167
172
trait_span,
168
173
vec ! [
169
- cx . ident_of ( krate, trait_span) ,
170
- cx . ident_of ( " Encodable" , trait_span) ,
171
- cx . ident_of ( " encode" , trait_span) ,
174
+ Ident :: new ( krate, trait_span) ,
175
+ Ident :: new ( sym :: Encodable , trait_span) ,
176
+ Ident :: new ( sym :: encode, trait_span) ,
172
177
] ,
173
178
) ) ;
174
179
175
180
match * substr. fields {
176
181
Struct ( _, ref fields) => {
177
- let emit_struct_field = cx . ident_of ( " emit_struct_field" , trait_span) ;
182
+ let emit_struct_field = Ident :: new ( sym :: emit_struct_field, trait_span) ;
178
183
let mut stmts = Vec :: new ( ) ;
179
184
for ( i, & FieldInfo { name, ref self_, span, .. } ) in fields. iter ( ) . enumerate ( ) {
180
185
let name = match name {
@@ -214,7 +219,7 @@ fn encodable_substructure(
214
219
cx. expr_method_call (
215
220
trait_span,
216
221
encoder,
217
- cx . ident_of ( " emit_struct" , trait_span) ,
222
+ Ident :: new ( sym :: emit_struct, trait_span) ,
218
223
vec ! [
219
224
cx. expr_str( trait_span, substr. type_ident. name) ,
220
225
cx. expr_usize( trait_span, fields. len( ) ) ,
@@ -230,7 +235,7 @@ fn encodable_substructure(
230
235
// actually exist.
231
236
let me = cx. stmt_let ( trait_span, false , blkarg, encoder) ;
232
237
let encoder = cx. expr_ident ( trait_span, blkarg) ;
233
- let emit_variant_arg = cx . ident_of ( " emit_enum_variant_arg" , trait_span) ;
238
+ let emit_variant_arg = Ident :: new ( sym :: emit_enum_variant_arg, trait_span) ;
234
239
let mut stmts = Vec :: new ( ) ;
235
240
if !fields. is_empty ( ) {
236
241
let last = fields. len ( ) - 1 ;
@@ -263,7 +268,7 @@ fn encodable_substructure(
263
268
let call = cx. expr_method_call (
264
269
trait_span,
265
270
blkencoder,
266
- cx . ident_of ( " emit_enum_variant" , trait_span) ,
271
+ Ident :: new ( sym :: emit_enum_variant, trait_span) ,
267
272
vec ! [
268
273
name,
269
274
cx. expr_usize( trait_span, idx) ,
@@ -275,7 +280,7 @@ fn encodable_substructure(
275
280
let ret = cx. expr_method_call (
276
281
trait_span,
277
282
encoder,
278
- cx . ident_of ( " emit_enum" , trait_span) ,
283
+ Ident :: new ( sym :: emit_enum, trait_span) ,
279
284
vec ! [ cx. expr_str( trait_span, substr. type_ident. name) , blk] ,
280
285
) ;
281
286
cx. expr_block ( cx. block ( trait_span, vec ! [ me, cx. stmt_expr( ret) ] ) )
0 commit comments