diff options
| author | Eduard Burtescu <edy.burt@gmail.com> | 2014-02-14 07:07:09 +0200 |
|---|---|---|
| committer | Eduard Burtescu <edy.burt@gmail.com> | 2014-02-14 08:43:29 +0200 |
| commit | a02b10a0621adfe36eb3cc2e46f45fc7ccdb7ea2 (patch) | |
| tree | 86fe8ac57360a232b07c4303547194646129561a /src/libsyntax/ast_util.rs | |
| parent | 22c34f3c4cddea33b916eb92f8d7286b02b865a7 (diff) | |
| download | rust-a02b10a0621adfe36eb3cc2e46f45fc7ccdb7ea2.tar.gz rust-a02b10a0621adfe36eb3cc2e46f45fc7ccdb7ea2.zip | |
Refactored ast_map and friends, mainly to have Paths without storing them.
Diffstat (limited to 'src/libsyntax/ast_util.rs')
| -rw-r--r-- | src/libsyntax/ast_util.rs | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 56f690f0e2b..790f3927352 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -14,6 +14,7 @@ use ast_util; use codemap::Span; use opt_vec; use parse::token; +use print::pprust; use visit::Visitor; use visit; @@ -26,8 +27,7 @@ use std::local_data; pub fn path_name_i(idents: &[Ident]) -> ~str { // FIXME: Bad copies (#2543 -- same for everything else that says "bad") idents.map(|i| { - let string = token::get_ident(i.name); - string.get().to_str() + token::get_ident(*i).get().to_str() }).connect("::") } @@ -246,6 +246,23 @@ pub fn unguarded_pat(a: &Arm) -> Option<~[@Pat]> { } } +/// Generate a "pretty" name for an `impl` from its type and trait. +/// This is designed so that symbols of `impl`'d methods give some +/// hint of where they came from, (previously they would all just be +/// listed as `__extensions__::method_name::hash`, with no indication +/// of the type). +pub fn impl_pretty_name(trait_ref: &Option<TraitRef>, ty: &Ty) -> Ident { + let mut pretty = pprust::ty_to_str(ty); + match *trait_ref { + Some(ref trait_ref) => { + pretty.push_char('.'); + pretty.push_str(pprust::path_to_str(&trait_ref.path)); + } + None => {} + } + token::gensym_ident(pretty) +} + pub fn public_methods(ms: ~[@Method]) -> ~[@Method] { ms.move_iter().filter(|m| { match m.vis { |
