@@ -24,6 +24,7 @@ use rustc_session::Session;
2424use rustc_session:: { lint, EarlyErrorHandler } ;
2525use rustc_span:: source_map:: { FileLoader , FileName } ;
2626use rustc_span:: symbol:: sym;
27+ use rustc_span:: Symbol ;
2728use std:: path:: PathBuf ;
2829use std:: result;
2930use std:: sync:: Arc ;
@@ -64,7 +65,7 @@ impl Compiler {
6465}
6566
6667/// 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 > {
6869 cfgs. into_iter ( )
6970 . map ( |s| {
7071 let sess = ParseSess :: with_silent_emitter ( Some ( format ! (
@@ -94,10 +95,7 @@ pub(crate) fn parse_cfg(handler: &EarlyErrorHandler, cfgs: Vec<String>) -> Cfg<S
9495 }
9596 MetaItemKind :: NameValue ( ..) | MetaItemKind :: Word => {
9697 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 ( ) ) ;
10199 }
102100 }
103101 }
@@ -118,11 +116,11 @@ pub(crate) fn parse_cfg(handler: &EarlyErrorHandler, cfgs: Vec<String>) -> Cfg<S
118116 error ! ( r#"expected `key` or `key="value"`"# ) ;
119117 }
120118 } )
121- . collect :: < Cfg < String > > ( )
119+ . collect :: < Cfg < Symbol > > ( )
122120}
123121
124122/// 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 > {
126124 // If any --check-cfg is passed then exhaustive_values and exhaustive_names
127125 // are enabled by default.
128126 let exhaustive_names = !specs. is_empty ( ) ;
@@ -179,10 +177,7 @@ pub(crate) fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -
179177 for arg in args {
180178 if arg. is_word ( ) && arg. ident ( ) . is_some ( ) {
181179 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 ) ;
186181 } else {
187182 error ! ( "`names()` arguments must be simple identifiers" ) ;
188183 }
@@ -200,7 +195,7 @@ pub(crate) fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -
200195 let ident = name. ident ( ) . expect ( "multi-segment cfg key" ) ;
201196 let expected_values = check_cfg
202197 . expecteds
203- . entry ( ident. name . to_string ( ) )
198+ . entry ( ident. name )
204199 . and_modify ( |expected_values| match expected_values {
205200 ExpectedValues :: Some ( _) => { }
206201 ExpectedValues :: Any => {
@@ -217,7 +212,7 @@ pub(crate) fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -
217212
218213 for val in values {
219214 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 ) ) ;
221216 } else {
222217 error ! ( "`values()` arguments must be string literals" ) ;
223218 }
@@ -271,10 +266,8 @@ pub(crate) fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -
271266 values_specified = true ;
272267
273268 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) ) ;
278271 } else if arg. has_name ( sym:: any)
279272 && let Some ( args) = arg. meta_item_list ( )
280273 {
@@ -322,7 +315,7 @@ pub(crate) fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -
322315 for name in names {
323316 check_cfg
324317 . expecteds
325- . entry ( name. to_string ( ) )
318+ . entry ( name. name )
326319 . and_modify ( |v| match v {
327320 ExpectedValues :: Some ( v) if !values_any_specified => {
328321 v. extend ( values. clone ( ) )
0 commit comments