]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_driver/driver.rs
rollup merge of #21830: japaric/for-cleanup
[rust.git] / src / librustc_driver / driver.rs
index 36a9c0e16f018e926c4675cfa25f1173dd11d6c7..9b9cc14c4761510dd53634732a23eb4a2a9513ae 100644 (file)
 
 use serialize::json;
 
-use std::old_io;
+use std::env;
+use std::ffi::OsString;
 use std::old_io::fs;
-use std::os;
+use std::old_io;
 use syntax::ast;
 use syntax::ast_map;
 use syntax::attr;
@@ -100,6 +101,7 @@ macro_rules! controller_entry_point{($point: ident, $make_state: expr) => ({
                                                                  &id[]));
 
         let mut forest = ast_map::Forest::new(expanded_crate);
+        let arenas = ty::CtxtArenas::new();
         let ast_map = assign_node_ids_and_map(&sess, &mut forest);
 
         write_out_deps(&sess, input, &outputs, &id[]);
@@ -111,7 +113,6 @@ macro_rules! controller_entry_point{($point: ident, $make_state: expr) => ({
                                                                      &ast_map,
                                                                      &id[]));
 
-        let arenas = ty::CtxtArenas::new();
         let analysis = phase_3_run_analysis_passes(sess,
                                                    ast_map,
                                                    &arenas,
@@ -390,16 +391,10 @@ pub fn phase_2_configure_and_expand(sess: &Session,
     // baz! should not use this definition unless foo is enabled.
 
     time(time_passes, "gated macro checking", (), |_| {
-        let (features, unknown_features) =
+        let features =
             syntax::feature_gate::check_crate_macros(sess.codemap(),
                                                      &sess.parse_sess.span_diagnostic,
                                                      &krate);
-        for uf in unknown_features.iter() {
-            sess.add_lint(lint::builtin::UNKNOWN_FEATURES,
-                          ast::CRATE_NODE_ID,
-                          *uf,
-                          "unknown feature".to_string());
-        }
 
         // these need to be set "early" so that expansion sees `quote` if enabled.
         *sess.features.borrow_mut() = features;
@@ -430,7 +425,7 @@ pub fn phase_2_configure_and_expand(sess: &Session,
                 diagnostics::plugin::expand_build_diagnostic_array);
         }
 
-        for registrar in registrars.into_iter() {
+        for registrar in registrars {
             registry.args_hidden = Some(registrar.args);
             (registrar.fun)(&mut registry);
         }
@@ -440,11 +435,11 @@ pub fn phase_2_configure_and_expand(sess: &Session,
 
     {
         let mut ls = sess.lint_store.borrow_mut();
-        for pass in lint_passes.into_iter() {
+        for pass in lint_passes {
             ls.register_pass(Some(sess), true, pass);
         }
 
-        for (name, to) in lint_groups.into_iter() {
+        for (name, to) in lint_groups {
             ls.register_group(Some(sess), true, name, to);
         }
     }
@@ -466,12 +461,12 @@ pub fn phase_2_configure_and_expand(sess: &Session,
             // dependent dlls. Note that this uses cfg!(windows) as opposed to
             // targ_cfg because syntax extensions are always loaded for the host
             // compiler, not for the target.
-            let mut _old_path = String::new();
+            let mut _old_path = OsString::from_str("");
             if cfg!(windows) {
-                _old_path = os::getenv("PATH").unwrap_or(_old_path);
+                _old_path = env::var("PATH").unwrap_or(_old_path);
                 let mut new_path = sess.host_filesearch(PathKind::All).get_dylib_search_paths();
-                new_path.extend(os::split_paths(&_old_path[]).into_iter());
-                os::setenv("PATH", os::join_paths(&new_path[]).unwrap());
+                new_path.extend(env::split_paths(&_old_path));
+                env::set_var("PATH", &env::join_paths(new_path.iter()).unwrap());
             }
             let cfg = syntax::ext::expand::ExpansionConfig {
                 crate_name: crate_name.to_string(),
@@ -484,7 +479,7 @@ pub fn phase_2_configure_and_expand(sess: &Session,
                                               syntax_exts,
                                               krate);
             if cfg!(windows) {
-                os::setenv("PATH", _old_path);
+                env::set_var("PATH", &_old_path);
             }
             ret
         }
@@ -492,9 +487,11 @@ pub fn phase_2_configure_and_expand(sess: &Session,
 
     // Needs to go *after* expansion to be able to check the results of macro expansion.
     time(time_passes, "complete gated feature checking", (), |_| {
-        syntax::feature_gate::check_crate(sess.codemap(),
+        let features =
+            syntax::feature_gate::check_crate(sess.codemap(),
                                           &sess.parse_sess.span_diagnostic,
                                           &krate);
+        *sess.features.borrow_mut() = features;
         sess.abort_if_errors();
     });
 
@@ -564,7 +561,6 @@ pub fn phase_3_run_analysis_passes<'tcx>(sess: Session,
     let resolve::CrateMap {
         def_map,
         freevars,
-        capture_mode_map,
         export_map,
         trait_map,
         external_exports,
@@ -599,7 +595,7 @@ pub fn phase_3_run_analysis_passes<'tcx>(sess: Session,
          middle::check_loop::check_crate(&sess, krate));
 
     let stability_index = time(time_passes, "stability index", (), |_|
-                               stability::Index::build(krate));
+                               stability::Index::build(&sess, krate));
 
     time(time_passes, "static item recursion checking", (), |_|
          middle::check_static_recursion::check_crate(&sess, krate, &def_map, &ast_map));
@@ -610,7 +606,6 @@ pub fn phase_3_run_analysis_passes<'tcx>(sess: Session,
                             named_region_map,
                             ast_map,
                             freevars,
-                            capture_mode_map,
                             region_map,
                             lang_items,
                             stability_index);
@@ -668,9 +663,20 @@ pub fn phase_3_run_analysis_passes<'tcx>(sess: Session,
                                   &reachable_map)
     });
 
+    let ref lib_features_used =
+        time(time_passes, "stability checking", (), |_|
+             stability::check_unstable_api_usage(&ty_cx));
+
+    time(time_passes, "unused feature checking", (), |_|
+         stability::check_unused_features(
+             &ty_cx.sess, lib_features_used));
+
     time(time_passes, "lint checking", (), |_|
          lint::check_crate(&ty_cx, &exported_items));
 
+    // The above three passes generate errors w/o aborting
+    ty_cx.sess.abort_if_errors();
+
     ty::CrateAnalysis {
         export_map: export_map,
         ty_cx: ty_cx,
@@ -729,10 +735,10 @@ pub fn phase_5_run_llvm_passes(sess: &Session,
 pub fn phase_6_link_output(sess: &Session,
                            trans: &trans::CrateTranslation,
                            outputs: &OutputFilenames) {
-    let old_path = os::getenv("PATH").unwrap_or_else(||String::new());
+    let old_path = env::var("PATH").unwrap_or(OsString::from_str(""));
     let mut new_path = sess.host_filesearch(PathKind::All).get_tools_search_paths();
-    new_path.extend(os::split_paths(&old_path[]).into_iter());
-    os::setenv("PATH", os::join_paths(&new_path[]).unwrap());
+    new_path.extend(env::split_paths(&old_path));
+    env::set_var("PATH", &env::join_paths(new_path.iter()).unwrap());
 
     time(sess.time_passes(), "linking", (), |_|
          link::link_binary(sess,
@@ -740,7 +746,7 @@ pub fn phase_6_link_output(sess: &Session,
                            outputs,
                            &trans.link.crate_name[]));
 
-    os::setenv("PATH", old_path);
+    env::set_var("PATH", &old_path);
 }
 
 fn escape_dep_filename(filename: &str) -> String {
@@ -755,11 +761,11 @@ fn write_out_deps(sess: &Session,
                   id: &str) {
 
     let mut out_filenames = Vec::new();
-    for output_type in sess.opts.output_types.iter() {
+    for output_type in &sess.opts.output_types {
         let file = outputs.path(*output_type);
         match *output_type {
             config::OutputTypeExe => {
-                for output in sess.crate_types.borrow().iter() {
+                for output in &*sess.crate_types.borrow() {
                     let p = link::filename_for_input(sess, *output,
                                                      id, &file);
                     out_filenames.push(p);
@@ -795,7 +801,7 @@ fn write_out_deps(sess: &Session,
                                    .map(|fmap| escape_dep_filename(&fmap.name[]))
                                    .collect();
         let mut file = try!(old_io::File::create(&deps_filename));
-        for path in out_filenames.iter() {
+        for path in &out_filenames {
             try!(write!(&mut file as &mut Writer,
                           "{}: {}\n\n", path.display(), files.connect(" ")));
         }
@@ -875,7 +881,7 @@ pub fn collect_crate_types(session: &Session,
         let res = !link::invalid_output_for_target(session, *crate_type);
 
         if !res {
-            session.warn(&format!("dropping unsupported crate type `{:?}` \
+            session.warn(&format!("dropping unsupported crate type `{}` \
                                    for target `{}`",
                                  *crate_type, session.opts.target_triple)[]);
         }