Skip to content

Commit 56a6394

Browse files
author
wickerwaka
committed
---
yaml --- r: 130487 b: refs/heads/try c: 2bc4a5e h: refs/heads/master i: 130485: fc39560 130483: 05cd1d4 130479: c03bcdc v: v3
1 parent 8b8a129 commit 56a6394

File tree

11 files changed

+75
-87
lines changed

11 files changed

+75
-87
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: c964cb229bd342bdeb0b4506c3a6d32b03e575f6
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 67b97ab6d2b7de9b69fd97dc171fcf8feec932ff
5-
refs/heads/try: 8d5e64f3bc2f754bed4b5a1857dd3494c5049c50
5+
refs/heads/try: 2bc4a5e92aef51bd34a5b1a506c5edcee893d6ac
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/libcore/fmt/mod.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -461,19 +461,28 @@ impl<'a> Formatter<'a> {
461461
use char::Char;
462462
let align = match self.align {
463463
rt::AlignUnknown => default,
464-
rt::AlignLeft | rt::AlignRight => self.align
464+
_ => self.align
465465
};
466-
if align == rt::AlignLeft {
467-
try!(f(self));
468-
}
466+
467+
let (pre_pad, post_pad) = match align {
468+
rt::AlignLeft => (0u, padding),
469+
rt::AlignRight | rt::AlignUnknown => (padding, 0u),
470+
rt::AlignCenter => (padding / 2, (padding + 1) / 2),
471+
};
472+
469473
let mut fill = [0u8, ..4];
470474
let len = self.fill.encode_utf8(fill).unwrap_or(0);
471-
for _ in range(0, padding) {
475+
476+
for _ in range(0, pre_pad) {
472477
try!(self.buf.write(fill.slice_to(len)));
473478
}
474-
if align == rt::AlignRight {
475-
try!(f(self));
479+
480+
try!(f(self));
481+
482+
for _ in range(0, post_pad) {
483+
try!(self.buf.write(fill.slice_to(len)));
476484
}
485+
477486
Ok(())
478487
}
479488

branches/try/src/libcore/fmt/rt.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ pub enum Alignment {
4343
AlignLeft,
4444
/// Indication that contents should be right-aligned.
4545
AlignRight,
46+
/// Indication that contents should be center-aligned.
47+
AlignCenter,
4648
/// No alignment was requested.
4749
AlignUnknown,
4850
}

branches/try/src/libfmt_macros/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ pub enum Alignment {
8181
AlignLeft,
8282
/// The value will be aligned to the right.
8383
AlignRight,
84+
/// The value will be aligned in the center.
85+
AlignCenter,
8486
/// The value will take on a default alignment.
8587
AlignUnknown,
8688
}
@@ -279,7 +281,7 @@ impl<'a> Parser<'a> {
279281
match self.cur.clone().next() {
280282
Some((_, c)) => {
281283
match self.cur.clone().skip(1).next() {
282-
Some((_, '>')) | Some((_, '<')) => {
284+
Some((_, '>')) | Some((_, '<')) | Some((_, '^')) => {
283285
spec.fill = Some(c);
284286
self.cur.next();
285287
}
@@ -293,6 +295,8 @@ impl<'a> Parser<'a> {
293295
spec.align = AlignLeft;
294296
} else if self.consume('>') {
295297
spec.align = AlignRight;
298+
} else if self.consume('^') {
299+
spec.align = AlignCenter;
296300
}
297301
// Sign flags
298302
if self.consume('+') {

branches/try/src/liblibc/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4542,7 +4542,7 @@ pub mod funcs {
45424542
pub fn glob(pattern: *const c_char,
45434543
flags: c_int,
45444544
errfunc: ::Nullable<extern "C" fn(epath: *const c_char,
4545-
errno: c_int) -> c_int>,
4545+
errno: c_int) -> int>,
45464546
pglob: *mut glob_t);
45474547
pub fn globfree(pglob: *mut glob_t);
45484548
}

branches/try/src/librustc/lint/builtin.rs

Lines changed: 40 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ use syntax::attr;
4545
use syntax::codemap::Span;
4646
use syntax::parse::token;
4747
use syntax::{ast, ast_util, visit};
48-
use syntax::visit::Visitor;
4948

5049
declare_lint!(WHILE_TRUE, Warn,
5150
"suggest using `loop { }` instead of `while true { }`")
@@ -340,51 +339,6 @@ impl LintPass for TypeLimits {
340339
declare_lint!(CTYPES, Warn,
341340
"proper use of libc types in foreign modules")
342341

343-
struct CTypesVisitor<'a> {
344-
cx: &'a Context<'a>
345-
}
346-
347-
impl<'a> CTypesVisitor<'a> {
348-
fn check_def(&mut self, sp: Span, ty_id: ast::NodeId, path_id: ast::NodeId) {
349-
match self.cx.tcx.def_map.borrow().get_copy(&path_id) {
350-
def::DefPrimTy(ast::TyInt(ast::TyI)) => {
351-
self.cx.span_lint(CTYPES, sp,
352-
"found rust type `int` in foreign module, while \
353-
libc::c_int or libc::c_long should be used");
354-
}
355-
def::DefPrimTy(ast::TyUint(ast::TyU)) => {
356-
self.cx.span_lint(CTYPES, sp,
357-
"found rust type `uint` in foreign module, while \
358-
libc::c_uint or libc::c_ulong should be used");
359-
}
360-
def::DefTy(..) => {
361-
let tty = match self.cx.tcx.ast_ty_to_ty_cache.borrow().find(&ty_id) {
362-
Some(&ty::atttce_resolved(t)) => t,
363-
_ => fail!("ast_ty_to_ty_cache was incomplete after typeck!")
364-
};
365-
366-
if !ty::is_ffi_safe(self.cx.tcx, tty) {
367-
self.cx.span_lint(CTYPES, sp,
368-
"found type without foreign-function-safe
369-
representation annotation in foreign module, consider \
370-
adding a #[repr(...)] attribute to the type");
371-
}
372-
}
373-
_ => ()
374-
}
375-
}
376-
}
377-
378-
impl<'a> Visitor<()> for CTypesVisitor<'a> {
379-
fn visit_ty(&mut self, ty: &ast::Ty, _: ()) {
380-
match ty.node {
381-
ast::TyPath(_, _, id) => self.check_def(ty.span, ty.id, id),
382-
_ => (),
383-
}
384-
visit::walk_ty(self, ty, ());
385-
}
386-
}
387-
388342
pub struct CTypes;
389343

390344
impl LintPass for CTypes {
@@ -394,8 +348,38 @@ impl LintPass for CTypes {
394348

395349
fn check_item(&mut self, cx: &Context, it: &ast::Item) {
396350
fn check_ty(cx: &Context, ty: &ast::Ty) {
397-
let mut vis = CTypesVisitor { cx: cx };
398-
vis.visit_ty(ty, ());
351+
match ty.node {
352+
ast::TyPath(_, _, id) => {
353+
match cx.tcx.def_map.borrow().get_copy(&id) {
354+
def::DefPrimTy(ast::TyInt(ast::TyI)) => {
355+
cx.span_lint(CTYPES, ty.span,
356+
"found rust type `int` in foreign module, while \
357+
libc::c_int or libc::c_long should be used");
358+
}
359+
def::DefPrimTy(ast::TyUint(ast::TyU)) => {
360+
cx.span_lint(CTYPES, ty.span,
361+
"found rust type `uint` in foreign module, while \
362+
libc::c_uint or libc::c_ulong should be used");
363+
}
364+
def::DefTy(..) => {
365+
let tty = match cx.tcx.ast_ty_to_ty_cache.borrow().find(&ty.id) {
366+
Some(&ty::atttce_resolved(t)) => t,
367+
_ => fail!("ast_ty_to_ty_cache was incomplete after typeck!")
368+
};
369+
370+
if !ty::is_ffi_safe(cx.tcx, tty) {
371+
cx.span_lint(CTYPES, ty.span,
372+
"found type without foreign-function-safe
373+
representation annotation in foreign module, consider \
374+
adding a #[repr(...)] attribute to the type");
375+
}
376+
}
377+
_ => ()
378+
}
379+
}
380+
ast::TyPtr(ref mt) => { check_ty(cx, &*mt.ty) }
381+
_ => {}
382+
}
399383
}
400384

401385
fn check_foreign_fn(cx: &Context, decl: &ast::FnDecl) {
@@ -406,15 +390,15 @@ impl LintPass for CTypes {
406390
}
407391

408392
match it.node {
409-
ast::ItemForeignMod(ref nmod) if nmod.abi != abi::RustIntrinsic => {
410-
for ni in nmod.items.iter() {
411-
match ni.node {
412-
ast::ForeignItemFn(decl, _) => check_foreign_fn(cx, &*decl),
413-
ast::ForeignItemStatic(t, _) => check_ty(cx, &*t)
414-
}
393+
ast::ItemForeignMod(ref nmod) if nmod.abi != abi::RustIntrinsic => {
394+
for ni in nmod.items.iter() {
395+
match ni.node {
396+
ast::ForeignItemFn(decl, _) => check_foreign_fn(cx, &*decl),
397+
ast::ForeignItemStatic(t, _) => check_ty(cx, &*t)
415398
}
416399
}
417-
_ => (),
400+
}
401+
_ => {/* nothing to do */ }
418402
}
419403
}
420404
}
@@ -509,7 +493,7 @@ struct RawPtrDerivingVisitor<'a> {
509493
cx: &'a Context<'a>
510494
}
511495

512-
impl<'a> Visitor<()> for RawPtrDerivingVisitor<'a> {
496+
impl<'a> visit::Visitor<()> for RawPtrDerivingVisitor<'a> {
513497
fn visit_ty(&mut self, ty: &ast::Ty, _: ()) {
514498
static MSG: &'static str = "use of `#[deriving]` with a raw pointer";
515499
match ty.node {

branches/try/src/libstd/fmt.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ argument := integer | identifier
333333
334334
format_spec := [[fill]align][sign]['#'][0][width]['.' precision][type]
335335
fill := character
336-
align := '<' | '>'
336+
align := '<' | '^' | '>'
337337
sign := '+' | '-'
338338
width := count
339339
precision := count | '*'
@@ -357,6 +357,7 @@ parameter. This indicates that if the value being formatted is smaller than
357357
are specified by `fill`, and the alignment can be one of two options:
358358
359359
* `<` - the argument is left-aligned in `width` columns
360+
* `^` - the argument is center-aligned in `width` columns
360361
* `>` - the argument is right-aligned in `width` columns
361362
362363
### Sign/#/0

branches/try/src/libsyntax/ext/format.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,9 @@ impl<'a, 'b> Context<'a, 'b> {
430430
parse::AlignRight => {
431431
self.ecx.path_global(sp, self.rtpath("AlignRight"))
432432
}
433+
parse::AlignCenter => {
434+
self.ecx.path_global(sp, self.rtpath("AlignCenter"))
435+
}
433436
parse::AlignUnknown => {
434437
self.ecx.path_global(sp, self.rtpath("AlignUnknown"))
435438
}

branches/try/src/libtime/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,6 @@ pub fn tzset() {
232232

233233
/// Holds a calendar date and time broken down into its components (year, month, day, and so on),
234234
/// also called a broken-down time value.
235-
// FIXME: use c_int instead of i32?
236-
#[repr(C)]
237235
#[deriving(Clone, PartialEq, Eq, Show)]
238236
pub struct Tm {
239237
/// Seconds after the minute - [0, 60]

branches/try/src/test/compile-fail/issue-16250.rs

Lines changed: 0 additions & 18 deletions
This file was deleted.

branches/try/src/test/run-pass/ifmt.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,16 @@ pub fn main() {
9090
t!(format!("{:4s}", "a"), "a ");
9191
t!(format!("{:>4s}", "a"), " a");
9292
t!(format!("{:<4s}", "a"), "a ");
93+
t!(format!("{:^5s}", "a"), " a ");
94+
t!(format!("{:^5s}", "aa"), " aa ");
95+
t!(format!("{:^4s}", "a"), " a ");
96+
t!(format!("{:^4s}", "aa"), " aa ");
9397
t!(format!("{:.4s}", "a"), "a");
9498
t!(format!("{:4.4s}", "a"), "a ");
9599
t!(format!("{:4.4s}", "aaaaaaaaaaaaaaaaaa"), "aaaa");
96100
t!(format!("{:<4.4s}", "aaaaaaaaaaaaaaaaaa"), "aaaa");
97101
t!(format!("{:>4.4s}", "aaaaaaaaaaaaaaaaaa"), "aaaa");
102+
t!(format!("{:^4.4s}", "aaaaaaaaaaaaaaaaaa"), "aaaa");
98103
t!(format!("{:>10.4s}", "aaaaaaaaaaaaaaaaaa"), "aaaa");
99104
t!(format!("{:2.4s}", "aaaaa"), "aaaa");
100105
t!(format!("{:2.4s}", "aaaa"), "aaaa");

0 commit comments

Comments
 (0)