Skip to content

Commit 8b57111

Browse files
committed
pretty=expanded should expand mod declarations
1 parent 5ab15cd commit 8b57111

File tree

4 files changed

+55
-6
lines changed

4 files changed

+55
-6
lines changed

src/libsyntax/parse/parser.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6204,10 +6204,9 @@ impl<'a> Parser<'a> {
62046204
// This mod is in an external file. Let's go get it!
62056205
let ModulePathSuccess { path, directory_ownership, warn } =
62066206
self.submod_path(id, &outer_attrs, id_span)?;
6207-
let (mut module, mut attrs) =
6207+
let (module, mut attrs) =
62086208
self.eval_src_mod(path, directory_ownership, id.to_string(), id_span)?;
62096209
// Record that we fetched the mod from an external file
6210-
module.inline = false;
62116210
if warn {
62126211
let attr = Attribute {
62136212
id: attr::mk_attr_id(),
@@ -6446,7 +6445,8 @@ impl<'a> Parser<'a> {
64466445
p0.cfg_mods = self.cfg_mods;
64476446
let mod_inner_lo = p0.span;
64486447
let mod_attrs = p0.parse_inner_attributes()?;
6449-
let m0 = p0.parse_mod_items(&token::Eof, mod_inner_lo)?;
6448+
let mut m0 = p0.parse_mod_items(&token::Eof, mod_inner_lo)?;
6449+
m0.inline = false;
64506450
self.sess.included_mod_stack.borrow_mut().pop();
64516451
Ok((m0, mod_attrs))
64526452
}

src/libsyntax/print/pprust.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ pub struct State<'a> {
6363
cur_cmnt: usize,
6464
boxes: Vec<pp::Breaks>,
6565
ann: &'a (dyn PpAnn+'a),
66+
is_expanded: bool
6667
}
6768

6869
fn rust_printer<'a>(writer: Box<dyn Write+'a>, ann: &'a dyn PpAnn) -> State<'a> {
@@ -74,6 +75,7 @@ fn rust_printer<'a>(writer: Box<dyn Write+'a>, ann: &'a dyn PpAnn) -> State<'a>
7475
cur_cmnt: 0,
7576
boxes: Vec::new(),
7677
ann,
78+
is_expanded: false
7779
}
7880
}
7981

@@ -135,14 +137,17 @@ impl<'a> State<'a> {
135137
// If the code is post expansion, don't use the table of
136138
// literals, since it doesn't correspond with the literals
137139
// in the AST anymore.
138-
if is_expanded { None } else { Some(lits) })
140+
if is_expanded { None } else { Some(lits) },
141+
is_expanded
142+
)
139143
}
140144

141145
pub fn new(cm: &'a CodeMap,
142146
out: Box<dyn Write+'a>,
143147
ann: &'a dyn PpAnn,
144148
comments: Option<Vec<comments::Comment>>,
145-
literals: Option<Vec<comments::Literal>>) -> State<'a> {
149+
literals: Option<Vec<comments::Literal>>,
150+
is_expanded: bool) -> State<'a> {
146151
State {
147152
s: pp::mk_printer(out, DEFAULT_COLUMNS),
148153
cm: Some(cm),
@@ -151,6 +156,7 @@ impl<'a> State<'a> {
151156
cur_cmnt: 0,
152157
boxes: Vec::new(),
153158
ann,
159+
is_expanded: is_expanded
154160
}
155161
}
156162
}
@@ -1263,7 +1269,8 @@ impl<'a> State<'a> {
12631269
self.head(&visibility_qualified(&item.vis, "mod"))?;
12641270
self.print_ident(item.ident)?;
12651271

1266-
if _mod.inline {
1272+
if _mod.inline || self.is_expanded {
1273+
println!("Going to print inline anyway");
12671274
self.nbsp()?;
12681275
self.bopen()?;
12691276
self.print_mod(_mod, &item.attrs)?;

src/test/pretty/issue_12590_c.pp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// pp-exact:issue_12590_c.pp
12+
// pretty-mode:expanded
13+
14+
// The next line should be expanded
15+
16+
mod issue_12590_b {
17+
18+
19+
fn b() { }
20+
21+
fn main() { }
22+
}
23+
24+
fn main() { }

src/test/pretty/issue_12590_c.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// pp-exact:issue_12590_c.pp
12+
// pretty-mode:expanded
13+
14+
// The next line should be expanded
15+
16+
mod issue_12590_b;
17+
18+
fn main() { }

0 commit comments

Comments
 (0)