diff options
Diffstat (limited to 'src/libsyntax/parse/parser.rs')
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index cc0baa28e20..611d58f852d 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -264,7 +264,6 @@ pub struct Parser { obsolete_set: @mut HashSet<ObsoleteSyntax>, /// Used to determine the path to externally loaded source files mod_path_stack: @mut ~[@str], - } #[unsafe_destructor] @@ -3834,7 +3833,7 @@ impl Parser { (id, item_static(ty, m, e), None) } - // parse a mod { ...} item + // parse a `mod <foo> { ... }` or `mod <foo>;` item fn parse_item_mod(&self, outer_attrs: ~[ast::attribute]) -> item_info { let id_span = *self.span; let id = self.parse_ident(); @@ -3907,6 +3906,23 @@ impl Parser { prefix.push_many(path.components) }; let full_path = full_path.normalize(); + + let maybe_i = do self.sess.included_mod_stack.iter().position_ |&p| { p == full_path }; + match maybe_i { + Some(i) => { + let stack = &self.sess.included_mod_stack; + let mut err = ~"circular modules: "; + for stack.slice(i, stack.len()).iter().advance |p| { + err.push_str(p.to_str()); + err.push_str(" -> "); + } + err.push_str(full_path.to_str()); + self.span_fatal(id_sp, err); + } + None => () + } + self.sess.included_mod_stack.push(full_path.clone()); + let p0 = new_sub_parser_from_file(self.sess, copy self.cfg, &full_path, id_sp); @@ -3914,6 +3930,7 @@ 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(); return (ast::item_mod(m0), mod_attrs); fn cdir_path_opt(default: @str, attrs: ~[ast::attribute]) -> @str { |
