Skip to content

Commit 2b4f28e

Browse files
committed
Misc fixups
1 parent 3d81f78 commit 2b4f28e

File tree

9 files changed

+54
-26
lines changed

9 files changed

+54
-26
lines changed

src/librustc/middle/astencode.rs

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ use serialize::EncoderHelpers;
5454

5555
#[cfg(test)] use std::io::Cursor;
5656
#[cfg(test)] use syntax::parse;
57+
#[cfg(test)] use syntax::ast::NodeId;
5758
#[cfg(test)] use rustc_front::print::pprust;
58-
#[cfg(test)] use rustc_front::lowering::lower_item;
59+
#[cfg(test)] use rustc_front::lowering::{lower_item, LoweringContext};
5960

6061
struct DecodeContext<'a, 'b, 'tcx: 'a> {
6162
tcx: &'a ty::ctxt<'tcx>,
@@ -1374,6 +1375,22 @@ impl FakeExtCtxt for parse::ParseSess {
13741375
fn parse_sess(&self) -> &parse::ParseSess { self }
13751376
}
13761377

1378+
#[cfg(test)]
1379+
struct FakeNodeIdAssigner;
1380+
1381+
#[cfg(test)]
1382+
// It should go without sayingt that this may give unexpected results. Avoid
1383+
// lowering anything which needs new nodes.
1384+
impl NodeIdAssigner for FakeNodeIdAssigner {
1385+
fn next_node_id(&self) -> NodeId {
1386+
0
1387+
}
1388+
1389+
fn peek_node_id(&self) -> NodeId {
1390+
0
1391+
}
1392+
}
1393+
13771394
#[cfg(test)]
13781395
fn mk_ctxt() -> parse::ParseSess {
13791396
parse::ParseSess::new()
@@ -1392,23 +1409,29 @@ fn roundtrip(in_item: P<hir::Item>) {
13921409
#[test]
13931410
fn test_basic() {
13941411
let cx = mk_ctxt();
1395-
roundtrip(lower_item(&quote_item!(&cx,
1412+
let fnia = FakeNodeIdAssigner;
1413+
let lcx = LoweringContext::new(&fnia, None);
1414+
roundtrip(lower_item(&lcx, &quote_item!(&cx,
13961415
fn foo() {}
13971416
).unwrap()));
13981417
}
13991418

14001419
#[test]
14011420
fn test_smalltalk() {
14021421
let cx = mk_ctxt();
1403-
roundtrip(lower_item(&quote_item!(&cx,
1422+
let fnia = FakeNodeIdAssigner;
1423+
let lcx = LoweringContext::new(&fnia, None);
1424+
roundtrip(lower_item(&lcx, &quote_item!(&cx,
14041425
fn foo() -> isize { 3 + 4 } // first smalltalk program ever executed.
14051426
).unwrap()));
14061427
}
14071428

14081429
#[test]
14091430
fn test_more() {
14101431
let cx = mk_ctxt();
1411-
roundtrip(lower_item(&quote_item!(&cx,
1432+
let fnia = FakeNodeIdAssigner;
1433+
let lcx = LoweringContext::new(&fnia, None);
1434+
roundtrip(lower_item(&lcx, &quote_item!(&cx,
14121435
fn foo(x: usize, y: usize) -> usize {
14131436
let z = x + y;
14141437
return z;
@@ -1425,10 +1448,12 @@ fn test_simplification() {
14251448
return alist {eq_fn: eq_int, data: Vec::new()};
14261449
}
14271450
).unwrap();
1428-
let hir_item = lower_item(&item);
1451+
let fnia = FakeNodeIdAssigner;
1452+
let lcx = LoweringContext::new(&fnia, None);
1453+
let hir_item = lower_item(&lcx, &item);
14291454
let item_in = InlinedItemRef::Item(&hir_item);
14301455
let item_out = simplify_ast(item_in);
1431-
let item_exp = InlinedItem::Item(lower_item(&quote_item!(&cx,
1456+
let item_exp = InlinedItem::Item(lower_item(&lcx, &quote_item!(&cx,
14321457
fn new_int_alist<B>() -> alist<isize, B> {
14331458
return alist {eq_fn: eq_int, data: Vec::new()};
14341459
}

src/librustc_driver/driver.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ pub fn compile_input(sess: Session,
112112

113113
let expanded_crate = assign_node_ids(&sess, expanded_crate);
114114
// Lower ast -> hir.
115-
let lcx = LoweringContext::new(&sess, &expanded_crate);
115+
let lcx = LoweringContext::new(&sess, Some(&expanded_crate));
116116
let mut hir_forest = time(sess.time_passes(),
117117
"lowering ast -> hir",
118118
|| hir_map::Forest::new(lower_crate(&lcx, &expanded_crate)));

src/librustc_driver/pretty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ pub fn pretty_print_input(sess: Session,
670670
// There is some twisted, god-forsaken tangle of lifetimes here which makes
671671
// the ordering of stuff super-finicky.
672672
let mut hir_forest;
673-
let lcx = LoweringContext::new(&sess, &krate);
673+
let lcx = LoweringContext::new(&sess, Some(&krate));
674674
let arenas = ty::CtxtArenas::new();
675675
let ast_map = if compute_ast_map {
676676
hir_forest = hir_map::Forest::new(lower_crate(&lcx, &krate));

src/librustc_driver/test.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use syntax::diagnostic::{Level, RenderSpan, Bug, Fatal, Error, Warning, Note, He
3838
use syntax::parse::token;
3939
use syntax::feature_gate::UnstableFeatures;
4040

41-
use rustc_front::lowering::lower_crate;
41+
use rustc_front::lowering::{lower_crate, LoweringContext};
4242
use rustc_front::hir;
4343

4444
struct Env<'a, 'tcx: 'a> {
@@ -124,7 +124,8 @@ fn test_env<F>(source_string: &str,
124124
.expect("phase 2 aborted");
125125

126126
let krate = driver::assign_node_ids(&sess, krate);
127-
let mut hir_forest = hir_map::Forest::new(lower_crate(&krate));
127+
let lcx = LoweringContext::new(&sess, Some(&krate));
128+
let mut hir_forest = hir_map::Forest::new(lower_crate(&lcx, &krate));
128129
let arenas = ty::CtxtArenas::new();
129130
let ast_map = driver::make_map(&sess, &mut hir_forest);
130131
let krate = ast_map.krate();
@@ -135,7 +136,7 @@ fn test_env<F>(source_string: &str,
135136
resolve::resolve_crate(&sess, &ast_map, resolve::MakeGlobMap::No);
136137
let named_region_map = resolve_lifetime::krate(&sess, krate, &def_map);
137138
let region_map = region::resolve_crate(&sess, krate);
138-
ty::ctxt::create_and_enter(sess,
139+
ty::ctxt::create_and_enter(&sess,
139140
&arenas,
140141
def_map,
141142
named_region_map,

src/librustc_front/lowering.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,16 @@ pub struct LoweringContext<'a> {
8080
}
8181

8282
impl<'a, 'hir> LoweringContext<'a> {
83-
pub fn new(id_assigner: &'a NodeIdAssigner, c: &Crate) -> LoweringContext<'a> {
84-
let crate_root = if std_inject::no_core(c) {
85-
None
86-
} else if std_inject::no_std(c) {
87-
Some("core")
88-
} else {
89-
Some("std")
90-
};
83+
pub fn new(id_assigner: &'a NodeIdAssigner, c: Option<&Crate>) -> LoweringContext<'a> {
84+
let crate_root = c.and_then(|c| {
85+
if std_inject::no_core(c) {
86+
None
87+
} else if std_inject::no_std(c) {
88+
Some("core")
89+
} else {
90+
Some("std")
91+
}
92+
});
9193

9294
LoweringContext {
9395
crate_root: crate_root,

src/librustc_typeck/coherence/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ use std::cell::RefCell;
3838
use std::rc::Rc;
3939
use syntax::codemap::Span;
4040
use syntax::parse::token;
41-
use syntax::ast::NodeIdAssigner;
4241
use util::nodemap::{DefIdMap, FnvHashMap};
4342
use rustc::front::map as hir_map;
4443
use rustc::front::map::NodeItem;

src/librustdoc/core.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ pub fn run_core(search_paths: SearchPaths, cfgs: Vec<String>, externs: Externs,
135135

136136
let krate = driver::assign_node_ids(&sess, krate);
137137
// Lower ast -> hir.
138-
let lcx = LoweringContext::new(&sess, &krate);
138+
let lcx = LoweringContext::new(&sess, Some(&krate));
139139
let mut hir_forest = hir_map::Forest::new(lower_crate(&lcx, &krate));
140140
let arenas = ty::CtxtArenas::new();
141141
let hir_map = driver::make_map(&sess, &mut hir_forest);

src/librustdoc/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub fn run(input: &str,
8383
"rustdoc-test", None)
8484
.expect("phase_2_configure_and_expand aborted in rustdoc!");
8585
let krate = driver::assign_node_ids(&sess, krate);
86-
let lcx = LoweringContext::new(&sess, &krate);
86+
let lcx = LoweringContext::new(&sess, Some(&krate));
8787
let krate = lower_crate(&lcx, &krate);
8888

8989
let opts = scrape_test_config(&krate);

src/test/run-make/execution-engine/test.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use rustc::middle::ty;
3131
use rustc::session::config::{self, basic_options, build_configuration, Input, Options};
3232
use rustc::session::build_session;
3333
use rustc_driver::driver;
34-
use rustc_front::lowering::lower_crate;
34+
use rustc_front::lowering::{lower_crate, LoweringContext};
3535
use rustc_resolve::MakeGlobMap;
3636
use libc::c_void;
3737

@@ -223,12 +223,13 @@ fn compile_program(input: &str, sysroot: PathBuf)
223223
.expect("phase_2 returned `None`");
224224

225225
let krate = driver::assign_node_ids(&sess, krate);
226-
let mut hir_forest = ast_map::Forest::new(lower_crate(&krate));
226+
let lcx = LoweringContext::new(&sess, Some(&krate));
227+
let mut hir_forest = ast_map::Forest::new(lower_crate(&lcx, &krate));
227228
let arenas = ty::CtxtArenas::new();
228229
let ast_map = driver::make_map(&sess, &mut hir_forest);
229230

230231
driver::phase_3_run_analysis_passes(
231-
sess, ast_map, &arenas, id, MakeGlobMap::No, |tcx, analysis| {
232+
&sess, ast_map, &arenas, id, MakeGlobMap::No, |tcx, analysis| {
232233

233234
let trans = driver::phase_4_translate_to_llvm(tcx, analysis);
234235

@@ -246,7 +247,7 @@ fn compile_program(input: &str, sysroot: PathBuf)
246247
let modp = llmod as usize;
247248

248249
(modp, deps)
249-
}).1
250+
})
250251
}).unwrap();
251252

252253
match handle.join() {

0 commit comments

Comments
 (0)