diff options
| author | John Clements <clements@racket-lang.org> | 2014-06-30 18:02:14 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-07-03 12:54:51 -0700 |
| commit | e38cb972dcfc0fdab44270257eac3405a39bd996 (patch) | |
| tree | f45affb2ba2b0e35e03f102755103f93063ac9e5 /src/libsyntax/print/pprust.rs | |
| parent | cff79ab5633f0900eb71a53ccb924632f7b1090c (diff) | |
| download | rust-e38cb972dcfc0fdab44270257eac3405a39bd996.tar.gz rust-e38cb972dcfc0fdab44270257eac3405a39bd996.zip | |
Simplify PatIdent to contain an Ident rather than a Path
Rationale: for what appear to be historical reasons only, the PatIdent contains a Path rather than an Ident. This means that there are many places in the code where an ident is artificially promoted to a path, and---much more problematically--- a bunch of elements from a path are simply thrown away, which seems like an invitation to some really nasty bugs. This commit replaces the Path in a PatIdent with a SpannedIdent, which just contains an ident and a span.
Diffstat (limited to 'src/libsyntax/print/pprust.rs')
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index a9cf4fbd9f0..4660bb337ab 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -196,6 +196,10 @@ pub fn path_to_str(p: &ast::Path) -> String { to_str(|s| s.print_path(p, false)) } +pub fn ident_to_str(id: &ast::Ident) -> String { + to_str(|s| s.print_ident(*id)) +} + pub fn fun_to_str(decl: &ast::FnDecl, fn_style: ast::FnStyle, name: ast::Ident, opt_explicit_self: Option<ast::ExplicitSelf_>, generics: &ast::Generics) -> String { @@ -1705,7 +1709,7 @@ impl<'a> State<'a> { match pat.node { ast::PatWild => try!(word(&mut self.s, "_")), ast::PatWildMulti => try!(word(&mut self.s, "..")), - ast::PatIdent(binding_mode, ref path, sub) => { + ast::PatIdent(binding_mode, ref path1, sub) => { match binding_mode { ast::BindByRef(mutbl) => { try!(self.word_nbsp("ref")); @@ -1716,7 +1720,7 @@ impl<'a> State<'a> { try!(self.word_nbsp("mut")); } } - try!(self.print_path(path, true)); + try!(self.print_ident(path1.node)); match sub { Some(ref p) => { try!(word(&mut self.s, "@")); @@ -2148,9 +2152,8 @@ impl<'a> State<'a> { ast::TyInfer => try!(self.print_pat(&*input.pat)), _ => { match input.pat.node { - ast::PatIdent(_, ref path, _) if - path.segments.len() == 1 && - path.segments.get(0).identifier.name == + ast::PatIdent(_, ref path1, _) if + path1.node.name == parse::token::special_idents::invalid.name => { // Do nothing. } |
