Skip to content

Commit f553701

Browse files
committed
libsyntax: De-@mut ParseSess::included_mod_stack
1 parent 08321f1 commit f553701

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

src/libsyntax/parse/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use parse::attr::parser_attr;
1919
use parse::lexer::reader;
2020
use parse::parser::Parser;
2121

22+
use std::cell::RefCell;
2223
use std::io;
2324
use std::io::File;
2425
use std::str;
@@ -43,15 +44,15 @@ pub struct ParseSess {
4344
cm: @codemap::CodeMap, // better be the same as the one in the reader!
4445
span_diagnostic: @mut SpanHandler, // better be the same as the one in the reader!
4546
/// Used to determine and report recursive mod inclusions
46-
included_mod_stack: ~[Path],
47+
included_mod_stack: RefCell<~[Path]>,
4748
}
4849

4950
pub fn new_parse_sess(demitter: Option<@Emitter>) -> @mut ParseSess {
5051
let cm = @CodeMap::new();
5152
@mut ParseSess {
5253
cm: cm,
5354
span_diagnostic: mk_span_handler(mk_handler(demitter), cm),
54-
included_mod_stack: ~[],
55+
included_mod_stack: RefCell::new(~[]),
5556
}
5657
}
5758

@@ -61,7 +62,7 @@ pub fn new_parse_sess_special_handler(sh: @mut SpanHandler,
6162
@mut ParseSess {
6263
cm: cm,
6364
span_diagnostic: sh,
64-
included_mod_stack: ~[],
65+
included_mod_stack: RefCell::new(~[]),
6566
}
6667
}
6768

src/libsyntax/parse/parser.rs

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4264,21 +4264,28 @@ impl Parser {
42644264
path: Path,
42654265
outer_attrs: ~[ast::Attribute],
42664266
id_sp: Span) -> (ast::item_, ~[ast::Attribute]) {
4267-
let maybe_i = self.sess.included_mod_stack.iter().position(|p| *p == path);
4268-
match maybe_i {
4269-
Some(i) => {
4270-
let stack = &self.sess.included_mod_stack;
4271-
let mut err = ~"circular modules: ";
4272-
for p in stack.slice(i, stack.len()).iter() {
4273-
p.display().with_str(|s| err.push_str(s));
4274-
err.push_str(" -> ");
4267+
{
4268+
let mut included_mod_stack = self.sess
4269+
.included_mod_stack
4270+
.borrow_mut();
4271+
let maybe_i = included_mod_stack.get()
4272+
.iter()
4273+
.position(|p| *p == path);
4274+
match maybe_i {
4275+
Some(i) => {
4276+
let mut err = ~"circular modules: ";
4277+
let len = included_mod_stack.get().len();
4278+
for p in included_mod_stack.get().slice(i, len).iter() {
4279+
p.display().with_str(|s| err.push_str(s));
4280+
err.push_str(" -> ");
4281+
}
4282+
path.display().with_str(|s| err.push_str(s));
4283+
self.span_fatal(id_sp, err);
42754284
}
4276-
path.display().with_str(|s| err.push_str(s));
4277-
self.span_fatal(id_sp, err);
4285+
None => ()
42784286
}
4279-
None => ()
4287+
included_mod_stack.get().push(path.clone());
42804288
}
4281-
self.sess.included_mod_stack.push(path.clone());
42824289
42834290
let mut p0 =
42844291
new_sub_parser_from_file(self.sess,
@@ -4289,7 +4296,12 @@ impl Parser {
42894296
let mod_attrs = vec::append(outer_attrs, inner);
42904297
let first_item_outer_attrs = next;
42914298
let m0 = p0.parse_mod_items(token::EOF, first_item_outer_attrs);
4292-
self.sess.included_mod_stack.pop();
4299+
{
4300+
let mut included_mod_stack = self.sess
4301+
.included_mod_stack
4302+
.borrow_mut();
4303+
included_mod_stack.get().pop();
4304+
}
42934305
return (ast::item_mod(m0), mod_attrs);
42944306
}
42954307

0 commit comments

Comments
 (0)