about summary refs log tree commit diff
path: root/compiler/rustc_expand/src/module.rs
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2021-02-17 00:56:07 +0300
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2021-02-18 13:07:49 +0300
commit4a8816512477513f57986685738cd065e72c4908 (patch)
tree264d04ccc27f50e8b7f3e91402ba228e97af43c6 /compiler/rustc_expand/src/module.rs
parenteb65f15c7800930c3f74288974689d9884e51ba0 (diff)
downloadrust-4a8816512477513f57986685738cd065e72c4908.tar.gz
rust-4a8816512477513f57986685738cd065e72c4908.zip
ast: Keep expansion status for out-of-line module items
Also remove `ast::Mod` which is mostly redundant now
Diffstat (limited to 'compiler/rustc_expand/src/module.rs')
-rw-r--r--compiler/rustc_expand/src/module.rs23
1 files changed, 10 insertions, 13 deletions
diff --git a/compiler/rustc_expand/src/module.rs b/compiler/rustc_expand/src/module.rs
index d63625fea46..076d3b02be9 100644
--- a/compiler/rustc_expand/src/module.rs
+++ b/compiler/rustc_expand/src/module.rs
@@ -1,4 +1,5 @@
-use rustc_ast::{token, Attribute, Mod, Unsafe};
+use rustc_ast::ptr::P;
+use rustc_ast::{token, Attribute, Item};
 use rustc_errors::{struct_span_err, PResult};
 use rustc_parse::new_parser_from_file;
 use rustc_session::parse::ParseSess;
@@ -42,11 +43,10 @@ crate fn parse_external_mod(
     sess: &Session,
     id: Ident,
     span: Span, // The span to blame on errors.
-    unsafety: Unsafe,
     Directory { mut ownership, path }: Directory,
     attrs: &mut Vec<Attribute>,
     pop_mod_stack: &mut bool,
-) -> (Mod, Directory) {
+) -> (Vec<P<Item>>, Span, Directory) {
     // We bail on the first error, but that error does not cause a fatal error... (1)
     let result: PResult<'_, _> = try {
         // Extract the file path and the new ownership.
@@ -62,25 +62,22 @@ crate fn parse_external_mod(
 
         // Actually parse the external file as a module.
         let mut parser = new_parser_from_file(&sess.parse_sess, &mp.path, Some(span));
-        let (inner_attrs, items, inner) = parser.parse_mod(&token::Eof)?;
-        (Mod { unsafety, inline: false, items, inner }, inner_attrs)
+        let (mut inner_attrs, items, inner_span) = parser.parse_mod(&token::Eof)?;
+        attrs.append(&mut inner_attrs);
+        (items, inner_span)
     };
     // (1) ...instead, we return a dummy module.
-    let (module, mut new_attrs) = result.map_err(|mut err| err.emit()).unwrap_or_else(|_| {
-        let module = Mod { inner: Span::default(), unsafety, items: Vec::new(), inline: false };
-        (module, Vec::new())
-    });
-    attrs.append(&mut new_attrs);
+    let (items, inner_span) = result.map_err(|mut err| err.emit()).unwrap_or_default();
 
-    // Extract the directory path for submodules of `module`.
-    let path = sess.source_map().span_to_unmapped_path(module.inner);
+    // Extract the directory path for submodules of  the module.
+    let path = sess.source_map().span_to_unmapped_path(inner_span);
     let mut path = match path {
         FileName::Real(name) => name.into_local_path(),
         other => PathBuf::from(other.to_string()),
     };
     path.pop();
 
-    (module, Directory { ownership, path })
+    (items, inner_span, Directory { ownership, path })
 }
 
 fn error_on_circular_module<'a>(