Skip to content

Commit f8a61a8

Browse files
committed
---
yaml --- r: 64059 b: refs/heads/snap-stage3 c: d91ac39 h: refs/heads/master i: 64057: 8ec84ec 64055: 7d925ab v: v3
1 parent 2502c22 commit f8a61a8

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
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 2d28d645422c1617be58c8ca7ad9a457264ca850
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 63f785769740b3e61e1c4d908c7a97f836c3cdc4
4+
refs/heads/snap-stage3: d91ac39cd522dd40b80372baeb693680c1d15927
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/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/snap-stage3/src/libsyntax/parse/parser.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,6 @@ pub struct Parser {
264264
obsolete_set: @mut HashSet<ObsoleteSyntax>,
265265
/// Used to determine the path to externally loaded source files
266266
mod_path_stack: @mut ~[@str],
267-
268267
}
269268

270269
#[unsafe_destructor]
@@ -3833,7 +3832,7 @@ impl Parser {
38333832
(id, item_static(ty, m, e), None)
38343833
}
38353834

3836-
// parse a mod { ...} item
3835+
// parse a `mod <foo> { ... }` or `mod <foo>;` item
38373836
fn parse_item_mod(&self, outer_attrs: ~[ast::attribute]) -> item_info {
38383837
let id_span = *self.span;
38393838
let id = self.parse_ident();
@@ -3906,13 +3905,31 @@ impl Parser {
39063905
prefix.push_many(path.components)
39073906
};
39083907
let full_path = full_path.normalize();
3908+
3909+
let maybe_i = do self.sess.included_mod_stack.iter().position_ |&p| { p == full_path };
3910+
match maybe_i {
3911+
Some(i) => {
3912+
let stack = &self.sess.included_mod_stack;
3913+
let mut err = ~"circular modules: ";
3914+
for stack.slice(i, stack.len()).iter().advance |p| {
3915+
err.push_str(p.to_str());
3916+
err.push_str(" -> ");
3917+
}
3918+
err.push_str(full_path.to_str());
3919+
self.span_fatal(id_sp, err);
3920+
}
3921+
None => ()
3922+
}
3923+
self.sess.included_mod_stack.push(full_path.clone());
3924+
39093925
let p0 =
39103926
new_sub_parser_from_file(self.sess, copy self.cfg,
39113927
&full_path, id_sp);
39123928
let (inner, next) = p0.parse_inner_attrs_and_next();
39133929
let mod_attrs = vec::append(outer_attrs, inner);
39143930
let first_item_outer_attrs = next;
39153931
let m0 = p0.parse_mod_items(token::EOF, first_item_outer_attrs);
3932+
self.sess.included_mod_stack.pop();
39163933
return (ast::item_mod(m0), mod_attrs);
39173934
39183935
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)