From 805666a4d283b60f9f4b979b53b3d498cd876f2e Mon Sep 17 00:00:00 2001 From: Jeffrey Seyfried Date: Sun, 8 May 2016 04:18:55 +0000 Subject: [PATCH] Fix fallout in `librustdoc` and in tests --- src/librustc_driver/test.rs | 23 ++++++++++--------- src/librustdoc/core.rs | 13 +++++++---- src/librustdoc/test.rs | 5 ++-- src/test/run-make/execution-engine/test.rs | 11 +++++---- .../pretty-expanded-hygiene/input.pp.rs | 2 ++ .../run-make/pretty-expanded-hygiene/input.rs | 2 ++ 6 files changed, 33 insertions(+), 23 deletions(-) diff --git a/src/librustc_driver/test.rs b/src/librustc_driver/test.rs index d546db086b588..869bbb723ef41 100644 --- a/src/librustc_driver/test.rs +++ b/src/librustc_driver/test.rs @@ -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}; @@ -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> { @@ -123,26 +122,28 @@ fn test_env(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, diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 0b3a0c19dacc4..e5fc84037ce57 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -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; @@ -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 { diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index 81fd1128afac8..fc548924e2964 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -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}; @@ -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); diff --git a/src/test/run-make/execution-engine/test.rs b/src/test/run-make/execution-engine/test.rs index b9a45c09626a7..98412c08df520 100644 --- a/src/test/run-make/execution-engine/test.rs +++ b/src/test/run-make/execution-engine/test.rs @@ -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; @@ -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); diff --git a/src/test/run-make/pretty-expanded-hygiene/input.pp.rs b/src/test/run-make/pretty-expanded-hygiene/input.pp.rs index c241241e18b97..0717af98b30b4 100644 --- a/src/test/run-make/pretty-expanded-hygiene/input.pp.rs +++ b/src/test/run-make/pretty-expanded-hygiene/input.pp.rs @@ -14,3 +14,5 @@ fn bar /* 62#0 */() { let x /* 59#2 */ = 1; y /* 61#4 */ + x /* 59#5 */ } + +fn y /* 61#0 */() { } diff --git a/src/test/run-make/pretty-expanded-hygiene/input.rs b/src/test/run-make/pretty-expanded-hygiene/input.rs index 56783b5609943..422fbdb088488 100644 --- a/src/test/run-make/pretty-expanded-hygiene/input.rs +++ b/src/test/run-make/pretty-expanded-hygiene/input.rs @@ -20,3 +20,5 @@ fn bar() { let x = 1; foo!(x) } + +fn y() {}