Skip to content

Commit

Permalink
Fix fallout in librustdoc and in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jseyfried committed May 9, 2016
1 parent abec20b commit 805666a
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 23 deletions.
23 changes: 12 additions & 11 deletions src/librustc_driver/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use driver;
use rustc::dep_graph::DepGraph;
use rustc_lint;
use rustc_resolve as resolve;
use rustc_resolve::MakeGlobMap;
use rustc::middle::lang_items;
use rustc::middle::free_region::FreeRegionMap;
use rustc::middle::region::{self, CodeExtent};
Expand All @@ -40,7 +40,6 @@ use syntax::errors::{Level, RenderSpan};
use syntax::parse::token;
use syntax::feature_gate::UnstableFeatures;

use rustc::hir::lowering::{lower_crate, LoweringContext};
use rustc::hir;

struct Env<'a, 'tcx: 'a> {
Expand Down Expand Up @@ -123,26 +122,28 @@ fn test_env<F>(source_string: &str,
let krate = driver::assign_node_ids(&sess, krate);
let defs = &RefCell::new(hir_map::collect_definitions(&krate));
LocalCrateReader::new(&sess, &cstore, defs, &krate, "test_crate").read_crates(&dep_graph);
let lcx = LoweringContext::new(&sess, Some(&krate), defs);
let _ignore = dep_graph.in_ignore();
let mut hir_forest = &mut hir_map::Forest::new(lower_crate(&lcx, &krate), dep_graph.clone());

let (_, resolutions, mut hir_forest) = {
let (defs, dep_graph) = (&mut *defs.borrow_mut(), dep_graph.clone());
driver::lower_and_resolve(&sess, "test-crate", defs, &krate, dep_graph, MakeGlobMap::No)
};

let arenas = ty::CtxtArenas::new();
let ast_map = hir_map::map_crate(hir_forest, defs);
let ast_map = hir_map::map_crate(&mut hir_forest, defs);

// run just enough stuff to build a tcx:
let lang_items = lang_items::collect_language_items(&sess, &ast_map);
let resolve::CrateMap { def_map, freevars, maybe_unused_trait_imports, .. } =
resolve::resolve_crate(&sess, &ast_map, resolve::MakeGlobMap::No);
let named_region_map = resolve_lifetime::krate(&sess, &ast_map, &def_map.borrow());
let named_region_map = resolve_lifetime::krate(&sess, &ast_map, &resolutions.def_map.borrow());
let region_map = region::resolve_crate(&sess, &ast_map);
let index = stability::Index::new(&ast_map);
TyCtxt::create_and_enter(&sess,
&arenas,
def_map,
resolutions.def_map,
named_region_map.unwrap(),
ast_map,
freevars,
maybe_unused_trait_imports,
resolutions.freevars,
resolutions.maybe_unused_trait_imports,
region_map,
lang_items,
index,
Expand Down
13 changes: 8 additions & 5 deletions src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use rustc::hir::map as hir_map;
use rustc::lint;
use rustc_trans::back::link;
use rustc_resolve as resolve;
use rustc::hir::lowering::{lower_crate, LoweringContext};
use rustc_metadata::cstore::CStore;
use rustc_metadata::creader::LocalCrateReader;

Expand Down Expand Up @@ -156,18 +155,22 @@ pub fn run_core(search_paths: SearchPaths,

let defs = &RefCell::new(hir_map::collect_definitions(&krate));
LocalCrateReader::new(&sess, &cstore, &defs, &krate, &name).read_crates(&dep_graph);
let lcx = LoweringContext::new(&sess, Some(&krate), defs);

// Lower ast -> hir.
let mut hir_forest = hir_map::Forest::new(lower_crate(&lcx, &krate), dep_graph);
// Lower ast -> hir and resolve.
let (analysis, resolutions, mut hir_forest) = {
let defs = &mut *defs.borrow_mut();
driver::lower_and_resolve(&sess, &name, defs, &krate, dep_graph, resolve::MakeGlobMap::No)
};

let arenas = ty::CtxtArenas::new();
let hir_map = hir_map::map_crate(&mut hir_forest, defs);

abort_on_err(driver::phase_3_run_analysis_passes(&sess,
hir_map,
analysis,
resolutions,
&arenas,
&name,
resolve::MakeGlobMap::No,
|tcx, _, analysis, result| {
// Return if the driver hit an err (in `result`)
if let Err(_) = result {
Expand Down
5 changes: 3 additions & 2 deletions src/librustdoc/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use rustc::hir::map as hir_map;
use rustc::session::{self, config};
use rustc::session::config::{get_unstable_features_setting, OutputType};
use rustc::session::search_paths::{SearchPaths, PathKind};
use rustc::hir::lowering::{lower_crate, LoweringContext};
use rustc::hir::lowering::{lower_crate, LoweringContext, DummyResolver};
use rustc_back::dynamic_lib::DynamicLibrary;
use rustc_back::tempdir::TempDir;
use rustc_driver::{driver, Compilation};
Expand Down Expand Up @@ -97,7 +97,8 @@ pub fn run(input: &str,
let dep_graph = DepGraph::new(false);
let defs = &RefCell::new(hir_map::collect_definitions(&krate));

let lcx = LoweringContext::new(&sess, Some(&krate), defs);
let mut dummy_resolver = DummyResolver;
let lcx = LoweringContext::new(&sess, Some(&krate), &mut dummy_resolver);
let krate = lower_crate(&lcx, &krate);

let opts = scrape_test_config(&krate);
Expand Down
11 changes: 6 additions & 5 deletions src/test/run-make/execution-engine/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ use rustc::ty;
use rustc::session::config::{self, basic_options, build_configuration, Input, Options};
use rustc::session::build_session;
use rustc_driver::{driver, abort_on_err};
use rustc::hir::lowering::{lower_crate, LoweringContext};
use rustc_resolve::MakeGlobMap;
use rustc_metadata::creader::LocalCrateReader;
use rustc_metadata::cstore::CStore;
Expand Down Expand Up @@ -243,14 +242,16 @@ fn compile_program(input: &str, sysroot: PathBuf)
let krate = driver::assign_node_ids(&sess, krate);
let defs = RefCell::new(ast_map::collect_definitions(&krate));
LocalCrateReader::new(&sess, &cstore, &defs, &krate, &id).read_crates(&dep_graph);
let lcx = LoweringContext::new(&sess, Some(&krate), &defs);
let mut hir_forest = ast_map::Forest::new(lower_crate(&lcx, &krate), dep_graph);
let (analysis, resolutions, mut hir_forest) = {
let defs = &mut *defs.borrow_mut();
driver::lower_and_resolve(&sess, &id, defs, &krate, dep_graph, MakeGlobMap::No)
};
let arenas = ty::CtxtArenas::new();
let ast_map = ast_map::map_crate(&mut hir_forest, &defs);

abort_on_err(driver::phase_3_run_analysis_passes(
&sess, ast_map, &arenas, &id,
MakeGlobMap::No, |tcx, mir_map, analysis, _| {
&sess, ast_map, analysis, resolutions, &arenas, &id,
|tcx, mir_map, analysis, _| {

let trans = driver::phase_4_translate_to_llvm(tcx, mir_map.unwrap(), analysis);

Expand Down
2 changes: 2 additions & 0 deletions src/test/run-make/pretty-expanded-hygiene/input.pp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@


fn bar /* 62#0 */() { let x /* 59#2 */ = 1; y /* 61#4 */ + x /* 59#5 */ }

fn y /* 61#0 */() { }
2 changes: 2 additions & 0 deletions src/test/run-make/pretty-expanded-hygiene/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ fn bar() {
let x = 1;
foo!(x)
}

fn y() {}

0 comments on commit 805666a

Please sign in to comment.