diff options
| author | Brian Anderson <banderson@mozilla.com> | 2013-07-19 19:11:30 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2013-07-21 19:32:24 -0700 |
| commit | a74d92e8ab61863876d2b5b6256b403efbb55492 (patch) | |
| tree | 0c38ed6c3a087fc555f54709791f983e97ce1905 /src/libsyntax/parse | |
| parent | fe3f75ff8e2a7e750713295f5fa17a4abf9d9d62 (diff) | |
| download | rust-a74d92e8ab61863876d2b5b6256b403efbb55492.tar.gz rust-a74d92e8ab61863876d2b5b6256b403efbb55492.zip | |
syntax: Bless mod.rs. #4116
When loading a module the parser will look for either foo.rs or foo/mod.rs and generate an error when both are found.
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 37 |
1 files changed, 25 insertions, 12 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 { |
