Skip to content

Commit

Permalink
Correctly stringify! types and paths inside macros
Browse files Browse the repository at this point in the history
Closes #8709
  • Loading branch information
Sawyer47 committed Jul 20, 2014
1 parent 44a71de commit 20df4cc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/libsyntax/parse/token.rs
Expand Up @@ -249,6 +249,8 @@ pub fn to_string(t: &Token) -> String {
match nt {
&NtExpr(ref e) => ::print::pprust::expr_to_string(&**e),
&NtMeta(ref e) => ::print::pprust::meta_item_to_string(&**e),
&NtTy(ref e) => ::print::pprust::ty_to_string(&**e),
&NtPath(ref e) => ::print::pprust::path_to_string(&**e),
_ => {
let mut s = "an interpolated ".to_string();
match *nt {
Expand All @@ -257,10 +259,10 @@ pub fn to_string(t: &Token) -> String {
NtStmt(..) => s.push_str("statement"),
NtPat(..) => s.push_str("pattern"),
NtMeta(..) => fail!("should have been handled"),
NtExpr(..) => fail!("should have been handled above"),
NtTy(..) => s.push_str("type"),
NtExpr(..) => fail!("should have been handled"),
NtTy(..) => fail!("should have been handled"),
NtIdent(..) => s.push_str("identifier"),
NtPath(..) => s.push_str("path"),
NtPath(..) => fail!("should have been handled"),
NtTT(..) => s.push_str("tt"),
NtMatchers(..) => s.push_str("matcher sequence")
};
Expand Down
24 changes: 24 additions & 0 deletions src/test/run-pass/issue-8709.rs
@@ -0,0 +1,24 @@
// Copyright 2014 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.

#![feature(macro_rules)]

macro_rules! sty(
($t:ty) => (stringify!($t))
)

macro_rules! spath(
($t:path) => (stringify!($t))
)

fn main() {
assert_eq!(sty!(int), "int")
assert_eq!(spath!(std::option), "std::option")
}

5 comments on commit 20df4cc

@bors
Copy link
Contributor

@bors bors commented on 20df4cc Jul 20, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton
at Sawyer47@20df4cc

@bors
Copy link
Contributor

@bors bors commented on 20df4cc Jul 20, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging Sawyer47/rust/issue-8709 = 20df4cc into auto

@bors
Copy link
Contributor

@bors bors commented on 20df4cc Jul 20, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sawyer47/rust/issue-8709 = 20df4cc merged ok, testing candidate = c4dd47d

@bors
Copy link
Contributor

@bors bors commented on 20df4cc Jul 20, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = c4dd47d

Please sign in to comment.