From 7f816b7ef4c617eec3d03397f4013c06c9f98ce2 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Sun, 22 Dec 2013 14:26:36 -0800 Subject: [PATCH] librustc: De-`@mut` the `idstack` in constant checking --- src/librustc/middle/check_const.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/librustc/middle/check_const.rs b/src/librustc/middle/check_const.rs index 840f9ec2475..3922d338f3e 100644 --- a/src/librustc/middle/check_const.rs +++ b/src/librustc/middle/check_const.rs @@ -15,6 +15,7 @@ use middle::typeck; use util::ppaux; +use std::cell::RefCell; use syntax::ast::*; use syntax::codemap; use syntax::{ast_util, ast_map}; @@ -215,7 +216,7 @@ struct env { sess: Session, ast_map: ast_map::map, def_map: resolve::DefMap, - idstack: @mut ~[NodeId] + idstack: @RefCell<~[NodeId]>, } struct CheckItemRecursionVisitor { @@ -233,7 +234,7 @@ pub fn check_item_recursion(sess: Session, sess: sess, ast_map: ast_map, def_map: def_map, - idstack: @mut ~[] + idstack: @RefCell::new(~[]), }; let mut visitor = CheckItemRecursionVisitor { env: env }; @@ -242,12 +243,19 @@ pub fn check_item_recursion(sess: Session, impl Visitor<()> for CheckItemRecursionVisitor { fn visit_item(&mut self, it: @item, _: ()) { - if self.env.idstack.iter().any(|x| x == &(it.id)) { - self.env.sess.span_fatal(self.env.root_it.span, "recursive constant"); + { + let mut idstack = self.env.idstack.borrow_mut(); + if idstack.get().iter().any(|x| x == &(it.id)) { + self.env.sess.span_fatal(self.env.root_it.span, + "recursive constant"); + } + idstack.get().push(it.id); } - self.env.idstack.push(it.id); visit::walk_item(self, it, ()); - self.env.idstack.pop(); + { + let mut idstack = self.env.idstack.borrow_mut(); + idstack.get().pop(); + } } fn visit_expr(&mut self, e: @Expr, _: ()) { -- GitLab