about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2020-03-08 12:33:15 +0100
committerMazdak Farrokhzad <twingoow@gmail.com>2020-03-18 15:08:25 +0100
commit463995fe2974e2473392ddf7be8699746f6b7dac (patch)
tree2fff007ad240131048a27705b58bca1134ef173e
parent8bab88f2d9d1c81ab8d80d903359900ef106d21e (diff)
downloadrust-463995fe2974e2473392ddf7be8699746f6b7dac.tar.gz
rust-463995fe2974e2473392ddf7be8699746f6b7dac.zip
extract parse_external_module
-rw-r--r--src/librustc_parse/parser/module.rs20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/librustc_parse/parser/module.rs b/src/librustc_parse/parser/module.rs
index 8f99d88b8e4..0701b733076 100644
--- a/src/librustc_parse/parser/module.rs
+++ b/src/librustc_parse/parser/module.rs
@@ -44,12 +44,8 @@ impl<'a> Parser<'a> {
         let id = self.parse_ident()?;
         let (module, mut inner_attrs) = if self.eat(&token::Semi) {
             if in_cfg && self.recurse_into_file_modules {
-                // This mod is in an external file. Let's go get it!
                 let dir = &self.directory;
-                submod_path(self.sess, id, &attrs, dir.ownership, &dir.path)
-                    .and_then(|r| eval_src_mod(self.sess, self.cfg_mods, r.path, r.ownership, id))
-                    .map_err(|mut err| err.emit())
-                    .unwrap_or_default()
+                parse_external_module(self.sess, self.cfg_mods, id, dir.ownership, &dir.path, attrs)
             } else {
                 Default::default()
             }
@@ -99,6 +95,20 @@ impl<'a> Parser<'a> {
     }
 }
 
+fn parse_external_module(
+    sess: &ParseSess,
+    cfg_mods: bool,
+    id: ast::Ident,
+    ownership: DirectoryOwnership,
+    dir_path: &Path,
+    attrs: &[Attribute],
+) -> (Mod, Vec<Attribute>) {
+    submod_path(sess, id, &attrs, ownership, dir_path)
+        .and_then(|r| eval_src_mod(sess, cfg_mods, r.path, r.ownership, id))
+        .map_err(|mut err| err.emit())
+        .unwrap_or_default()
+}
+
 /// Reads a module from a source file.
 fn eval_src_mod<'a>(
     sess: &'a ParseSess,