Skip to content

Made ast::blk not use spanned<T> anymore. #7826

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
6 changes: 3 additions & 3 deletions src/libextra/dlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,11 @@ impl<T> Deque<T> for DList<T> {
let tail_own = match tail.prev.resolve() {
None => {
self.list_tail = Rawlink::none();
self.list_head.swap_unwrap()
self.list_head.take_unwrap()
},
Some(tail_prev) => {
self.list_tail = tail.prev;
tail_prev.next.swap_unwrap()
tail_prev.next.take_unwrap()
}
};
Some(tail_own.value)
Expand Down Expand Up @@ -465,7 +465,7 @@ impl<'self, A> ListInsertion<A> for MutDListIterator<'self, A> {
Some(prev) => prev,
};
let mut ins_node = ~Node{value: elt, next: None, prev: Rawlink::none()};
let node_own = prev_node.next.swap_unwrap();
let node_own = prev_node.next.take_unwrap();
ins_node.next = link_with_prev(node_own, Rawlink::some(ins_node));
prev_node.next = link_with_prev(ins_node, Rawlink::some(prev_node));
self.list.length += 1;
Expand Down
2 changes: 1 addition & 1 deletion src/libextra/net/ip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ pub fn get_addr(node: &str, iotask: &iotask)
let (output_po, output_ch) = stream();
let mut output_ch = Some(SharedChan::new(output_ch));
do str::as_buf(node) |node_ptr, len| {
let output_ch = output_ch.swap_unwrap();
let output_ch = output_ch.take_unwrap();
debug!("slice len %?", len);
let handle = create_uv_getaddrinfo_t();
let handle_ptr: *uv_getaddrinfo_t = &handle;
Expand Down
4 changes: 2 additions & 2 deletions src/libextra/smallintmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ impl<V> SmallIntMap<V> {
/// Visit all key-value pairs in reverse order
pub fn each_reverse<'a>(&'a self, it: &fn(uint, &'a V) -> bool) -> bool {
for uint::range_rev(self.v.len(), 0) |i| {
match self.v[i - 1] {
Some(ref elt) => if !it(i - 1, elt) { return false; },
match self.v[i] {
Some(ref elt) => if !it(i, elt) { return false; },
None => ()
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/libextra/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ impl<'self> Condvar<'self> {
signal_waitqueue(&state.waiters);
}
// Enqueue ourself to be woken up by a signaller.
let SignalEnd = SignalEnd.swap_unwrap();
let SignalEnd = SignalEnd.take_unwrap();
state.blocked[condvar_id].tail.send(SignalEnd);
} else {
out_of_bounds = Some(state.blocked.len());
Expand All @@ -281,7 +281,7 @@ impl<'self> Condvar<'self> {
// Unconditionally "block". (Might not actually block if a
// signaller already sent -- I mean 'unconditionally' in contrast
// with acquire().)
let _ = comm::recv_one(WaitEnd.swap_unwrap());
let _ = comm::recv_one(WaitEnd.take_unwrap());
}

// This is needed for a failing condition variable to reacquire the
Expand Down Expand Up @@ -353,7 +353,7 @@ impl<'self> Condvar<'self> {
}
}
do check_cvar_bounds(out_of_bounds, condvar_id, "cond.signal_on()") {
let queue = queue.swap_unwrap();
let queue = queue.take_unwrap();
broadcast_waitqueue(&queue)
}
}
Expand Down Expand Up @@ -1436,7 +1436,7 @@ mod tests {
do x.write_downgrade |xwrite| {
let mut xopt = Some(xwrite);
do y.write_downgrade |_ywrite| {
y.downgrade(xopt.swap_unwrap());
y.downgrade(xopt.take_unwrap());
error!("oops, y.downgrade(x) should have failed!");
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/libextra/treemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ fn mutate_values<'r, K: TotalOrd, V>(node: &'r mut Option<~TreeNode<K, V>>,
// Remove left horizontal link by rotating right
fn skew<K: TotalOrd, V>(node: &mut ~TreeNode<K, V>) {
if node.left.map_default(false, |x| x.level == node.level) {
let mut save = node.left.swap_unwrap();
let mut save = node.left.take_unwrap();
swap(&mut node.left, &mut save.right); // save.right now None
swap(node, &mut save);
node.right = Some(save);
Expand All @@ -564,7 +564,7 @@ fn skew<K: TotalOrd, V>(node: &mut ~TreeNode<K, V>) {
fn split<K: TotalOrd, V>(node: &mut ~TreeNode<K, V>) {
if node.right.map_default(false,
|x| x.right.map_default(false, |y| y.level == node.level)) {
let mut save = node.right.swap_unwrap();
let mut save = node.right.take_unwrap();
swap(&mut node.right, &mut save.left); // save.left now None
save.level += 1;
swap(node, &mut save);
Expand Down Expand Up @@ -643,7 +643,7 @@ fn remove<K: TotalOrd, V>(node: &mut Option<~TreeNode<K, V>>,
Equal => {
if save.left.is_some() {
if save.right.is_some() {
let mut left = save.left.swap_unwrap();
let mut left = save.left.take_unwrap();
if left.right.is_some() {
heir_swap(save, &mut left.right);
} else {
Expand All @@ -653,13 +653,13 @@ fn remove<K: TotalOrd, V>(node: &mut Option<~TreeNode<K, V>>,
save.left = Some(left);
(remove(&mut save.left, key), true)
} else {
let new = save.left.swap_unwrap();
let new = save.left.take_unwrap();
let ~TreeNode{value, _} = replace(save, new);
*save = save.left.swap_unwrap();
*save = save.left.take_unwrap();
(Some(value), true)
}
} else if save.right.is_some() {
let new = save.right.swap_unwrap();
let new = save.right.take_unwrap();
let ~TreeNode{value, _} = replace(save, new);
(Some(value), true)
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ pub fn pretty_print_input(sess: Session, cfg: ast::crate_cfg, input: &input,
pprust::node_block(s, ref blk) => {
pp::space(s.s);
pprust::synth_comment(
s, ~"block " + int::to_str(blk.node.id));
s, ~"block " + int::to_str(blk.id));
}
pprust::node_expr(s, expr) => {
pp::space(s.s);
Expand Down
9 changes: 5 additions & 4 deletions src/librustc/front/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub fn strip_items(crate: &ast::crate, in_cfg: in_cfg_pred)

let precursor = @fold::AstFoldFns {
fold_mod: |a,b| fold_mod(ctxt, a, b),
fold_block: fold::wrap(|a,b| fold_block(ctxt, a, b) ),
fold_block: |a,b| fold_block(ctxt, a, b),
fold_foreign_mod: |a,b| fold_foreign_mod(ctxt, a, b),
fold_item_underscore: |a,b| {
// Bad copy.
Expand Down Expand Up @@ -133,21 +133,22 @@ fn filter_stmt(cx: @Context, stmt: @ast::stmt) ->

fn fold_block(
cx: @Context,
b: &ast::blk_,
b: &ast::blk,
fld: @fold::ast_fold
) -> ast::blk_ {
) -> ast::blk {
let resulting_stmts = do b.stmts.iter().filter_map |a| {
filter_stmt(cx, *a).chain(|stmt| fld.fold_stmt(stmt))
}.collect();
let filtered_view_items = do b.view_items.iter().filter_map |a| {
filter_view_item(cx, a).map(|&x| fld.fold_view_item(x))
}.collect();
ast::blk_ {
ast::blk {
view_items: filtered_view_items,
stmts: resulting_stmts,
expr: b.expr.map(|x| fld.fold_expr(*x)),
id: b.id,
rules: b.rules,
span: b.span,
}
}

Expand Down
9 changes: 5 additions & 4 deletions src/librustc/middle/astencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ fn encode_ast(ebml_w: &mut writer::Encoder, item: ast::inlined_item) {
// nested items, as otherwise it would get confused when translating
// inlined items.
fn simplify_ast(ii: &ast::inlined_item) -> ast::inlined_item {
fn drop_nested_items(blk: &ast::blk_, fld: @fold::ast_fold) -> ast::blk_ {
fn drop_nested_items(blk: &ast::blk, fld: @fold::ast_fold) -> ast::blk {
let stmts_sans_items = do blk.stmts.iter().filter_map |stmt| {
match stmt.node {
ast::stmt_expr(_, _) | ast::stmt_semi(_, _) |
Expand All @@ -300,19 +300,20 @@ fn simplify_ast(ii: &ast::inlined_item) -> ast::inlined_item {
ast::stmt_mac(*) => fail!("unexpanded macro in astencode")
}
}.collect();
let blk_sans_items = ast::blk_ {
let blk_sans_items = ast::blk {
view_items: ~[], // I don't know if we need the view_items here,
// but it doesn't break tests!
stmts: stmts_sans_items,
expr: blk.expr,
id: blk.id,
rules: blk.rules
rules: blk.rules,
span: blk.span,
};
fold::noop_fold_block(&blk_sans_items, fld)
}

let fld = fold::make_fold(@fold::AstFoldFns {
fold_block: fold::wrap(drop_nested_items),
fold_block: drop_nested_items,
.. *fold::default_ast_fold()
});

Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/borrowck/check_loans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub fn check_loans(bccx: @BorrowckCtxt,
move_data: move_data::FlowedMoveData,
all_loans: &[Loan],
body: &ast::blk) {
debug!("check_loans(body id=%?)", body.node.id);
debug!("check_loans(body id=%?)", body.id);

let clcx = @mut CheckLoanCtxt {
bccx: bccx,
Expand Down Expand Up @@ -751,5 +751,5 @@ fn check_loans_in_block<'a>(blk: &ast::blk,
visit::vt<@mut CheckLoanCtxt<'a>>))
{
visit::visit_block(blk, (this, vt));
this.check_for_conflicting_loans(blk.node.id);
this.check_for_conflicting_loans(blk.id);
}
22 changes: 11 additions & 11 deletions src/librustc/middle/borrowck/gather_loans/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ pub fn gather_loans(bccx: @BorrowckCtxt,
bccx: bccx,
id_range: id_range::max(),
all_loans: @mut ~[],
item_ub: body.node.id,
repeating_ids: ~[body.node.id],
item_ub: body.id,
repeating_ids: ~[body.id],
move_data: @mut MoveData::new()
};
glcx.gather_fn_arg_patterns(decl, body);
Expand Down Expand Up @@ -123,9 +123,9 @@ fn gather_loans_in_fn(fk: &visit::fn_kind,

// Visit closures as part of the containing item.
&visit::fk_anon(*) | &visit::fk_fn_block(*) => {
this.push_repeating_id(body.node.id);
this.push_repeating_id(body.id);
visit::visit_fn(fk, decl, body, sp, id, (this, v));
this.pop_repeating_id(body.node.id);
this.pop_repeating_id(body.id);
this.gather_fn_arg_patterns(decl, body);
}
}
Expand All @@ -134,7 +134,7 @@ fn gather_loans_in_fn(fk: &visit::fn_kind,
fn gather_loans_in_block(blk: &ast::blk,
(this, vt): (@mut GatherLoanCtxt,
visit::vt<@mut GatherLoanCtxt>)) {
this.id_range.add(blk.node.id);
this.id_range.add(blk.id);
visit::visit_block(blk, (this, vt));
}

Expand Down Expand Up @@ -240,7 +240,7 @@ fn gather_loans_in_expr(ex: @ast::expr,
let cmt = this.bccx.cat_expr(ex_v);
for arms.iter().advance |arm| {
for arm.pats.iter().advance |pat| {
this.gather_pat(cmt, *pat, Some((arm.body.node.id, ex.id)));
this.gather_pat(cmt, *pat, Some((arm.body.id, ex.id)));
}
}
visit::visit_expr(ex, (this, vt));
Expand Down Expand Up @@ -268,16 +268,16 @@ fn gather_loans_in_expr(ex: @ast::expr,
this.pop_repeating_id(cond.id);

// during body, can only root for the body
this.push_repeating_id(body.node.id);
this.push_repeating_id(body.id);
(vt.visit_block)(body, (this, vt));
this.pop_repeating_id(body.node.id);
this.pop_repeating_id(body.id);
}

// see explanation attached to the `root_ub` field:
ast::expr_loop(ref body, _) => {
this.push_repeating_id(body.node.id);
this.push_repeating_id(body.id);
visit::visit_expr(ex, (this, vt));
this.pop_repeating_id(body.node.id);
this.pop_repeating_id(body.id);
}

ast::expr_fn_block(*) => {
Expand Down Expand Up @@ -623,7 +623,7 @@ impl GatherLoanCtxt {
let arg_cmt = mc_ctxt.cat_rvalue(
arg.id,
arg.pat.span,
body.node.id, // Arguments live only as long as the fn body.
body.id, // Arguments live only as long as the fn body.
arg_ty);

self.gather_pat(arg_cmt, arg.pat, None);
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/cfg/construct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ pub fn construct(tcx: ty::ctxt,
impl CFGBuilder {
fn block(&mut self, blk: &ast::blk, pred: CFGIndex) -> CFGIndex {
let mut stmts_exit = pred;
for blk.node.stmts.iter().advance |&stmt| {
for blk.stmts.iter().advance |&stmt| {
stmts_exit = self.stmt(stmt, stmts_exit);
}

let expr_exit = self.opt_expr(blk.node.expr, stmts_exit);
let expr_exit = self.opt_expr(blk.expr, stmts_exit);

self.add_node(blk.node.id, [expr_exit])
self.add_node(blk.id, [expr_exit])
}

fn stmt(&mut self, stmt: @ast::stmt, pred: CFGIndex) -> CFGIndex {
Expand Down
58 changes: 53 additions & 5 deletions src/librustc/middle/const_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,58 @@ pub fn classify(e: &expr,
pub fn lookup_const(tcx: ty::ctxt, e: &expr) -> Option<@expr> {
match tcx.def_map.find(&e.id) {
Some(&ast::def_static(def_id, false)) => lookup_const_by_id(tcx, def_id),
Some(&ast::def_variant(enum_def, variant_def)) => lookup_variant_by_id(tcx,
enum_def,
variant_def),
_ => None
}
}

pub fn lookup_variant_by_id(tcx: ty::ctxt,
enum_def: ast::def_id,
variant_def: ast::def_id)
-> Option<@expr> {
fn variant_expr(variants: &[ast::variant], id: ast::node_id) -> Option<@expr> {
for variants.iter().advance |variant| {
if variant.node.id == id {
return variant.node.disr_expr;
}
}
None
}

if ast_util::is_local(enum_def) {
match tcx.items.find(&enum_def.node) {
None => None,
Some(&ast_map::node_item(it, _)) => match it.node {
item_enum(ast::enum_def { variants: ref variants }, _) => {
variant_expr(*variants, variant_def.node)
}
_ => None
},
Some(_) => None
}
} else {
let maps = astencode::Maps {
root_map: @mut HashMap::new(),
method_map: @mut HashMap::new(),
vtable_map: @mut HashMap::new(),
write_guard_map: @mut HashSet::new(),
capture_map: @mut HashMap::new()
};
match csearch::maybe_get_item_ast(tcx, enum_def,
|a, b, c, d| astencode::decode_inlined_item(a, b, maps, /*bar*/ copy c, d)) {
csearch::found(ast::ii_item(item)) => match item.node {
item_enum(ast::enum_def { variants: ref variants }, _) => {
variant_expr(*variants, variant_def.node)
}
_ => None
},
_ => None
}
}
}

pub fn lookup_const_by_id(tcx: ty::ctxt,
def_id: ast::def_id)
-> Option<@expr> {
Expand Down Expand Up @@ -237,13 +285,13 @@ pub enum const_val {
}

pub fn eval_const_expr(tcx: middle::ty::ctxt, e: &expr) -> const_val {
match eval_const_expr_partial(tcx, e) {
match eval_const_expr_partial(&tcx, e) {
Ok(r) => r,
Err(s) => tcx.sess.span_fatal(e.span, s)
}
}

pub fn eval_const_expr_partial(tcx: middle::ty::ctxt, e: &expr)
pub fn eval_const_expr_partial<T: ty::ExprTyProvider>(tcx: &T, e: &expr)
-> Result<const_val, ~str> {
use middle::ty;
fn fromb(b: bool) -> Result<const_val, ~str> { Ok(const_int(b as i64)) }
Expand Down Expand Up @@ -360,7 +408,7 @@ pub fn eval_const_expr_partial(tcx: middle::ty::ctxt, e: &expr)
}
}
expr_cast(base, _) => {
let ety = ty::expr_ty(tcx, e);
let ety = tcx.expr_ty(e);
let base = eval_const_expr_partial(tcx, base);
match /*bad*/copy base {
Err(_) => base,
Expand Down Expand Up @@ -390,8 +438,8 @@ pub fn eval_const_expr_partial(tcx: middle::ty::ctxt, e: &expr)
}
}
expr_path(_) => {
match lookup_const(tcx, e) {
Some(actual_e) => eval_const_expr_partial(tcx, actual_e),
match lookup_const(tcx.ty_ctxt(), e) {
Some(actual_e) => eval_const_expr_partial(&tcx.ty_ctxt(), actual_e),
None => Err(~"Non-constant path in constant expr")
}
}
Expand Down
Loading