]> git.lizzy.rs Git - rust.git/blobdiff - src/modules.rs
discard trailing blank comments
[rust.git] / src / modules.rs
index 80a7e85c71def304fa72e688f384e22e082f780e..7619c0afa57a4f69fd8d7ff80014d8039eecd906 100644 (file)
 use std::path::{Path, PathBuf};
 
 use syntax::ast;
-use syntax::codemap::{self, FileName};
+use syntax::codemap;
 use syntax::parse::{parser, DirectoryOwnership};
+use syntax_pos::symbol::Symbol;
 
+use config::FileName;
 use utils::contains_skip;
 
 /// List all the files containing modules of a crate.
@@ -28,15 +30,30 @@ pub fn list_files<'a>(
     let root_filename = codemap.span_to_filename(krate.span);
     {
         let parent = match root_filename {
-            FileName::Real(ref path) => path.parent().unwrap(),
+            codemap::FileName::Real(ref path) => path.parent().unwrap(),
             _ => Path::new(""),
         };
         list_submodules(&krate.module, parent, None, codemap, &mut result)?;
     }
-    result.insert(root_filename, &krate.module);
+    result.insert(root_filename.into(), &krate.module);
     Ok(result)
 }
 
+fn path_value(attr: &ast::Attribute) -> Option<Symbol> {
+    if attr.name() == "path" {
+        attr.value_str()
+    } else {
+        None
+    }
+}
+
+// N.B. Even when there are multiple `#[path = ...]` attributes, we just need to
+// examine the first one, since rustc ignores the second and the subsequent ones
+// as unused attributes.
+fn find_path_value(attrs: &[ast::Attribute]) -> Option<Symbol> {
+    attrs.iter().flat_map(path_value).next()
+}
+
 /// Recursively list all external modules included in a module.
 fn list_submodules<'a>(
     module: &'a ast::Mod,
@@ -52,7 +69,11 @@ fn list_submodules<'a>(
                 let is_internal =
                     codemap.span_to_filename(item.span) == codemap.span_to_filename(sub_mod.inner);
                 let (dir_path, relative) = if is_internal {
-                    (search_dir.join(&item.ident.to_string()), None)
+                    if let Some(path) = find_path_value(&item.attrs) {
+                        (search_dir.join(&path.as_str()), None)
+                    } else {
+                        (search_dir.join(&item.ident.to_string()), None)
+                    }
                 } else {
                     let (mod_path, relative) =
                         module_file(item.ident, &item.attrs, search_dir, relative, codemap)?;