about summary refs log tree commit diff
path: root/src/librustc_driver
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2017-08-14 19:36:13 -0700
committerAlex Crichton <alex@alexcrichton.com>2017-08-14 19:36:13 -0700
commit1413253a41de87ce7da73f0733aa3f433b1f5a3b (patch)
tree111cba46a53aaaa0733b6b8ba19aece25b6f8533 /src/librustc_driver
parentb045c201b2086073f43d76290b9cb2a5a8e16f89 (diff)
parent56fe3b2ad0055bb28325f412395577e2b842719a (diff)
downloadrust-1413253a41de87ce7da73f0733aa3f433b1f5a3b.tar.gz
rust-1413253a41de87ce7da73f0733aa3f433b1f5a3b.zip
Merge remote-tracking branch 'origin/master' into gen
Diffstat (limited to 'src/librustc_driver')
-rw-r--r--src/librustc_driver/driver.rs66
-rw-r--r--src/librustc_driver/lib.rs147
-rw-r--r--src/librustc_driver/pretty.rs64
-rw-r--r--src/librustc_driver/test.rs2
4 files changed, 149 insertions, 130 deletions
diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs
index 7efa2846cd6..6c673b2ea23 100644
--- a/src/librustc_driver/driver.rs
+++ b/src/librustc_driver/driver.rs
@@ -8,6 +8,8 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+#![cfg_attr(not(feature="llvm"), allow(dead_code))]
+
 use rustc::hir::{self, map as hir_map};
 use rustc::hir::lowering::lower_crate;
 use rustc::ich::Fingerprint;
@@ -19,8 +21,6 @@ use rustc::session::config::{self, Input, OutputFilenames, OutputType};
 use rustc::session::search_paths::PathKind;
 use rustc::lint;
 use rustc::middle::{self, stability, reachable};
-#[cfg(feature="llvm")]
-use rustc::middle::dependency_format;
 use rustc::middle::privacy::AccessLevels;
 use rustc::mir::transform::{MIR_CONST, MIR_VALIDATED, MIR_OPTIMIZED, Passes};
 use rustc::ty::{self, TyCtxt, Resolutions, GlobalArenas};
@@ -33,9 +33,7 @@ use rustc_incremental::{self, IncrementalHashesMap};
 use rustc_resolve::{MakeGlobMap, Resolver};
 use rustc_metadata::creader::CrateLoader;
 use rustc_metadata::cstore::{self, CStore};
-#[cfg(feature="llvm")]
-use rustc_trans::back::{link, write};
-#[cfg(feature="llvm")]
+use rustc_trans::back::write;
 use rustc_trans as trans;
 use rustc_typeck as typeck;
 use rustc_privacy;
@@ -73,11 +71,7 @@ pub fn compile_input(sess: &Session,
                      output: &Option<PathBuf>,
                      addl_plugins: Option<Vec<String>>,
                      control: &CompileController) -> CompileResult {
-    #[cfg(feature="llvm")]
     use rustc_trans::back::write::OngoingCrateTranslation;
-    #[cfg(not(feature="llvm"))]
-    type OngoingCrateTranslation = ();
-
     macro_rules! controller_entry_point {
         ($point: ident, $tsess: expr, $make_state: expr, $phase_result: expr) => {{
             let state = &mut $make_state;
@@ -94,6 +88,23 @@ pub fn compile_input(sess: &Session,
         }}
     }
 
+    if cfg!(not(feature="llvm")) {
+        use rustc::session::config::CrateType;
+        if !sess.opts.debugging_opts.no_trans && sess.opts.output_types.should_trans() {
+            sess.err("LLVM is not supported by this rustc. Please use -Z no-trans to compile")
+        }
+
+        if sess.opts.crate_types.iter().all(|&t|{
+            t != CrateType::CrateTypeRlib && t != CrateType::CrateTypeExecutable
+        }) && !sess.opts.crate_types.is_empty() {
+            sess.err(
+                "LLVM is not supported by this rustc, so non rlib libraries are not supported"
+            );
+        }
+
+        sess.abort_if_errors();
+    }
+
     // We need nested scopes here, because the intermediate results can keep
     // large chunks of memory alive and we want to free them as soon as
     // possible to keep the peak memory usage low
@@ -217,7 +228,6 @@ pub fn compile_input(sess: &Session,
                 tcx.print_debug_stats();
             }
 
-            #[cfg(feature="llvm")]
             let trans = phase_4_translate_to_llvm(tcx, analysis, incremental_hashes_map,
                                                   &outputs);
 
@@ -233,24 +243,13 @@ pub fn compile_input(sess: &Session,
                 }
             }
 
-            #[cfg(not(feature="llvm"))]
-            {
-                let _ = incremental_hashes_map;
-                sess.err(&format!("LLVM is not supported by this rustc"));
-                sess.abort_if_errors();
-                unreachable!();
-            }
-
-            #[cfg(feature="llvm")]
             Ok((outputs, trans))
         })??
     };
 
-    #[cfg(not(feature="llvm"))]
-    {
-        let _ = outputs;
-        let _ = trans;
-        unreachable!();
+    if cfg!(not(feature="llvm")) {
+        let (_, _) = (outputs, trans);
+        sess.fatal("LLVM is not supported by this rustc");
     }
 
     #[cfg(feature="llvm")]
@@ -315,7 +314,7 @@ pub fn source_name(input: &Input) -> String {
 /// This is a somewhat higher level controller than a Session - the Session
 /// controls what happens in each phase, whereas the CompileController controls
 /// whether a phase is run at all and whether other code (from outside the
-/// the compiler) is run between phases.
+/// compiler) is run between phases.
 ///
 /// Note that if compilation is set to stop and a callback is provided for a
 /// given entry point, the callback is called before compilation is stopped.
@@ -393,7 +392,6 @@ pub struct CompileState<'a, 'tcx: 'a> {
     pub resolutions: Option<&'a Resolutions>,
     pub analysis: Option<&'a ty::CrateAnalysis>,
     pub tcx: Option<TyCtxt<'a, 'tcx, 'tcx>>,
-    #[cfg(feature="llvm")]
     pub trans: Option<&'a trans::CrateTranslation>,
 }
 
@@ -420,7 +418,6 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
             resolutions: None,
             analysis: None,
             tcx: None,
-            #[cfg(feature="llvm")]
             trans: None,
         }
     }
@@ -509,7 +506,6 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
         }
     }
 
-    #[cfg(feature="llvm")]
     fn state_after_llvm(input: &'a Input,
                         session: &'tcx Session,
                         out_dir: &'a Option<PathBuf>,
@@ -523,7 +519,6 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
         }
     }
 
-    #[cfg(feature="llvm")]
     fn state_when_compilation_done(input: &'a Input,
                                    session: &'tcx Session,
                                    out_dir: &'a Option<PathBuf>,
@@ -942,7 +937,6 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
     mir::provide(&mut local_providers);
     reachable::provide(&mut local_providers);
     rustc_privacy::provide(&mut local_providers);
-    #[cfg(feature="llvm")]
     trans::provide(&mut local_providers);
     typeck::provide(&mut local_providers);
     ty::provide(&mut local_providers);
@@ -955,7 +949,6 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
 
     let mut extern_providers = ty::maps::Providers::default();
     cstore::provide(&mut extern_providers);
-    #[cfg(feature="llvm")]
     trans::provide(&mut extern_providers);
     ty::provide_extern(&mut extern_providers);
     traits::provide_extern(&mut extern_providers);
@@ -974,7 +967,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
     passes.push_pass(MIR_CONST, mir::transform::type_check::TypeckMir);
     passes.push_pass(MIR_CONST, mir::transform::rustc_peek::SanityCheck);
 
-    // We compute "constant qualifications" betwen MIR_CONST and MIR_VALIDATED.
+    // We compute "constant qualifications" between MIR_CONST and MIR_VALIDATED.
 
     // What we need to run borrowck etc.
     passes.push_pass(MIR_VALIDATED, mir::transform::qualify_consts::QualifyAndPromoteConstants);
@@ -1104,7 +1097,6 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
 
 /// Run the translation phase to LLVM, after which the AST and analysis can
 /// be discarded.
-#[cfg(feature="llvm")]
 pub fn phase_4_translate_to_llvm<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
                                            analysis: ty::CrateAnalysis,
                                            incremental_hashes_map: IncrementalHashesMap,
@@ -1114,7 +1106,7 @@ pub fn phase_4_translate_to_llvm<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
 
     time(time_passes,
          "resolving dependency formats",
-         || dependency_format::calculate(tcx));
+         || ::rustc::middle::dependency_format::calculate(tcx));
 
     let translation =
         time(time_passes,
@@ -1149,9 +1141,9 @@ pub fn phase_5_run_llvm_passes(sess: &Session,
 pub fn phase_6_link_output(sess: &Session,
                            trans: &trans::CrateTranslation,
                            outputs: &OutputFilenames) {
-    time(sess.time_passes(),
-         "linking",
-         || link::link_binary(sess, trans, outputs, &trans.crate_name.as_str()));
+    time(sess.time_passes(), "linking", || {
+        ::rustc_trans::back::link::link_binary(sess, trans, outputs, &trans.crate_name.as_str())
+    });
 }
 
 fn escape_dep_filename(filename: &str) -> String {
diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs
index 91ba7ed1958..f8cd2280caf 100644
--- a/src/librustc_driver/lib.rs
+++ b/src/librustc_driver/lib.rs
@@ -28,15 +28,10 @@
 #![feature(rustc_diagnostic_macros)]
 #![feature(set_stdio)]
 
-#[cfg(not(feature="llvm"))]
-extern crate ar;
-
 extern crate arena;
 extern crate getopts;
 extern crate graphviz;
 extern crate env_logger;
-#[cfg(not(feature="llvm"))]
-extern crate owning_ref;
 extern crate libc;
 extern crate rustc;
 extern crate rustc_allocator;
@@ -71,8 +66,6 @@ use pretty::{PpMode, UserIdentifiedItem};
 use rustc_resolve as resolve;
 use rustc_save_analysis as save;
 use rustc_save_analysis::DumpHandler;
-#[cfg(feature="llvm")]
-use rustc_trans::back::write::{RELOC_MODEL_ARGS, CODE_GEN_MODEL_ARGS};
 use rustc::dep_graph::DepGraph;
 use rustc::session::{self, config, Session, build_session, CompileResult};
 use rustc::session::CompileIncomplete;
@@ -81,13 +74,9 @@ use rustc::session::config::nightly_options;
 use rustc::session::{early_error, early_warn};
 use rustc::lint::Lint;
 use rustc::lint;
-#[cfg(not(feature="llvm"))]
-use rustc::middle::cstore::MetadataLoader as MetadataLoaderTrait;
 use rustc_metadata::locator;
 use rustc_metadata::cstore::CStore;
 use rustc::util::common::{time, ErrorReported};
-#[cfg(not(feature="llvm"))]
-use rustc_back::target::Target;
 
 use serialize::json::ToJson;
 
@@ -100,8 +89,6 @@ use std::ffi::OsString;
 use std::io::{self, Read, Write};
 use std::iter::repeat;
 use std::path::PathBuf;
-#[cfg(not(feature="llvm"))]
-use std::path::Path;
 use std::process::{self, Command, Stdio};
 use std::rc::Rc;
 use std::str;
@@ -114,15 +101,11 @@ use syntax::feature_gate::{GatedCfg, UnstableFeatures};
 use syntax::parse::{self, PResult};
 use syntax_pos::{DUMMY_SP, MultiSpan};
 
-#[cfg(not(feature="llvm"))]
-use owning_ref::{OwningRef, ErasedBoxRef};
-
 #[cfg(test)]
 pub mod test;
 
 pub mod driver;
 pub mod pretty;
-#[cfg(feature="llvm")]
 pub mod target_features;
 mod derive_registrar;
 
@@ -169,48 +152,106 @@ pub fn run<F>(run_compiler: F) -> isize
 }
 
 #[cfg(not(feature="llvm"))]
-pub struct NoLLvmMetadataLoader;
-
-#[cfg(not(feature="llvm"))]
-pub use NoLLvmMetadataLoader as MetadataLoader;
+pub use no_llvm_metadata_loader::NoLLvmMetadataLoader as MetadataLoader;
 #[cfg(feature="llvm")]
 pub use rustc_trans::LlvmMetadataLoader as MetadataLoader;
 
 #[cfg(not(feature="llvm"))]
-impl MetadataLoaderTrait for NoLLvmMetadataLoader {
-    fn get_rlib_metadata(&self, _: &Target, filename: &Path) -> Result<ErasedBoxRef<[u8]>, String> {
-        use std::fs::File;
-        use std::io;
-        use self::ar::Archive;
-
-        let file = File::open(filename).map_err(|e|format!("metadata file open err: {:?}", e))?;
-        let mut archive = Archive::new(file);
-
-        while let Some(entry_result) = archive.next_entry() {
-            let mut entry = entry_result.map_err(|e|format!("metadata section read err: {:?}", e))?;
-            if entry.header().identifier() == "rust.metadata.bin" {
-                let mut buf = Vec::new();
-                io::copy(&mut entry, &mut buf).unwrap();
-                let buf: OwningRef<Vec<u8>, [u8]> = OwningRef::new(buf).into();
-                return Ok(buf.map_owner_box().erase_owner());
+mod no_llvm_metadata_loader {
+    extern crate ar;
+    extern crate owning_ref;
+
+    use rustc::middle::cstore::MetadataLoader as MetadataLoaderTrait;
+    use rustc_back::target::Target;
+    use std::io;
+    use std::fs::File;
+    use std::path::Path;
+
+    use self::ar::Archive;
+    use self::owning_ref::{OwningRef, ErasedBoxRef};
+
+    pub struct NoLLvmMetadataLoader;
+
+    impl MetadataLoaderTrait for NoLLvmMetadataLoader {
+        fn get_rlib_metadata(
+            &self,
+            _: &Target,
+            filename: &Path
+        ) -> Result<ErasedBoxRef<[u8]>, String> {
+            let file = File::open(filename).map_err(|e| {
+                format!("metadata file open err: {:?}", e)
+            })?;
+            let mut archive = Archive::new(file);
+
+            while let Some(entry_result) = archive.next_entry() {
+                let mut entry = entry_result.map_err(|e| {
+                    format!("metadata section read err: {:?}", e)
+                })?;
+                if entry.header().identifier() == "rust.metadata.bin" {
+                    let mut buf = Vec::new();
+                    io::copy(&mut entry, &mut buf).unwrap();
+                    let buf: OwningRef<Vec<u8>, [u8]> = OwningRef::new(buf).into();
+                    return Ok(buf.map_owner_box().erase_owner());
+                }
             }
+
+            Err("Couldnt find metadata section".to_string())
         }
 
-        Err("Couldnt find metadata section".to_string())
+        fn get_dylib_metadata(&self,
+                            _target: &Target,
+                            _filename: &Path)
+                            -> Result<ErasedBoxRef<[u8]>, String> {
+            panic!("Dylib metadata loading not supported without LLVM")
+        }
     }
+}
 
-    fn get_dylib_metadata(&self,
-                          _target: &Target,
-                          _filename: &Path)
-                          -> Result<ErasedBoxRef<[u8]>, String> {
-        panic!("Dylib metadata loading not supported without LLVM")
+#[cfg(not(feature="llvm"))]
+mod rustc_trans {
+    use syntax_pos::symbol::Symbol;
+    use rustc::session::Session;
+    use rustc::session::config::{PrintRequest, OutputFilenames};
+    use rustc::ty::{TyCtxt, CrateAnalysis};
+    use rustc::ty::maps::Providers;
+    use rustc_incremental::IncrementalHashesMap;
+
+    use self::back::write::OngoingCrateTranslation;
+
+    pub fn init(_sess: &Session) {}
+    pub fn enable_llvm_debug() {}
+    pub fn provide(_providers: &mut Providers) {}
+    pub fn print_version() {}
+    pub fn print_passes() {}
+    pub fn print(_req: PrintRequest, _sess: &Session) {}
+    pub fn target_features(_sess: &Session) -> Vec<Symbol> { vec![] }
+
+    pub fn trans_crate<'a, 'tcx>(
+        _tcx: TyCtxt<'a, 'tcx, 'tcx>,
+        _analysis: CrateAnalysis,
+        _incr_hashes_map: IncrementalHashesMap,
+        _output_filenames: &OutputFilenames
+    ) -> OngoingCrateTranslation {
+        OngoingCrateTranslation(())
     }
+
+    pub struct CrateTranslation(());
+
+    pub mod back {
+        pub mod write {
+            pub struct OngoingCrateTranslation(pub (in ::rustc_trans) ());
+
+            pub const RELOC_MODEL_ARGS: [(&'static str, ()); 0] = [];
+            pub const CODE_GEN_MODEL_ARGS: [(&'static str, ()); 0] = [];
+        }
+    }
+
+    __build_diagnostic_array! { librustc_trans, DIAGNOSTICS }
 }
 
 // Parse args and run the compiler. This is the primary entry point for rustc.
 // See comments on CompilerCalls below for details about the callbacks argument.
 // The FileLoader provides a way to load files from sources other than the file system.
-#[cfg_attr(not(feature="llvm"), allow(unused_mut))]
 pub fn run_compiler<'a>(args: &[String],
                         callbacks: &mut CompilerCalls<'a>,
                         file_loader: Option<Box<FileLoader + 'static>>,
@@ -232,7 +273,6 @@ pub fn run_compiler<'a>(args: &[String],
     let (sopts, cfg) = config::build_session_options_and_crate_config(&matches);
 
     if sopts.debugging_opts.debug_llvm {
-        #[cfg(feature="llvm")]
         rustc_trans::enable_llvm_debug();
     }
 
@@ -262,12 +302,10 @@ pub fn run_compiler<'a>(args: &[String],
     let mut sess = session::build_session_with_codemap(
         sopts, &dep_graph, input_file_path, descriptions, cstore.clone(), codemap, emitter_dest,
     );
-    #[cfg(feature="llvm")]
     rustc_trans::init(&sess);
     rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
 
     let mut cfg = config::build_configuration(&sess, cfg);
-    #[cfg(feature="llvm")]
     target_features::add_configuration(&mut cfg, &sess);
     sess.parse_sess.config = cfg;
 
@@ -520,7 +558,6 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
         Compilation::Continue
     }
 
-    #[cfg_attr(not(feature="llvm"), allow(unused_mut))]
     fn no_input(&mut self,
                 matches: &getopts::Matches,
                 sopts: &config::Options,
@@ -544,11 +581,9 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
                     None,
                     descriptions.clone(),
                     cstore.clone());
-                #[cfg(feature="llvm")]
                 rustc_trans::init(&sess);
                 rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
                 let mut cfg = config::build_configuration(&sess, cfg.clone());
-                #[cfg(feature="llvm")]
                 target_features::add_configuration(&mut cfg, &sess);
                 sess.parse_sess.config = cfg;
                 let should_stop =
@@ -802,25 +837,20 @@ impl RustcDefaultCalls {
                 }
                 PrintRequest::RelocationModels => {
                     println!("Available relocation models:");
-                    #[cfg(feature="llvm")]
-                    for &(name, _) in RELOC_MODEL_ARGS.iter() {
+                    for &(name, _) in rustc_trans::back::write::RELOC_MODEL_ARGS.iter() {
                         println!("    {}", name);
                     }
                     println!("");
                 }
                 PrintRequest::CodeModels => {
                     println!("Available code models:");
-                    #[cfg(feature="llvm")]
-                    for &(name, _) in CODE_GEN_MODEL_ARGS.iter(){
+                    for &(name, _) in rustc_trans::back::write::CODE_GEN_MODEL_ARGS.iter(){
                         println!("    {}", name);
                     }
                     println!("");
                 }
                 PrintRequest::TargetCPUs | PrintRequest::TargetFeatures => {
-                    #[cfg(feature="llvm")]
                     rustc_trans::print(*req, sess);
-                    #[cfg(not(feature="llvm"))]
-                    panic!("LLVM not supported by this rustc")
                 }
             }
         }
@@ -859,7 +889,6 @@ pub fn version(binary: &str, matches: &getopts::Matches) {
         println!("commit-date: {}", unw(commit_date_str()));
         println!("host: {}", config::host_triple());
         println!("release: {}", unw(release_str()));
-        #[cfg(feature="llvm")]
         rustc_trans::print_version();
     }
 }
@@ -1157,7 +1186,6 @@ pub fn handle_options(args: &[String]) -> Option<getopts::Matches> {
     }
 
     if cg_flags.contains(&"passes=list".to_string()) {
-        #[cfg(feature="llvm")]
         rustc_trans::print_passes();
         return None;
     }
@@ -1285,7 +1313,6 @@ pub fn diagnostics_registry() -> errors::registry::Registry {
     all_errors.extend_from_slice(&rustc_borrowck::DIAGNOSTICS);
     all_errors.extend_from_slice(&rustc_resolve::DIAGNOSTICS);
     all_errors.extend_from_slice(&rustc_privacy::DIAGNOSTICS);
-    #[cfg(feature="llvm")]
     all_errors.extend_from_slice(&rustc_trans::DIAGNOSTICS);
     all_errors.extend_from_slice(&rustc_const_eval::DIAGNOSTICS);
     all_errors.extend_from_slice(&rustc_metadata::DIAGNOSTICS);
diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs
index 269363fdd2f..84d3ab65b1c 100644
--- a/src/librustc_driver/pretty.rs
+++ b/src/librustc_driver/pretty.rs
@@ -44,6 +44,7 @@ use std::io::{self, Write};
 use std::option;
 use std::path::Path;
 use std::str::FromStr;
+use std::mem;
 
 use rustc::hir::map as hir_map;
 use rustc::hir::map::blocks;
@@ -232,7 +233,7 @@ impl PpSourceMode {
                                                                  arenas,
                                                                  id,
                                                                  |tcx, _, _, _| {
-                    let empty_tables = ty::TypeckTables::empty();
+                    let empty_tables = ty::TypeckTables::empty(None);
                     let annotation = TypedAnnotation {
                         tcx: tcx,
                         tables: Cell::new(&empty_tables)
@@ -618,52 +619,53 @@ impl UserIdentifiedItem {
     }
 }
 
-struct ReplaceBodyWithLoop {
+// Note: Also used by librustdoc, see PR #43348. Consider moving this struct elsewhere.
+pub struct ReplaceBodyWithLoop {
     within_static_or_const: bool,
 }
 
 impl ReplaceBodyWithLoop {
-    fn new() -> ReplaceBodyWithLoop {
+    pub fn new() -> ReplaceBodyWithLoop {
         ReplaceBodyWithLoop { within_static_or_const: false }
     }
+
+    fn run<R, F: FnOnce(&mut Self) -> R>(&mut self, is_const: bool, action: F) -> R {
+        let old_const = mem::replace(&mut self.within_static_or_const, is_const);
+        let ret = action(self);
+        self.within_static_or_const = old_const;
+        ret
+    }
 }
 
 impl fold::Folder for ReplaceBodyWithLoop {
     fn fold_item_kind(&mut self, i: ast::ItemKind) -> ast::ItemKind {
-        match i {
-            ast::ItemKind::Static(..) |
-            ast::ItemKind::Const(..) => {
-                self.within_static_or_const = true;
-                let ret = fold::noop_fold_item_kind(i, self);
-                self.within_static_or_const = false;
-                return ret;
-            }
-            _ => fold::noop_fold_item_kind(i, self),
-        }
+        let is_const = match i {
+            ast::ItemKind::Static(..) | ast::ItemKind::Const(..) => true,
+            ast::ItemKind::Fn(_, _, ref constness, _, _, _) =>
+                constness.node == ast::Constness::Const,
+            _ => false,
+        };
+        self.run(is_const, |s| fold::noop_fold_item_kind(i, s))
     }
 
     fn fold_trait_item(&mut self, i: ast::TraitItem) -> SmallVector<ast::TraitItem> {
-        match i.node {
-            ast::TraitItemKind::Const(..) => {
-                self.within_static_or_const = true;
-                let ret = fold::noop_fold_trait_item(i, self);
-                self.within_static_or_const = false;
-                return ret;
-            }
-            _ => fold::noop_fold_trait_item(i, self),
-        }
+        let is_const = match i.node {
+            ast::TraitItemKind::Const(..) => true,
+            ast::TraitItemKind::Method(ast::MethodSig { ref constness, .. }, _) =>
+                constness.node == ast::Constness::Const,
+            _ => false,
+        };
+        self.run(is_const, |s| fold::noop_fold_trait_item(i, s))
     }
 
     fn fold_impl_item(&mut self, i: ast::ImplItem) -> SmallVector<ast::ImplItem> {
-        match i.node {
-            ast::ImplItemKind::Const(..) => {
-                self.within_static_or_const = true;
-                let ret = fold::noop_fold_impl_item(i, self);
-                self.within_static_or_const = false;
-                return ret;
-            }
-            _ => fold::noop_fold_impl_item(i, self),
-        }
+        let is_const = match i.node {
+            ast::ImplItemKind::Const(..) => true,
+            ast::ImplItemKind::Method(ast::MethodSig { ref constness, .. }, _) =>
+                constness.node == ast::Constness::Const,
+            _ => false,
+        };
+        self.run(is_const, |s| fold::noop_fold_impl_item(i, s))
     }
 
     fn fold_block(&mut self, b: P<ast::Block>) -> P<ast::Block> {
diff --git a/src/librustc_driver/test.rs b/src/librustc_driver/test.rs
index 7f65a8b97cd..b187cdaa480 100644
--- a/src/librustc_driver/test.rs
+++ b/src/librustc_driver/test.rs
@@ -14,7 +14,6 @@ use driver;
 use rustc::dep_graph::DepGraph;
 use rustc_lint;
 use rustc_resolve::MakeGlobMap;
-#[cfg(feature="llvm")]
 use rustc_trans;
 use rustc::middle::lang_items;
 use rustc::middle::free_region::FreeRegionMap;
@@ -114,7 +113,6 @@ fn test_env<F>(source_string: &str,
                                        diagnostic_handler,
                                        Rc::new(CodeMap::new(FilePathMapping::empty())),
                                        cstore.clone());
-    #[cfg(feature="llvm")]
     rustc_trans::init(&sess);
     rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
     let input = config::Input::Str {