@@ -21,7 +21,7 @@ use rustc_target::spec::{Target, TargetTriple};
2121use lint;
2222use middle:: cstore;
2323
24- use syntax:: ast:: { self , IntTy , UintTy } ;
24+ use syntax:: ast:: { self , IntTy , UintTy , MetaItemKind } ;
2525use syntax:: source_map:: { FileName , FilePathMapping } ;
2626use syntax:: edition:: { Edition , EDITION_NAME_LIST , DEFAULT_EDITION } ;
2727use syntax:: parse:: token;
@@ -1735,22 +1735,33 @@ pub fn parse_cfgspecs(cfgspecs: Vec<String>) -> ast::CrateConfig {
17351735 let mut parser =
17361736 parse:: new_parser_from_source_str ( & sess, FileName :: CfgSpec , s. to_string ( ) ) ;
17371737
1738- let meta_item = panictry ! ( parser. parse_meta_item( ) ) ;
1738+ macro_rules! error { ( $reason: expr) => {
1739+ early_error( ErrorOutputType :: default ( ) ,
1740+ & format!( concat!( "invalid `--cfg` argument: `{}` (" , $reason, ")" ) , s) ) ;
1741+ } }
17391742
1740- if parser. token != token:: Eof {
1741- early_error (
1742- ErrorOutputType :: default ( ) ,
1743- & format ! ( "invalid --cfg argument: {}" , s) ,
1744- )
1745- } else if meta_item. is_meta_item_list ( ) {
1746- let msg = format ! (
1747- "invalid predicate in --cfg command line argument: `{}`" ,
1748- meta_item. ident
1749- ) ;
1750- early_error ( ErrorOutputType :: default ( ) , & msg)
1743+ match & mut parser. parse_meta_item ( ) {
1744+ Ok ( meta_item) if parser. token == token:: Eof => {
1745+ if meta_item. ident . segments . len ( ) != 1 {
1746+ error ! ( "argument key must be an identifier" ) ;
1747+ }
1748+ match & meta_item. node {
1749+ MetaItemKind :: List ( ..) => {
1750+ error ! ( r#"expected `key` or `key="value"`"# ) ;
1751+ }
1752+ MetaItemKind :: NameValue ( lit) if !lit. node . is_str ( ) => {
1753+ error ! ( "argument value must be a string" ) ;
1754+ }
1755+ MetaItemKind :: NameValue ( ..) | MetaItemKind :: Word => {
1756+ return ( meta_item. name ( ) , meta_item. value_str ( ) ) ;
1757+ }
1758+ }
1759+ }
1760+ Ok ( ..) => { }
1761+ Err ( err) => err. cancel ( ) ,
17511762 }
17521763
1753- ( meta_item . name ( ) , meta_item . value_str ( ) )
1764+ error ! ( r#"expected `key` or `key="value"`"# ) ;
17541765 } )
17551766 . collect :: < ast:: CrateConfig > ( )
17561767}
0 commit comments