about summary refs log tree commit diff
path: root/src/librustc_parse/parser
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2020-03-07 18:59:44 +0100
committerMazdak Farrokhzad <twingoow@gmail.com>2020-03-18 15:08:25 +0100
commitbc75cba23feb45b2d1b67ee07e6eb8264c0d5fd6 (patch)
tree1866a728959946e04a84c1c4fdbcf94ecb336f42 /src/librustc_parse/parser
parentf509b26a7730d721ef87423a72b3fdf8724b4afa (diff)
downloadrust-bc75cba23feb45b2d1b67ee07e6eb8264c0d5fd6.tar.gz
rust-bc75cba23feb45b2d1b67ee07e6eb8264c0d5fd6.zip
submod_path_from_attr: simplify & document
Diffstat (limited to 'src/librustc_parse/parser')
-rw-r--r--src/librustc_parse/parser/module.rs25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/librustc_parse/parser/module.rs b/src/librustc_parse/parser/module.rs
index 7b46601cc7d..4965615c64c 100644
--- a/src/librustc_parse/parser/module.rs
+++ b/src/librustc_parse/parser/module.rs
@@ -179,21 +179,22 @@ impl<'a> Parser<'a> {
         }
     }
 
+    /// Derive a submodule path from the first found `#[path = "path_string"]`.
+    /// The provided `dir_path` is joined with the `path_string`.
     // Public for rustfmt usage.
     pub fn submod_path_from_attr(attrs: &[Attribute], dir_path: &Path) -> Option<PathBuf> {
-        if let Some(s) = attr::first_attr_value_str_by_name(attrs, sym::path) {
-            let s = s.as_str();
+        // Extract path string from first `#[path = "path_string"]` attribute.
+        let path_string = attr::first_attr_value_str_by_name(attrs, sym::path)?;
+        let path_string = path_string.as_str();
 
-            // On windows, the base path might have the form
-            // `\\?\foo\bar` in which case it does not tolerate
-            // mixed `/` and `\` separators, so canonicalize
-            // `/` to `\`.
-            #[cfg(windows)]
-            let s = s.replace("/", "\\");
-            Some(dir_path.join(&*s))
-        } else {
-            None
-        }
+        // On windows, the base path might have the form
+        // `\\?\foo\bar` in which case it does not tolerate
+        // mixed `/` and `\` separators, so canonicalize
+        // `/` to `\`.
+        #[cfg(windows)]
+        let path_string = path_string.replace("/", "\\");
+
+        Some(dir_path.join(&*path_string))
     }
 
     /// Returns a path to a module.