Skip to content

Commit b8c763d

Browse files
committed
---
yaml --- r: 142481 b: refs/heads/try2 c: 0f25155 h: refs/heads/master i: 142479: 7b6c4ad v: v3
1 parent 74664c5 commit b8c763d

File tree

5 files changed

+61
-3
lines changed

5 files changed

+61
-3
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 280e4245c065da9c22b09c1d18c0629af1709eb3
8+
refs/heads/try2: 0f2515583dca4d6af7fabb6ebbd46c265710aacc
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libsyntax/parse/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ pub struct ParseSess {
4444
cm: @codemap::CodeMap, // better be the same as the one in the reader!
4545
next_id: node_id,
4646
span_diagnostic: @span_handler, // better be the same as the one in the reader!
47+
/// Used to determine and report recursive mod inclusions
48+
included_mod_stack: ~[Path],
4749
}
4850

4951
pub fn new_parse_sess(demitter: Option<Emitter>) -> @mut ParseSess {
@@ -52,6 +54,7 @@ pub fn new_parse_sess(demitter: Option<Emitter>) -> @mut ParseSess {
5254
cm: cm,
5355
next_id: 1,
5456
span_diagnostic: mk_span_handler(mk_handler(demitter), cm),
57+
included_mod_stack: ~[],
5558
}
5659
}
5760

@@ -62,6 +65,7 @@ pub fn new_parse_sess_special_handler(sh: @span_handler,
6265
cm: cm,
6366
next_id: 1,
6467
span_diagnostic: sh,
68+
included_mod_stack: ~[],
6569
}
6670
}
6771

branches/try2/src/libsyntax/parse/parser.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,6 @@ pub struct Parser {
272272
obsolete_set: @mut HashSet<ObsoleteSyntax>,
273273
/// Used to determine the path to externally loaded source files
274274
mod_path_stack: @mut ~[@str],
275-
276275
}
277276

278277
#[unsafe_destructor]
@@ -3841,7 +3840,7 @@ impl Parser {
38413840
(id, item_static(ty, m, e), None)
38423841
}
38433842

3844-
// parse a mod { ...} item
3843+
// parse a `mod <foo> { ... }` or `mod <foo>;` item
38453844
fn parse_item_mod(&self, outer_attrs: ~[ast::attribute]) -> item_info {
38463845
let id_span = *self.span;
38473846
let id = self.parse_ident();
@@ -3914,13 +3913,31 @@ impl Parser {
39143913
prefix.push_many(path.components)
39153914
};
39163915
let full_path = full_path.normalize();
3916+
3917+
let maybe_i = do self.sess.included_mod_stack.iter().position_ |&p| { p == full_path };
3918+
match maybe_i {
3919+
Some(i) => {
3920+
let stack = &self.sess.included_mod_stack;
3921+
let mut err = ~"circular modules: ";
3922+
for stack.slice(i, stack.len()).iter().advance |p| {
3923+
err.push_str(p.to_str());
3924+
err.push_str(" -> ");
3925+
}
3926+
err.push_str(full_path.to_str());
3927+
self.span_fatal(id_sp, err);
3928+
}
3929+
None => ()
3930+
}
3931+
self.sess.included_mod_stack.push(full_path.clone());
3932+
39173933
let p0 =
39183934
new_sub_parser_from_file(self.sess, copy self.cfg,
39193935
&full_path, id_sp);
39203936
let (inner, next) = p0.parse_inner_attrs_and_next();
39213937
let mod_attrs = vec::append(outer_attrs, inner);
39223938
let first_item_outer_attrs = next;
39233939
let m0 = p0.parse_mod_items(token::EOF, first_item_outer_attrs);
3940+
self.sess.included_mod_stack.pop();
39243941
return (ast::item_mod(m0), mod_attrs);
39253942
39263943
fn cdir_path_opt(default: @str, attrs: ~[ast::attribute]) -> @str {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// xfail-test: this is an auxiliary file for circular-modules-main.rs
12+
13+
mod circular_modules_main;
14+
15+
pub fn say_hello() {
16+
println(circular_modules_main::hi_str());
17+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
12+
mod circular_modules_hello; //~ERROR: circular modules
13+
14+
pub fn hi_str() -> ~str {
15+
~"Hi!"
16+
}
17+
18+
fn main() {
19+
circular_modules_hello::say_hello();
20+
}

0 commit comments

Comments
 (0)