diff options
| author | Michael Bradshaw <mjbshaw@google.com> | 2018-09-29 19:51:09 -0700 |
|---|---|---|
| committer | Michael Bradshaw <mjbshaw@google.com> | 2018-09-29 19:51:09 -0700 |
| commit | 43cc32fbb2506eff0090e894c1e8a46b62a8eb0b (patch) | |
| tree | ac301fe1be819c25d833880da0ab32bf550016eb /src/libsyntax | |
| parent | aec5330082a0c4664abf0f6604c1b05768a90234 (diff) | |
| parent | 9653f790333d1270f36f1614e85d8a7b54193e75 (diff) | |
| download | rust-43cc32fbb2506eff0090e894c1e8a46b62a8eb0b.tar.gz rust-43cc32fbb2506eff0090e894c1e8a46b62a8eb0b.zip | |
Merge branch 'master' into drop
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/config.rs | 1 | ||||
| -rw-r--r-- | src/libsyntax/ext/build.rs | 1 | ||||
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 1 | ||||
| -rw-r--r-- | src/libsyntax/fold.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 17 | ||||
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 26 | ||||
| -rw-r--r-- | src/libsyntax/test.rs | 1 |
8 files changed, 41 insertions, 12 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index cd2efb4c747..9ed628e2ed3 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -1885,6 +1885,8 @@ pub struct Mod { /// to the last token in the external file. pub inner: Span, pub items: Vec<P<Item>>, + /// For `mod foo;` inline is false, for `mod foo { .. }` it is true. + pub inline: bool, } /// Foreign module declaration. diff --git a/src/libsyntax/config.rs b/src/libsyntax/config.rs index 3d9f4a92f81..a9ce2365577 100644 --- a/src/libsyntax/config.rs +++ b/src/libsyntax/config.rs @@ -90,6 +90,7 @@ impl<'a> StripUnconfigured<'a> { parser.expect(&token::Comma)?; let lo = parser.span.lo(); let (path, tokens) = parser.parse_meta_item_unrestricted()?; + parser.eat(&token::Comma); // Optional trailing comma parser.expect(&token::CloseDelim(token::Paren))?; Ok((cfg, path, tokens, parser.prev_span.with_lo(lo))) }) { diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index b1bed9602f3..6210003a40d 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -1101,6 +1101,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { ast::ItemKind::Mod(ast::Mod { inner: inner_span, items, + inline: true }) ) } diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 87c53d16875..52322e98d46 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -303,6 +303,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { krate.module = ast::Mod { inner: orig_mod_span, items: vec![], + inline: true, }; }, _ => unreachable!(), diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 3e422f5af81..95a2298ca75 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -1044,10 +1044,11 @@ pub fn noop_fold_fn_header<T: Folder>(mut header: FnHeader, folder: &mut T) -> F header } -pub fn noop_fold_mod<T: Folder>(Mod {inner, items}: Mod, folder: &mut T) -> Mod { +pub fn noop_fold_mod<T: Folder>(Mod {inner, items, inline}: Mod, folder: &mut T) -> Mod { Mod { inner: folder.new_span(inner), items: items.move_flat_map(|x| folder.fold_item(x)), + inline: inline, } } @@ -1077,6 +1078,7 @@ pub fn noop_fold_crate<T: Folder>(Crate {module, attrs, span}: Crate, None => (ast::Mod { inner: span, items: vec![], + inline: true, }, vec![], span) }; diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index d6cbe47a66e..5571a18b596 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -6297,6 +6297,7 @@ impl<'a> Parser<'a> { Ok(ast::Mod { inner: inner_lo.to(hi), items, + inline: true }) } @@ -6334,6 +6335,7 @@ impl<'a> Parser<'a> { self.submod_path(id, &outer_attrs, id_span)?; let (module, mut attrs) = self.eval_src_mod(path, directory_ownership, id.to_string(), id_span)?; + // Record that we fetched the mod from an external file if warn { let attr = Attribute { id: attr::mk_attr_id(), @@ -6346,9 +6348,13 @@ impl<'a> Parser<'a> { attr::mark_known(&attr); attrs.push(attr); } - Ok((id, module, Some(attrs))) + Ok((id, ItemKind::Mod(module), Some(attrs))) } else { - let placeholder = ast::Mod { inner: syntax_pos::DUMMY_SP, items: Vec::new() }; + let placeholder = ast::Mod { + inner: syntax_pos::DUMMY_SP, + items: Vec::new(), + inline: false + }; Ok((id, ItemKind::Mod(placeholder), None)) } } else { @@ -6548,7 +6554,7 @@ impl<'a> Parser<'a> { directory_ownership: DirectoryOwnership, name: String, id_sp: Span) - -> PResult<'a, (ast::ItemKind, Vec<Attribute> )> { + -> PResult<'a, (ast::Mod, Vec<Attribute> )> { let mut included_mod_stack = self.sess.included_mod_stack.borrow_mut(); if let Some(i) = included_mod_stack.iter().position(|p| *p == path) { let mut err = String::from("circular modules: "); @@ -6568,9 +6574,10 @@ impl<'a> Parser<'a> { p0.cfg_mods = self.cfg_mods; let mod_inner_lo = p0.span; let mod_attrs = p0.parse_inner_attributes()?; - let m0 = p0.parse_mod_items(&token::Eof, mod_inner_lo)?; + let mut m0 = p0.parse_mod_items(&token::Eof, mod_inner_lo)?; + m0.inline = false; self.sess.included_mod_stack.borrow_mut().pop(); - Ok((ast::ItemKind::Mod(m0), mod_attrs)) + Ok((m0, mod_attrs)) } /// Parse a function declaration from a foreign module diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 85d29a5be89..f2acdb3f469 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -61,6 +61,7 @@ pub struct State<'a> { cur_cmnt: usize, boxes: Vec<pp::Breaks>, ann: &'a (dyn PpAnn+'a), + is_expanded: bool } fn rust_printer<'a>(writer: Box<dyn Write+'a>, ann: &'a dyn PpAnn) -> State<'a> { @@ -72,6 +73,7 @@ fn rust_printer<'a>(writer: Box<dyn Write+'a>, ann: &'a dyn PpAnn) -> State<'a> cur_cmnt: 0, boxes: Vec::new(), ann, + is_expanded: false } } @@ -133,14 +135,17 @@ impl<'a> State<'a> { // If the code is post expansion, don't use the table of // literals, since it doesn't correspond with the literals // in the AST anymore. - if is_expanded { None } else { Some(lits) }) + if is_expanded { None } else { Some(lits) }, + is_expanded + ) } pub fn new(cm: &'a SourceMap, out: Box<dyn Write+'a>, ann: &'a dyn PpAnn, comments: Option<Vec<comments::Comment>>, - literals: Option<Vec<comments::Literal>>) -> State<'a> { + literals: Option<Vec<comments::Literal>>, + is_expanded: bool) -> State<'a> { State { s: pp::mk_printer(out, DEFAULT_COLUMNS), cm: Some(cm), @@ -149,6 +154,7 @@ impl<'a> State<'a> { cur_cmnt: 0, boxes: Vec::new(), ann, + is_expanded: is_expanded } } } @@ -1260,10 +1266,18 @@ impl<'a> State<'a> { ast::ItemKind::Mod(ref _mod) => { self.head(&visibility_qualified(&item.vis, "mod"))?; self.print_ident(item.ident)?; - self.nbsp()?; - self.bopen()?; - self.print_mod(_mod, &item.attrs)?; - self.bclose(item.span)?; + + if _mod.inline || self.is_expanded { + self.nbsp()?; + self.bopen()?; + self.print_mod(_mod, &item.attrs)?; + self.bclose(item.span)?; + } else { + self.s.word(";")?; + self.end()?; // end inner head-block + self.end()?; // end outer head-block + } + } ast::ItemKind::ForeignMod(ref nmod) => { self.head("extern")?; diff --git a/src/libsyntax/test.rs b/src/libsyntax/test.rs index 744e2e4a5fd..9f554a90afb 100644 --- a/src/libsyntax/test.rs +++ b/src/libsyntax/test.rs @@ -237,6 +237,7 @@ fn mk_reexport_mod(cx: &mut TestCtxt, })).collect(); let reexport_mod = ast::Mod { + inline: true, inner: DUMMY_SP, items, }; |
