diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2013-08-10 16:50:42 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2013-08-12 23:18:51 -0700 |
| commit | 1f6afa887b9fbaadda36ce57a3c296f43ed8a084 (patch) | |
| tree | 4288b946747ca74367b21301bb609f23b5ffdf40 /src/libsyntax/ext | |
| parent | 6feb58ed84d8dce2aea35a8be9fd8d7b6883f002 (diff) | |
| download | rust-1f6afa887b9fbaadda36ce57a3c296f43ed8a084.tar.gz rust-1f6afa887b9fbaadda36ce57a3c296f43ed8a084.zip | |
Correct the padding on integer types for formatting
Diffstat (limited to 'src/libsyntax/ext')
| -rw-r--r-- | src/libsyntax/ext/ifmt.rs | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/libsyntax/ext/ifmt.rs b/src/libsyntax/ext/ifmt.rs index 6dda3fc26e8..2d839f652d5 100644 --- a/src/libsyntax/ext/ifmt.rs +++ b/src/libsyntax/ext/ifmt.rs @@ -317,6 +317,10 @@ impl Context { /// Translate a `parse::Piece` to a static `rt::Piece` fn trans_piece(&mut self, piece: &parse::Piece) -> @ast::expr { let sp = self.fmtsp; + let parsepath = |s: &str| { + ~[self.ecx.ident_of("std"), self.ecx.ident_of("fmt"), + self.ecx.ident_of("parse"), self.ecx.ident_of(s)] + }; let rtpath = |s: &str| { ~[self.ecx.ident_of("std"), self.ecx.ident_of("fmt"), self.ecx.ident_of("rt"), self.ecx.ident_of(s)] @@ -482,20 +486,24 @@ impl Context { let fill = self.ecx.expr_lit(sp, ast::lit_int(fill as i64, ast::ty_char)); let align = match arg.format.align { - None | Some(parse::AlignLeft) => { - self.ecx.expr_bool(sp, true) + parse::AlignLeft => { + self.ecx.path_global(sp, parsepath("AlignLeft")) + } + parse::AlignRight => { + self.ecx.path_global(sp, parsepath("AlignRight")) } - Some(parse::AlignRight) => { - self.ecx.expr_bool(sp, false) + parse::AlignUnknown => { + self.ecx.path_global(sp, parsepath("AlignUnknown")) } }; + let align = self.ecx.expr_path(align); let flags = self.ecx.expr_uint(sp, arg.format.flags); let prec = trans_count(arg.format.precision); let width = trans_count(arg.format.width); let path = self.ecx.path_global(sp, rtpath("FormatSpec")); let fmt = self.ecx.expr_struct(sp, path, ~[ self.ecx.field_imm(sp, self.ecx.ident_of("fill"), fill), - self.ecx.field_imm(sp, self.ecx.ident_of("alignleft"), align), + self.ecx.field_imm(sp, self.ecx.ident_of("align"), align), self.ecx.field_imm(sp, self.ecx.ident_of("flags"), flags), self.ecx.field_imm(sp, self.ecx.ident_of("precision"), prec), self.ecx.field_imm(sp, self.ecx.ident_of("width"), width), |
