@@ -28,7 +28,7 @@ use rustc_data_structures::stable_hasher::ToStableHashKey;
2828use lint;
2929use middle:: cstore;
3030
31- use syntax:: ast:: { self , IntTy , UintTy } ;
31+ use syntax:: ast:: { self , IntTy , UintTy , MetaItemKind } ;
3232use syntax:: codemap:: { FileName , FilePathMapping } ;
3333use syntax:: edition:: { Edition , EDITION_NAME_LIST , DEFAULT_EDITION } ;
3434use syntax:: parse:: token;
@@ -1746,22 +1746,33 @@ pub fn parse_cfgspecs(cfgspecs: Vec<String>) -> ast::CrateConfig {
17461746 let mut parser =
17471747 parse:: new_parser_from_source_str ( & sess, FileName :: CfgSpec , s. to_string ( ) ) ;
17481748
1749- let meta_item = panictry ! ( parser. parse_meta_item( ) ) ;
1749+ macro_rules! error { ( $reason: expr) => {
1750+ early_error( ErrorOutputType :: default ( ) ,
1751+ & format!( concat!( "invalid `--cfg` argument: `{}` (" , $reason, ")" ) , s) ) ;
1752+ } }
17501753
1751- if parser. token != token:: Eof {
1752- early_error (
1753- ErrorOutputType :: default ( ) ,
1754- & format ! ( "invalid --cfg argument: {}" , s) ,
1755- )
1756- } else if meta_item. is_meta_item_list ( ) {
1757- let msg = format ! (
1758- "invalid predicate in --cfg command line argument: `{}`" ,
1759- meta_item. ident
1760- ) ;
1761- early_error ( ErrorOutputType :: default ( ) , & msg)
1754+ match & mut parser. parse_meta_item ( ) {
1755+ Ok ( meta_item) if parser. token == token:: Eof => {
1756+ if meta_item. ident . segments . len ( ) != 1 {
1757+ error ! ( "argument key must be an identifier" ) ;
1758+ }
1759+ match & meta_item. node {
1760+ MetaItemKind :: List ( ..) => {
1761+ error ! ( r#"expected `key` or `key="value"`"# ) ;
1762+ }
1763+ MetaItemKind :: NameValue ( lit) if !lit. node . is_str ( ) => {
1764+ error ! ( "argument value must be a string" ) ;
1765+ }
1766+ MetaItemKind :: NameValue ( ..) | MetaItemKind :: Word => {
1767+ return ( meta_item. name ( ) , meta_item. value_str ( ) ) ;
1768+ }
1769+ }
1770+ }
1771+ Ok ( ..) => { }
1772+ Err ( err) => err. cancel ( ) ,
17621773 }
17631774
1764- ( meta_item . name ( ) , meta_item . value_str ( ) )
1775+ error ! ( r#"expected `key` or `key="value"`"# ) ;
17651776 } )
17661777 . collect :: < ast:: CrateConfig > ( )
17671778}
0 commit comments