Remove idempotent lowering test
This commit is contained in:
parent
0649942a46
commit
02df9f32b1
1 changed files with 0 additions and 114 deletions
|
@ -2116,117 +2116,3 @@ fn signal_block_expr(lctx: &LoweringContext,
|
||||||
}),
|
}),
|
||||||
attrs)
|
attrs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod test {
|
|
||||||
use super::*;
|
|
||||||
use syntax::ast::{self, NodeId, NodeIdAssigner};
|
|
||||||
use syntax::{parse, codemap};
|
|
||||||
use syntax::fold::Folder;
|
|
||||||
use std::cell::Cell;
|
|
||||||
|
|
||||||
struct MockAssigner {
|
|
||||||
next_id: Cell<NodeId>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl MockAssigner {
|
|
||||||
fn new() -> MockAssigner {
|
|
||||||
MockAssigner { next_id: Cell::new(0) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
trait FakeExtCtxt {
|
|
||||||
fn call_site(&self) -> codemap::Span;
|
|
||||||
fn cfg(&self) -> ast::CrateConfig;
|
|
||||||
fn ident_of(&self, st: &str) -> ast::Ident;
|
|
||||||
fn name_of(&self, st: &str) -> ast::Name;
|
|
||||||
fn parse_sess(&self) -> &parse::ParseSess;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FakeExtCtxt for parse::ParseSess {
|
|
||||||
fn call_site(&self) -> codemap::Span {
|
|
||||||
codemap::Span {
|
|
||||||
lo: codemap::BytePos(0),
|
|
||||||
hi: codemap::BytePos(0),
|
|
||||||
expn_id: codemap::NO_EXPANSION,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn cfg(&self) -> ast::CrateConfig {
|
|
||||||
Vec::new()
|
|
||||||
}
|
|
||||||
fn ident_of(&self, st: &str) -> ast::Ident {
|
|
||||||
parse::token::str_to_ident(st)
|
|
||||||
}
|
|
||||||
fn name_of(&self, st: &str) -> ast::Name {
|
|
||||||
parse::token::intern(st)
|
|
||||||
}
|
|
||||||
fn parse_sess(&self) -> &parse::ParseSess {
|
|
||||||
self
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl NodeIdAssigner for MockAssigner {
|
|
||||||
fn next_node_id(&self) -> NodeId {
|
|
||||||
let result = self.next_id.get();
|
|
||||||
self.next_id.set(result + 1);
|
|
||||||
result
|
|
||||||
}
|
|
||||||
|
|
||||||
fn peek_node_id(&self) -> NodeId {
|
|
||||||
self.next_id.get()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Folder for MockAssigner {
|
|
||||||
fn new_id(&mut self, old_id: NodeId) -> NodeId {
|
|
||||||
assert_eq!(old_id, ast::DUMMY_NODE_ID);
|
|
||||||
self.next_node_id()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_preserves_ids() {
|
|
||||||
let cx = parse::ParseSess::new();
|
|
||||||
let mut assigner = MockAssigner::new();
|
|
||||||
|
|
||||||
let ast_if_let = quote_expr!(&cx,
|
|
||||||
if let Some(foo) = baz {
|
|
||||||
bar(foo);
|
|
||||||
});
|
|
||||||
let ast_if_let = assigner.fold_expr(ast_if_let);
|
|
||||||
let ast_while_let = quote_expr!(&cx,
|
|
||||||
while let Some(foo) = baz {
|
|
||||||
bar(foo);
|
|
||||||
});
|
|
||||||
let ast_while_let = assigner.fold_expr(ast_while_let);
|
|
||||||
let ast_for = quote_expr!(&cx,
|
|
||||||
for i in 0..10 {
|
|
||||||
for j in 0..10 {
|
|
||||||
foo(i, j);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
let ast_for = assigner.fold_expr(ast_for);
|
|
||||||
let ast_in = quote_expr!(&cx, in HEAP { foo() });
|
|
||||||
let ast_in = assigner.fold_expr(ast_in);
|
|
||||||
|
|
||||||
let lctx = LoweringContext::testing_context(&assigner);
|
|
||||||
|
|
||||||
let hir1 = lower_expr(&lctx, &ast_if_let);
|
|
||||||
let hir2 = lower_expr(&lctx, &ast_if_let);
|
|
||||||
assert!(hir1 == hir2);
|
|
||||||
|
|
||||||
let hir1 = lower_expr(&lctx, &ast_while_let);
|
|
||||||
let hir2 = lower_expr(&lctx, &ast_while_let);
|
|
||||||
assert!(hir1 == hir2);
|
|
||||||
|
|
||||||
let hir1 = lower_expr(&lctx, &ast_for);
|
|
||||||
let hir2 = lower_expr(&lctx, &ast_for);
|
|
||||||
assert!(hir1 == hir2);
|
|
||||||
|
|
||||||
let hir1 = lower_expr(&lctx, &ast_in);
|
|
||||||
let hir2 = lower_expr(&lctx, &ast_in);
|
|
||||||
assert!(hir1 == hir2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue