diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2013-12-27 11:51:18 -0800 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2014-01-03 14:01:56 -0800 |
| commit | f553701da64dd70d1fa6b757208f012dbad118d7 (patch) | |
| tree | d0740b11dff63e3a883bbd4ac7273b74966044d7 /src/libsyntax/parse | |
| parent | 08321f1c49d75e60a2c56320a3f1483e7bf79a91 (diff) | |
| download | rust-f553701da64dd70d1fa6b757208f012dbad118d7.tar.gz rust-f553701da64dd70d1fa6b757208f012dbad118d7.zip | |
libsyntax: De-`@mut` `ParseSess::included_mod_stack`
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/mod.rs | 7 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 38 |
2 files changed, 29 insertions, 16 deletions
diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 5a8444518aa..b6139f0ae99 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -19,6 +19,7 @@ use parse::attr::parser_attr; use parse::lexer::reader; use parse::parser::Parser; +use std::cell::RefCell; use std::io; use std::io::File; use std::str; @@ -43,7 +44,7 @@ pub struct ParseSess { cm: @codemap::CodeMap, // better be the same as the one in the reader! span_diagnostic: @mut SpanHandler, // better be the same as the one in the reader! /// Used to determine and report recursive mod inclusions - included_mod_stack: ~[Path], + included_mod_stack: RefCell<~[Path]>, } pub fn new_parse_sess(demitter: Option<@Emitter>) -> @mut ParseSess { @@ -51,7 +52,7 @@ pub fn new_parse_sess(demitter: Option<@Emitter>) -> @mut ParseSess { @mut ParseSess { cm: cm, span_diagnostic: mk_span_handler(mk_handler(demitter), cm), - included_mod_stack: ~[], + included_mod_stack: RefCell::new(~[]), } } @@ -61,7 +62,7 @@ pub fn new_parse_sess_special_handler(sh: @mut SpanHandler, @mut ParseSess { cm: cm, span_diagnostic: sh, - included_mod_stack: ~[], + included_mod_stack: RefCell::new(~[]), } } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 2428710087f..ed149c1a73e 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -4264,21 +4264,28 @@ impl Parser { path: Path, outer_attrs: ~[ast::Attribute], id_sp: Span) -> (ast::item_, ~[ast::Attribute]) { - let maybe_i = self.sess.included_mod_stack.iter().position(|p| *p == path); - match maybe_i { - Some(i) => { - let stack = &self.sess.included_mod_stack; - let mut err = ~"circular modules: "; - for p in stack.slice(i, stack.len()).iter() { - p.display().with_str(|s| err.push_str(s)); - err.push_str(" -> "); + { + let mut included_mod_stack = self.sess + .included_mod_stack + .borrow_mut(); + let maybe_i = included_mod_stack.get() + .iter() + .position(|p| *p == path); + match maybe_i { + Some(i) => { + let mut err = ~"circular modules: "; + let len = included_mod_stack.get().len(); + for p in included_mod_stack.get().slice(i, len).iter() { + p.display().with_str(|s| err.push_str(s)); + err.push_str(" -> "); + } + path.display().with_str(|s| err.push_str(s)); + self.span_fatal(id_sp, err); } - path.display().with_str(|s| err.push_str(s)); - self.span_fatal(id_sp, err); + None => () } - None => () + included_mod_stack.get().push(path.clone()); } - self.sess.included_mod_stack.push(path.clone()); let mut p0 = new_sub_parser_from_file(self.sess, @@ -4289,7 +4296,12 @@ impl Parser { let mod_attrs = vec::append(outer_attrs, inner); let first_item_outer_attrs = next; let m0 = p0.parse_mod_items(token::EOF, first_item_outer_attrs); - self.sess.included_mod_stack.pop(); + { + let mut included_mod_stack = self.sess + .included_mod_stack + .borrow_mut(); + included_mod_stack.get().pop(); + } return (ast::item_mod(m0), mod_attrs); } |
