Skip to content

Suppress space after idents with "ModName" style in serialization of exported macros. #21542

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/libsyntax/print/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1164,11 +1164,20 @@ impl<'a> State<'a> {

pub fn print_tts(&mut self, tts: &[ast::TokenTree]) -> IoResult<()> {
try!(self.ibox(0));
let mut suppress_space = false;
for (i, tt) in tts.iter().enumerate() {
if i != 0 {
if i != 0 && !suppress_space {
try!(space(&mut self.s));
}
try!(self.print_tt(tt));
// There should be no space between the module name and the following `::` in paths,
// otherwise imported macros get re-parsed from crate metadata incorrectly (#20701)
suppress_space = match tt {
&ast::TtToken(_, token::Ident(_, token::ModName)) |
&ast::TtToken(_, token::MatchNt(_, _, _, token::ModName)) |
&ast::TtToken(_, token::SubstNt(_, token::ModName)) => true,
_ => false
}
}
self.end()
}
Expand Down
26 changes: 26 additions & 0 deletions src/test/auxiliary/macro_with_super_1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![crate_type = "lib"]

#[macro_export]
macro_rules! declare {
() => (
pub fn aaa() {}

pub mod bbb {
use super::aaa;

pub fn ccc() {
aaa();
}
}
)
}
20 changes: 20 additions & 0 deletions src/test/run-pass/macro_with_super_2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// aux-build:macro_with_super_1.rs

#[macro_use]
extern crate macro_with_super_1;

declare!();

fn main() {
bbb::ccc();
}