]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_driver/lib.rs
rollup merge of #21830: japaric/for-cleanup
[rust.git] / src / librustc_driver / lib.rs
index e35bc807d2828b9533165b090d4f3d0c603060f5..d71e85e6a55c60a918c210e4cbe483d1bbe7c743 100644 (file)
@@ -15,7 +15,7 @@
 //! This API is completely unstable and subject to change.
 
 #![crate_name = "rustc_driver"]
-#![unstable(feature = "unnamed_feature", since = "1.0.0")]
+#![unstable(feature = "rustc_private")]
 #![staged_api]
 #![crate_type = "dylib"]
 #![crate_type = "rlib"]
       html_favicon_url = "http://www.rust-lang.org/favicon.ico",
       html_root_url = "http://doc.rust-lang.org/nightly/")]
 
-#![allow(unknown_features)]
-#![feature(quote)]
-#![feature(slicing_syntax, unsafe_destructor)]
 #![feature(box_syntax)]
+#![feature(collections)]
+#![feature(core)]
+#![feature(env)]
+#![feature(int_uint)]
+#![feature(io)]
+#![feature(libc)]
+#![feature(os)]
+#![feature(path)]
+#![feature(quote)]
 #![feature(rustc_diagnostic_macros)]
-#![allow(unknown_features)] #![feature(int_uint)]
-#![allow(unstable)]
+#![feature(rustc_private)]
+#![feature(slicing_syntax, unsafe_destructor)]
+#![feature(staged_api)]
+#![feature(std_misc)]
+#![feature(unicode)]
 
 extern crate arena;
 extern crate flate;
 use rustc::lint;
 use rustc::metadata;
 use rustc::metadata::creader::CrateOrString::Str;
-use rustc::DIAGNOSTICS;
 use rustc::util::common::time;
 
 use std::cmp::Ordering::Equal;
-use std::io;
+use std::old_io;
 use std::iter::repeat;
-use std::os;
+use std::env;
 use std::sync::mpsc::channel;
 use std::thread;
 
@@ -98,7 +106,7 @@ fn run_compiler(args: &[String]) {
         None => return
     };
 
-    let descriptions = diagnostics::registry::Registry::new(&DIAGNOSTICS);
+    let descriptions = diagnostics_registry();
     match matches.opt_str("explain") {
         Some(ref code) => {
             match descriptions.find_description(&code[]) {
@@ -134,7 +142,7 @@ fn run_compiler(args: &[String]) {
         1u => {
             let ifile = &matches.free[0][];
             if ifile == "-" {
-                let contents = io::stdin().read_to_end().unwrap();
+                let contents = old_io::stdin().read_to_end().unwrap();
                 let src = String::from_utf8(contents).unwrap();
                 (Input::Str(src), None)
             } else {
@@ -154,10 +162,14 @@ fn run_compiler(args: &[String]) {
         return
     }
 
-    let pretty = matches.opt_default("pretty", "normal").map(|a| {
-        // stable pretty-print variants only
-        pretty::parse_pretty(&sess, a.as_slice(), false)
-    });
+    let pretty = if sess.opts.debugging_opts.unstable_options {
+        matches.opt_default("pretty", "normal").map(|a| {
+            // stable pretty-print variants only
+            pretty::parse_pretty(&sess, a.as_slice(), false)
+        })
+    } else {
+        None
+    };
     let pretty = if pretty.is_none() &&
         sess.unstable_options() {
             matches.opt_str("xpretty").map(|a| {
@@ -184,7 +196,7 @@ fn run_compiler(args: &[String]) {
     if r.contains(&("ls".to_string())) {
         match input {
             Input::File(ref ifile) => {
-                let mut stdout = io::stdout();
+                let mut stdout = old_io::stdout();
                 list_metadata(&sess, &(*ifile), &mut stdout).unwrap();
             }
             Input::Str(_) => {
@@ -241,7 +253,7 @@ pub fn get_unstable_features_setting() -> UnstableFeatures {
     // subverting the unstable features lints
     let bootstrap_secret_key = option_env!("CFG_BOOTSTRAP_KEY");
     // The matching key to the above, only known by the build system
-    let bootstrap_provided_key = os::getenv("RUSTC_BOOTSTRAP_KEY");
+    let bootstrap_provided_key = env::var_string("RUSTC_BOOTSTRAP_KEY").ok();
     match (disable_unstable_features, bootstrap_secret_key, bootstrap_provided_key) {
         (_, Some(ref s), Some(ref p)) if s == p => UnstableFeatures::Cheat,
         (true, _, _) => UnstableFeatures::Disallow,
@@ -362,7 +374,7 @@ fn sort_lint_groups(lints: Vec<(&'static str, Vec<lint::LintId>, bool)>)
     println!("    {}  {:7.7}  {}", padded("----"), "-------", "-------");
 
     let print_lints = |&: lints: Vec<&Lint>| {
-        for lint in lints.into_iter() {
+        for lint in lints {
             let name = lint.name_lower().replace("_", "-");
             println!("    {}  {:7.7}  {}",
                      padded(&name[]), lint.default_level.as_str(), lint.desc);
@@ -389,7 +401,7 @@ fn sort_lint_groups(lints: Vec<(&'static str, Vec<lint::LintId>, bool)>)
     println!("    {}  {}", padded("----"), "---------");
 
     let print_lint_groups = |&: lints: Vec<(&'static str, Vec<lint::LintId>)>| {
-        for (name, to) in lints.into_iter() {
+        for (name, to) in lints {
             let name = name.chars().map(|x| x.to_lowercase())
                            .collect::<String>().replace("_", "-");
             let desc = to.into_iter().map(|x| x.as_str().replace("_", "-"))
@@ -424,7 +436,7 @@ fn sort_lint_groups(lints: Vec<(&'static str, Vec<lint::LintId>, bool)>)
 
 fn describe_debug_flags() {
     println!("\nAvailable debug options:\n");
-    for &(name, _, opt_type_desc, desc) in config::DB_OPTIONS.iter() {
+    for &(name, _, opt_type_desc, desc) in config::DB_OPTIONS {
         let (width, extra) = match opt_type_desc {
             Some(..) => (21, "=val"),
             None => (25, "")
@@ -436,7 +448,7 @@ fn describe_debug_flags() {
 
 fn describe_codegen_flags() {
     println!("\nAvailable codegen options:\n");
-    for &(name, _, opt_type_desc, desc) in config::CG_OPTIONS.iter() {
+    for &(name, _, opt_type_desc, desc) in config::CG_OPTIONS {
         let (width, extra) = match opt_type_desc {
             Some(..) => (21, "=val"),
             None => (25, "")
@@ -531,7 +543,7 @@ fn print_crate_info(sess: &Session,
     if sess.opts.prints.len() == 0 { return false }
 
     let attrs = input.map(|input| parse_crate_attrs(sess, input));
-    for req in sess.opts.prints.iter() {
+    for req in &sess.opts.prints {
         match *req {
             PrintRequest::Sysroot => println!("{}", sess.sysroot().display()),
             PrintRequest::FileNames |
@@ -555,7 +567,7 @@ fn print_crate_info(sess: &Session,
                 let crate_types = driver::collect_crate_types(sess, attrs);
                 let metadata = driver::collect_crate_metadata(sess, attrs);
                 *sess.crate_metadata.borrow_mut() = metadata;
-                for &style in crate_types.iter() {
+                for &style in &crate_types {
                     let fname = link::filename_for_input(sess, style,
                                                          id.as_slice(),
                                                          &t_outputs.with_extension(""));
@@ -587,7 +599,7 @@ fn parse_crate_attrs(sess: &Session, input: &Input) ->
 }
 
 pub fn list_metadata(sess: &Session, path: &Path,
-                     out: &mut io::Writer) -> io::IoResult<()> {
+                     out: &mut old_io::Writer) -> old_io::IoResult<()> {
     metadata::loader::list_file_metadata(sess.target.target.options.is_like_osx, path, out)
 }
 
@@ -600,18 +612,18 @@ pub fn monitor<F:FnOnce()+Send>(f: F) {
     static STACK_SIZE: uint = 8 * 1024 * 1024; // 8MB
 
     let (tx, rx) = channel();
-    let w = io::ChanWriter::new(tx);
-    let mut r = io::ChanReader::new(rx);
+    let w = old_io::ChanWriter::new(tx);
+    let mut r = old_io::ChanReader::new(rx);
 
     let mut cfg = thread::Builder::new().name("rustc".to_string());
 
     // FIXME: Hacks on hacks. If the env is trying to override the stack size
     // then *don't* set it explicitly.
-    if os::getenv("RUST_MIN_STACK").is_none() {
+    if env::var("RUST_MIN_STACK").is_none() {
         cfg = cfg.stack_size(STACK_SIZE);
     }
 
-    match cfg.scoped(move || { std::io::stdio::set_stderr(box w); f() }).join() {
+    match cfg.scoped(move || { std::old_io::stdio::set_stderr(box w); f() }).join() {
         Ok(()) => { /* fallthrough */ }
         Err(value) => {
             // Thread panicked without emitting a fatal diagnostic
@@ -634,7 +646,7 @@ pub fn monitor<F:FnOnce()+Send>(f: F) {
                             BUG_REPORT_URL),
                     "run with `RUST_BACKTRACE=1` for a backtrace".to_string(),
                 ];
-                for note in xs.iter() {
+                for note in &xs {
                     emitter.emit(None, &note[], None, diagnostic::Note)
                 }
 
@@ -653,14 +665,26 @@ pub fn monitor<F:FnOnce()+Send>(f: F) {
             // Panic so the process returns a failure code, but don't pollute the
             // output with some unnecessary panic messages, we've already
             // printed everything that we needed to.
-            io::stdio::set_stderr(box io::util::NullWriter);
+            old_io::stdio::set_stderr(box old_io::util::NullWriter);
             panic!();
         }
     }
 }
 
+pub fn diagnostics_registry() -> diagnostics::registry::Registry {
+    use syntax::diagnostics::registry::Registry;
+
+    let all_errors = Vec::new() +
+        rustc::diagnostics::DIAGNOSTICS.as_slice() +
+        rustc_typeck::diagnostics::DIAGNOSTICS.as_slice() +
+        rustc_resolve::diagnostics::DIAGNOSTICS.as_slice();
+
+    Registry::new(&*all_errors)
+}
+
 pub fn main() {
-    let args = std::os::args();
-    let result = run(args);
-    std::os::set_exit_status(result);
+    let args = env::args().map(|s| s.into_string().unwrap());
+    let result = run(args.collect());
+    std::env::set_exit_status(result as i32);
 }
+