Skip to content

Commit 81a8ee8

Browse files
committed
pretty=expanded should expand mod declarations
1 parent c3afb16 commit 81a8ee8

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
@@ -6288,10 +6288,9 @@ impl<'a> Parser<'a> {
62886288
// This mod is in an external file. Let's go get it!
62896289
let ModulePathSuccess { path, directory_ownership, warn } =
62906290
self.submod_path(id, &outer_attrs, id_span)?;
6291-
let (mut module, mut attrs) =
6291+
let (module, mut attrs) =
62926292
self.eval_src_mod(path, directory_ownership, id.to_string(), id_span)?;
62936293
// Record that we fetched the mod from an external file
6294-
module.inline = false;
62956294
if warn {
62966295
let attr = Attribute {
62976296
id: attr::mk_attr_id(),
@@ -6530,7 +6529,8 @@ impl<'a> Parser<'a> {
65306529
p0.cfg_mods = self.cfg_mods;
65316530
let mod_inner_lo = p0.span;
65326531
let mod_attrs = p0.parse_inner_attributes()?;
6533-
let m0 = p0.parse_mod_items(&token::Eof, mod_inner_lo)?;
6532+
let mut m0 = p0.parse_mod_items(&token::Eof, mod_inner_lo)?;
6533+
m0.inline = false;
65346534
self.sess.included_mod_stack.borrow_mut().pop();
65356535
Ok((m0, mod_attrs))
65366536
}

src/libsyntax/print/pprust.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ pub struct State<'a> {
6161
cur_cmnt: usize,
6262
boxes: Vec<pp::Breaks>,
6363
ann: &'a (dyn PpAnn+'a),
64+
is_expanded: bool
6465
}
6566

6667
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>
7273
cur_cmnt: 0,
7374
boxes: Vec::new(),
7475
ann,
76+
is_expanded: false
7577
}
7678
}
7779

@@ -133,14 +135,17 @@ impl<'a> State<'a> {
133135
// If the code is post expansion, don't use the table of
134136
// literals, since it doesn't correspond with the literals
135137
// in the AST anymore.
136-
if is_expanded { None } else { Some(lits) })
138+
if is_expanded { None } else { Some(lits) },
139+
is_expanded
140+
)
137141
}
138142

139143
pub fn new(cm: &'a SourceMap,
140144
out: Box<dyn Write+'a>,
141145
ann: &'a dyn PpAnn,
142146
comments: Option<Vec<comments::Comment>>,
143-
literals: Option<Vec<comments::Literal>>) -> State<'a> {
147+
literals: Option<Vec<comments::Literal>>,
148+
is_expanded: bool) -> State<'a> {
144149
State {
145150
s: pp::mk_printer(out, DEFAULT_COLUMNS),
146151
cm: Some(cm),
@@ -149,6 +154,7 @@ impl<'a> State<'a> {
149154
cur_cmnt: 0,
150155
boxes: Vec::new(),
151156
ann,
157+
is_expanded: is_expanded
152158
}
153159
}
154160
}
@@ -1261,7 +1267,8 @@ impl<'a> State<'a> {
12611267
self.head(&visibility_qualified(&item.vis, "mod"))?;
12621268
self.print_ident(item.ident)?;
12631269

1264-
if _mod.inline {
1270+
if _mod.inline || self.is_expanded {
1271+
println!("Going to print inline anyway");
12651272
self.nbsp()?;
12661273
self.bopen()?;
12671274
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)