about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-07-22 04:37:36 -0700
committerbors <bors@rust-lang.org>2013-07-22 04:37:36 -0700
commit7b2218d248571a242ac243e0443d95619bdda056 (patch)
tree5a7df07eb67a06eab4eda78846e7db8cd7d0bd7e
parent40a48e62c1c72090dc00fa50dc7c6d3da8c9ab88 (diff)
parenta74d92e8ab61863876d2b5b6256b403efbb55492 (diff)
downloadrust-7b2218d248571a242ac243e0443d95619bdda056.tar.gz
rust-7b2218d248571a242ac243e0443d95619bdda056.zip
auto merge of #7926 : brson/rust/issue-4116, r=graydon
When loading a module the parser will look for either foo.rs or foo/mod.rs and generate
an error when both are found.
-rw-r--r--src/libsyntax/parse/parser.rs37
-rw-r--r--src/test/compile-fail/mod_file_disambig.rs15
-rw-r--r--src/test/compile-fail/mod_file_disambig_aux.rs (renamed from src/test/compile-fail/missingmod.rc)4
-rw-r--r--src/test/compile-fail/mod_file_disambig_aux/mod.rs11
-rw-r--r--src/test/compile-fail/mod_file_not_exist.rs2
-rw-r--r--src/test/run-pass/mod_dir_implicit.rs18
-rw-r--r--src/test/run-pass/mod_dir_implicit_aux/mod.rs11
7 files changed, 82 insertions, 16 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index e6a66b9c61e..b2a1a8a73bd 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -3996,37 +3996,50 @@ impl Parser {
         let prefix = prefix.dir_path();
         let mod_path_stack = &*self.mod_path_stack;
         let mod_path = Path(".").push_many(*mod_path_stack);
+        let dir_path = prefix.push_many(mod_path.components);
         let file_path = match ::attr::first_attr_value_str_by_name(
                 outer_attrs, "path") {
             Some(d) => {
                 let path = Path(d);
                 if !path.is_absolute {
-                    mod_path.push(d)
+                    dir_path.push(d)
                 } else {
                     path
                 }
             }
-            None => mod_path.push(token::interner_get(id.name) + ".rs") // default
+            None => {
+                let mod_name = token::interner_get(id.name).to_owned();
+                let default_path_str = mod_name + ".rs";
+                let secondary_path_str = mod_name + "/mod.rs";
+                let default_path = dir_path.push(default_path_str);
+                let secondary_path = dir_path.push(secondary_path_str);
+                let default_exists = default_path.exists();
+                let secondary_exists = secondary_path.exists();
+                match (default_exists, secondary_exists) {
+                    (true, false) => default_path,
+                    (false, true) => secondary_path,
+                    (false, false) => {
+                        self.span_fatal(id_sp, fmt!("file not found for module `%s`", mod_name));
+                    }
+                    (true, true) => {
+                        self.span_fatal(id_sp,
+                                        fmt!("file for module `%s` found at both %s and %s",
+                                             mod_name, default_path_str, secondary_path_str));
+                    }
+                }
+            }
         };
 
-        self.eval_src_mod_from_path(prefix,
-                                    file_path,
+        self.eval_src_mod_from_path(file_path,
                                     outer_attrs.to_owned(),
                                     id_sp)
     }
 
     fn eval_src_mod_from_path(&self,
-                              prefix: Path,
                               path: Path,
                               outer_attrs: ~[ast::Attribute],
                               id_sp: span) -> (ast::item_, ~[ast::Attribute]) {
-
-        let full_path = if path.is_absolute {
-            path
-        } else {
-            prefix.push_many(path.components)
-        };
-        let full_path = full_path.normalize();
+        let full_path = path.normalize();
 
         let maybe_i = do self.sess.included_mod_stack.iter().position |p| { *p == full_path };
         match maybe_i {
diff --git a/src/test/compile-fail/mod_file_disambig.rs b/src/test/compile-fail/mod_file_disambig.rs
new file mode 100644
index 00000000000..48bd00a3ee0
--- /dev/null
+++ b/src/test/compile-fail/mod_file_disambig.rs
@@ -0,0 +1,15 @@
+// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+mod mod_file_disambig_aux; //~ ERROR file for module `mod_file_disambig_aux` found at both
+
+fn main() {
+    assert_eq!(mod_file_aux::bar(), 10);
+}
diff --git a/src/test/compile-fail/missingmod.rc b/src/test/compile-fail/mod_file_disambig_aux.rs
index 106b2907b92..ca5fc51337d 100644
--- a/src/test/compile-fail/missingmod.rc
+++ b/src/test/compile-fail/mod_file_disambig_aux.rs
@@ -8,6 +8,4 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-// error-pattern:error opening
-
-mod doesnotexist;
\ No newline at end of file
+// xfail-test not a test. aux file
diff --git a/src/test/compile-fail/mod_file_disambig_aux/mod.rs b/src/test/compile-fail/mod_file_disambig_aux/mod.rs
new file mode 100644
index 00000000000..ca5fc51337d
--- /dev/null
+++ b/src/test/compile-fail/mod_file_disambig_aux/mod.rs
@@ -0,0 +1,11 @@
+// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// xfail-test not a test. aux file
diff --git a/src/test/compile-fail/mod_file_not_exist.rs b/src/test/compile-fail/mod_file_not_exist.rs
index 9b16738e951..8391ff6fa39 100644
--- a/src/test/compile-fail/mod_file_not_exist.rs
+++ b/src/test/compile-fail/mod_file_not_exist.rs
@@ -8,7 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-mod not_a_real_file; //~ ERROR not_a_real_file.rs
+mod not_a_real_file; //~ ERROR file not found for module `not_a_real_file`
 
 fn main() {
     assert_eq!(mod_file_aux::bar(), 10);
diff --git a/src/test/run-pass/mod_dir_implicit.rs b/src/test/run-pass/mod_dir_implicit.rs
new file mode 100644
index 00000000000..eb5f72e59eb
--- /dev/null
+++ b/src/test/run-pass/mod_dir_implicit.rs
@@ -0,0 +1,18 @@
+// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// xfail-pretty
+// xfail-fast
+
+mod mod_dir_implicit_aux;
+
+pub fn main() {
+    assert_eq!(mod_dir_implicit_aux::foo(), 10);
+}
diff --git a/src/test/run-pass/mod_dir_implicit_aux/mod.rs b/src/test/run-pass/mod_dir_implicit_aux/mod.rs
new file mode 100644
index 00000000000..a3c1628725a
--- /dev/null
+++ b/src/test/run-pass/mod_dir_implicit_aux/mod.rs
@@ -0,0 +1,11 @@
+// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+pub fn foo() -> int { 10 }