@@ -24,6 +24,7 @@ use rustc_session::Session;
24
24
use rustc_session:: { lint, EarlyErrorHandler } ;
25
25
use rustc_span:: source_map:: { FileLoader , FileName } ;
26
26
use rustc_span:: symbol:: sym;
27
+ use rustc_span:: Symbol ;
27
28
use std:: path:: PathBuf ;
28
29
use std:: result;
29
30
use std:: sync:: Arc ;
@@ -64,7 +65,7 @@ impl Compiler {
64
65
}
65
66
66
67
/// Converts strings provided as `--cfg [cfgspec]` into a `Cfg`.
67
- pub ( crate ) fn parse_cfg ( handler : & EarlyErrorHandler , cfgs : Vec < String > ) -> Cfg < String > {
68
+ pub ( crate ) fn parse_cfg ( handler : & EarlyErrorHandler , cfgs : Vec < String > ) -> Cfg < Symbol > {
68
69
cfgs. into_iter ( )
69
70
. map ( |s| {
70
71
let sess = ParseSess :: with_silent_emitter ( Some ( format ! (
@@ -94,10 +95,7 @@ pub(crate) fn parse_cfg(handler: &EarlyErrorHandler, cfgs: Vec<String>) -> Cfg<S
94
95
}
95
96
MetaItemKind :: NameValue ( ..) | MetaItemKind :: Word => {
96
97
let ident = meta_item. ident ( ) . expect ( "multi-segment cfg key" ) ;
97
- return (
98
- ident. name . to_string ( ) ,
99
- meta_item. value_str ( ) . map ( |sym| sym. to_string ( ) ) ,
100
- ) ;
98
+ return ( ident. name , meta_item. value_str ( ) ) ;
101
99
}
102
100
}
103
101
}
@@ -118,11 +116,11 @@ pub(crate) fn parse_cfg(handler: &EarlyErrorHandler, cfgs: Vec<String>) -> Cfg<S
118
116
error ! ( r#"expected `key` or `key="value"`"# ) ;
119
117
}
120
118
} )
121
- . collect :: < Cfg < String > > ( )
119
+ . collect :: < Cfg < Symbol > > ( )
122
120
}
123
121
124
122
/// Converts strings provided as `--check-cfg [specs]` into a `CheckCfg`.
125
- pub ( crate ) fn parse_check_cfg ( handler : & EarlyErrorHandler , specs : Vec < String > ) -> CheckCfg < String > {
123
+ pub ( crate ) fn parse_check_cfg ( handler : & EarlyErrorHandler , specs : Vec < String > ) -> CheckCfg < Symbol > {
126
124
// If any --check-cfg is passed then exhaustive_values and exhaustive_names
127
125
// are enabled by default.
128
126
let exhaustive_names = !specs. is_empty ( ) ;
@@ -179,10 +177,7 @@ pub(crate) fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -
179
177
for arg in args {
180
178
if arg. is_word ( ) && arg. ident ( ) . is_some ( ) {
181
179
let ident = arg. ident ( ) . expect ( "multi-segment cfg key" ) ;
182
- check_cfg
183
- . expecteds
184
- . entry ( ident. name . to_string ( ) )
185
- . or_insert ( ExpectedValues :: Any ) ;
180
+ check_cfg. expecteds . entry ( ident. name ) . or_insert ( ExpectedValues :: Any ) ;
186
181
} else {
187
182
error ! ( "`names()` arguments must be simple identifiers" ) ;
188
183
}
@@ -200,7 +195,7 @@ pub(crate) fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -
200
195
let ident = name. ident ( ) . expect ( "multi-segment cfg key" ) ;
201
196
let expected_values = check_cfg
202
197
. expecteds
203
- . entry ( ident. name . to_string ( ) )
198
+ . entry ( ident. name )
204
199
. and_modify ( |expected_values| match expected_values {
205
200
ExpectedValues :: Some ( _) => { }
206
201
ExpectedValues :: Any => {
@@ -217,7 +212,7 @@ pub(crate) fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -
217
212
218
213
for val in values {
219
214
if let Some ( LitKind :: Str ( s, _) ) = val. lit ( ) . map ( |lit| & lit. kind ) {
220
- expected_values. insert ( Some ( s . to_string ( ) ) ) ;
215
+ expected_values. insert ( Some ( * s ) ) ;
221
216
} else {
222
217
error ! ( "`values()` arguments must be string literals" ) ;
223
218
}
@@ -271,10 +266,8 @@ pub(crate) fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -
271
266
values_specified = true ;
272
267
273
268
for arg in args {
274
- if let Some ( LitKind :: Str ( s, _) ) =
275
- arg. lit ( ) . map ( |lit| & lit. kind )
276
- {
277
- values. insert ( Some ( s. to_string ( ) ) ) ;
269
+ if let Some ( LitKind :: Str ( s, _) ) = arg. lit ( ) . map ( |lit| & lit. kind ) {
270
+ values. insert ( Some ( * s) ) ;
278
271
} else if arg. has_name ( sym:: any)
279
272
&& let Some ( args) = arg. meta_item_list ( )
280
273
{
@@ -322,7 +315,7 @@ pub(crate) fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -
322
315
for name in names {
323
316
check_cfg
324
317
. expecteds
325
- . entry ( name. to_string ( ) )
318
+ . entry ( name. name )
326
319
. and_modify ( |v| match v {
327
320
ExpectedValues :: Some ( v) if !values_any_specified => {
328
321
v. extend ( values. clone ( ) )
0 commit comments