]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/session/config.rs
rollup merge of #20258: sanxiyn/show-span-2
[rust.git] / src / librustc / session / config.rs
index 19ac6d466fb5856cd3d768ca54c9b707a81cb29c..138f648049c73f748e6937474f7e94ff38054148 100644 (file)
@@ -18,7 +18,7 @@
 pub use self::OutputType::*;
 pub use self::DebugInfoLevel::*;
 
-use session::{early_error, Session};
+use session::{early_error, early_warn, Session};
 use session::search_paths::SearchPaths;
 
 use rustc_back::target::Target;
@@ -46,7 +46,7 @@ pub struct Config {
     pub uint_type: UintTy,
 }
 
-#[deriving(Clone, Copy, PartialEq)]
+#[derive(Clone, Copy, PartialEq)]
 pub enum OptLevel {
     No, // -O0
     Less, // -O1
@@ -54,14 +54,14 @@ pub enum OptLevel {
     Aggressive // -O3
 }
 
-#[deriving(Clone, Copy, PartialEq)]
+#[derive(Clone, Copy, PartialEq)]
 pub enum DebugInfoLevel {
     NoDebugInfo,
     LimitedDebugInfo,
     FullDebugInfo,
 }
 
-#[deriving(Clone, Copy, PartialEq, PartialOrd, Ord, Eq)]
+#[derive(Clone, Copy, PartialEq, PartialOrd, Ord, Eq)]
 pub enum OutputType {
     OutputTypeBitcode,
     OutputTypeAssembly,
@@ -71,7 +71,7 @@ pub enum OutputType {
     OutputTypeDepInfo,
 }
 
-#[deriving(Clone)]
+#[derive(Clone)]
 pub struct Options {
     // The crate config requested for the session, which may be combined
     // with additional crate configurations during the compile process
@@ -105,6 +105,7 @@ pub struct Options {
     pub prints: Vec<PrintRequest>,
     pub cg: CodegenOptions,
     pub color: ColorConfig,
+    pub show_span: Option<String>,
     pub externs: HashMap<String, Vec<String>>,
     pub crate_name: Option<String>,
     /// An optional name to use as the crate for std during std injection,
@@ -113,7 +114,7 @@ pub struct Options {
     pub alt_std_name: Option<String>
 }
 
-#[deriving(Clone, PartialEq, Eq)]
+#[derive(Clone, PartialEq, Eq)]
 #[allow(missing_copy_implementations)]
 pub enum PrintRequest {
     FileNames,
@@ -137,7 +138,7 @@ pub fn filestem(&self) -> String {
     }
 }
 
-#[deriving(Clone)]
+#[derive(Clone)]
 pub struct OutputFilenames {
     pub out_directory: Path,
     pub out_filestem: String,
@@ -211,6 +212,7 @@ pub fn basic_options() -> Options {
         prints: Vec::new(),
         cg: basic_codegen_options(),
         color: Auto,
+        show_span: None,
         externs: HashMap::new(),
         crate_name: None,
         alt_std_name: None,
@@ -222,14 +224,14 @@ pub fn basic_options() -> Options {
 // users can have their own entry
 // functions that don't start a
 // scheduler
-#[deriving(Copy, PartialEq)]
+#[derive(Copy, PartialEq)]
 pub enum EntryFnType {
     EntryMain,
     EntryStart,
     EntryNone,
 }
 
-#[deriving(Copy, PartialEq, PartialOrd, Clone, Ord, Eq, Hash)]
+#[derive(Copy, PartialEq, PartialOrd, Clone, Ord, Eq, Hash)]
 pub enum CrateType {
     CrateTypeExecutable,
     CrateTypeDylib,
@@ -259,7 +261,6 @@ macro_rules! debugging_opts {
         BORROWCK_STATS,
         NO_LANDING_PADS,
         DEBUG_LLVM,
-        SHOW_SPAN,
         COUNT_TYPE_SIZES,
         META_STATS,
         GC,
@@ -299,7 +300,6 @@ pub fn debugging_opts_map() -> Vec<(&'static str, &'static str, u64)> {
      ("no-landing-pads", "omit landing pads for unwinding",
       NO_LANDING_PADS),
      ("debug-llvm", "enable debug output from LLVM", DEBUG_LLVM),
-     ("show-span", "show spans for compiler debugging", SHOW_SPAN),
      ("count-type-sizes", "count the sizes of aggregate types",
       COUNT_TYPE_SIZES),
      ("meta-stats", "gather metadata statistics", META_STATS),
@@ -337,7 +337,7 @@ pub fn debugging_opts_map() -> Vec<(&'static str, &'static str, u64)> {
     ]
 }
 
-#[deriving(Clone)]
+#[derive(Clone)]
 pub enum Passes {
     SomePasses(Vec<String>),
     AllPasses,
@@ -365,7 +365,7 @@ pub fn is_empty(&self) -> bool {
 macro_rules! cgoptions {
     ($($opt:ident : $t:ty = ($init:expr, $parse:ident, $desc:expr)),* ,) =>
 (
-    #[deriving(Clone)]
+    #[derive(Clone)]
     pub struct CodegenOptions { $(pub $opt: $t),* }
 
     pub fn basic_codegen_options() -> CodegenOptions {
@@ -455,7 +455,7 @@ fn parse_opt_list(slot: &mut Option<Vec<String>>, v: Option<&str>)
         }
 
         fn parse_uint(slot: &mut uint, v: Option<&str>) -> bool {
-            match v.and_then(from_str) {
+            match v.and_then(|s| s.parse()) {
                 Some(i) => { *slot = i; true },
                 None => false
             }
@@ -463,7 +463,7 @@ fn parse_uint(slot: &mut uint, v: Option<&str>) -> bool {
 
         fn parse_opt_uint(slot: &mut Option<uint>, v: Option<&str>) -> bool {
             match v {
-                Some(s) => { *slot = from_str(s); slot.is_some() }
+                Some(s) => { *slot = s.parse(); slot.is_some() }
                 None => { *slot = None; true }
             }
         }
@@ -673,10 +673,10 @@ pub fn optgroups() -> Vec<getopts::OptGroup> {
         .collect()
 }
 
-#[deriving(Copy, Clone, PartialEq, Eq, Show)]
+#[derive(Copy, Clone, PartialEq, Eq, Show)]
 pub enum OptionStability { Stable, Unstable }
 
-#[deriving(Clone, PartialEq, Eq)]
+#[derive(Clone, PartialEq, Eq)]
 pub struct RustcOptGroup {
     pub opt_group: getopts::OptGroup,
     pub stability: OptionStability,
@@ -743,7 +743,7 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
         opt::multi("l", "",   "Link the generated crate(s) to the specified native
                              library NAME. The optional KIND can be one of,
                              static, dylib, or framework. If omitted, dylib is
-                             assumed.", "NAME[:KIND]"),
+                             assumed.", "[KIND=]NAME"),
         opt::multi("", "crate-type", "Comma separated list of types of crates
                                     for the compiler to emit",
                    "[bin|lib|rlib|dylib|staticlib]"),
@@ -754,7 +754,7 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
                  "[asm|llvm-bc|llvm-ir|obj|link|dep-info]"),
         opt::multi("", "print", "Comma separated list of compiler information to \
                                print on stdout",
-                 "[crate-name|output-file-names|sysroot]"),
+                 "[crate-name|file-names|sysroot]"),
         opt::flag("g",  "",  "Equivalent to -C debuginfo=2"),
         opt::flag("O", "", "Equivalent to -C opt-level=2"),
         opt::opt("o", "", "Write output to <filename>", "FILENAME"),
@@ -823,6 +823,7 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
                       `flowgraph=<nodeid>` (graphviz formatted flowgraph for node), or
                       `everybody_loops` (all function bodies replaced with `loop {}`).",
                      "TYPE"),
+        opt::opt_u("", "show-span", "Show spans for compiler debugging", "expr|pat|ty"),
         opt::flagopt("", "dep-info",
                  "Output dependency info to <filename> after compiling, \
                   in a format suitable for use by Makefiles", "FILENAME"),
@@ -878,22 +879,22 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
     }
 
     let parse_only = if matches.opt_present("parse-only") {
-        // FIXME(acrichto) uncomment deprecation warning
-        // early_warn("--parse-only is deprecated in favor of -Z parse-only");
+        // FIXME(acrichto) remove this eventually
+        early_warn("--parse-only is deprecated in favor of -Z parse-only");
         true
     } else {
         debugging_opts & PARSE_ONLY != 0
     };
     let no_trans = if matches.opt_present("no-trans") {
-        // FIXME(acrichto) uncomment deprecation warning
-        // early_warn("--no-trans is deprecated in favor of -Z no-trans");
+        // FIXME(acrichto) remove this eventually
+        early_warn("--no-trans is deprecated in favor of -Z no-trans");
         true
     } else {
         debugging_opts & NO_TRANS != 0
     };
     let no_analysis = if matches.opt_present("no-analysis") {
-        // FIXME(acrichto) uncomment deprecation warning
-        // early_warn("--no-analysis is deprecated in favor of -Z no-analysis");
+        // FIXME(acrichto) remove this eventually
+        early_warn("--no-analysis is deprecated in favor of -Z no-analysis");
         true
     } else {
         debugging_opts & NO_ANALYSIS != 0
@@ -945,8 +946,8 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
             }
             Default
         } else if matches.opt_present("opt-level") {
-            // FIXME(acrichto) uncomment deprecation warning
-            // early_warn("--opt-level=N is deprecated in favor of -C opt-level=N");
+            // FIXME(acrichto) remove this eventually
+            early_warn("--opt-level=N is deprecated in favor of -C opt-level=N");
             match matches.opt_str("opt-level").as_ref().map(|s| s.as_slice()) {
                 None      |
                 Some("0") => No,
@@ -984,8 +985,8 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
         }
         FullDebugInfo
     } else if matches.opt_present("debuginfo") {
-        // FIXME(acrichto) uncomment deprecation warning
-        // early_warn("--debuginfo=N is deprecated in favor of -C debuginfo=N");
+        // FIXME(acrichto) remove this eventually
+        early_warn("--debuginfo=N is deprecated in favor of -C debuginfo=N");
         match matches.opt_str("debuginfo").as_ref().map(|s| s.as_slice()) {
             Some("0") => NoDebugInfo,
             Some("1") => LimitedDebugInfo,
@@ -1016,6 +1017,24 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
     }
 
     let libs = matches.opt_strs("l").into_iter().map(|s| {
+        let mut parts = s.splitn(1, '=');
+        let kind = parts.next().unwrap();
+        if let Some(name) = parts.next() {
+            let kind = match kind {
+                "dylib" => cstore::NativeUnknown,
+                "framework" => cstore::NativeFramework,
+                "static" => cstore::NativeStatic,
+                s => {
+                    early_error(format!("unknown library kind `{}`, expected \
+                                         one of dylib, framework, or static",
+                                        s)[]);
+                }
+            };
+            return (name.to_string(), kind)
+        }
+
+        // FIXME(acrichto) remove this once crates have stopped using it, this
+        //                 is deprecated behavior now.
         let mut parts = s.rsplitn(1, ':');
         let kind = parts.next().unwrap();
         let (name, kind) = match (parts.next(), kind) {
@@ -1035,8 +1054,8 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
     let cfg = parse_cfgspecs(matches.opt_strs("cfg"));
     let test = matches.opt_present("test");
     let write_dependency_info = if matches.opt_present("dep-info") {
-        // FIXME(acrichto) uncomment deprecation warning
-        // early_warn("--dep-info has been deprecated in favor of --emit");
+        // FIXME(acrichto) remove this eventually
+        early_warn("--dep-info has been deprecated in favor of --emit");
         (true, matches.opt_str("dep-info").map(|p| Path::new(p)))
     } else {
         (output_types.contains(&OutputTypeDepInfo), None)
@@ -1053,22 +1072,21 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
         }
     }).collect::<Vec<_>>();
     if matches.opt_present("print-crate-name") {
-        // FIXME(acrichto) uncomment deprecation warning
-        // early_warn("--print-crate-name has been deprecated in favor of \
-        //             --print crate-name");
+        // FIXME(acrichto) remove this eventually
+        early_warn("--print-crate-name has been deprecated in favor of \
+                    --print crate-name");
         prints.push(PrintRequest::CrateName);
     }
     if matches.opt_present("print-file-name") {
-        // FIXME(acrichto) uncomment deprecation warning
-        // early_warn("--print-file-name has been deprecated in favor of \
-        //             --print file-names");
+        // FIXME(acrichto) remove this eventually
+        early_warn("--print-file-name has been deprecated in favor of \
+                    --print file-names");
         prints.push(PrintRequest::FileNames);
     }
 
     if !cg.remark.is_empty() && debuginfo == NoDebugInfo {
-        // FIXME(acrichto) uncomment deprecation warning
-        // early_warn("-C remark will not show source locations without \
-        //             --debuginfo");
+        early_warn("-C remark will not show source locations without \
+                    --debuginfo");
     }
 
     let color = match matches.opt_str("color").as_ref().map(|s| s[]) {
@@ -1097,8 +1115,8 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
             None => early_error("--extern value must be of the format `foo=bar`"),
         };
 
-        match externs.entry(name.to_string()) {
-            Vacant(entry) => { entry.set(vec![location.to_string()]); },
+        match externs.entry(&name.to_string()) {
+            Vacant(entry) => { entry.insert(vec![location.to_string()]); },
             Occupied(mut entry) => { entry.get_mut().push(location.to_string()); },
         }
     }
@@ -1126,6 +1144,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
         prints: prints,
         cg: cg,
         color: color,
+        show_span: None,
         externs: externs,
         crate_name: crate_name,
         alt_std_name: None,