From 45a83d18cc71fa4d7972d38c9302253ddec1c6cb Mon Sep 17 00:00:00 2001 From: Marcus Klaas Date: Fri, 15 Apr 2016 17:56:08 +0200 Subject: [PATCH] Format type ascription --- src/expr.rs | 5 +++-- tests/source/type-ascription.rs | 9 +++++++++ tests/target/type-ascription.rs | 14 ++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 tests/source/type-ascription.rs create mode 100644 tests/target/type-ascription.rs diff --git a/src/expr.rs b/src/expr.rs index a88e7ee6d19cc..b5be60cf05203 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -177,6 +177,9 @@ impl Rewrite for ast::Expr { ast::ExprKind::Cast(ref expr, ref ty) => { rewrite_pair(&**expr, &**ty, "", " as ", "", context, width, offset) } + ast::ExprKind::Type(ref expr, ref ty) => { + rewrite_pair(&**expr, &**ty, "", ": ", "", context, width, offset) + } ast::ExprKind::Index(ref expr, ref index) => { rewrite_pair(&**expr, &**index, "", "[", "]", context, width, offset) } @@ -210,8 +213,6 @@ impl Rewrite for ast::Expr { // satisfy our width restrictions. ast::ExprKind::InPlace(..) | ast::ExprKind::InlineAsm(..) | - // TODO(#848): Handle type ascription - ast::ExprKind::Type(_, _) | // TODO(#867): Handle try shorthand ast::ExprKind::Try(_) => { wrap_str(context.snippet(self.span), diff --git a/tests/source/type-ascription.rs b/tests/source/type-ascription.rs new file mode 100644 index 0000000000000..3b761f4fc784e --- /dev/null +++ b/tests/source/type-ascription.rs @@ -0,0 +1,9 @@ +fn main() { + let xxxxxxxxxxx = yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy : SomeTrait; + + let xxxxxxxxxxxxxxx = yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA; + + let z = funk(yyyyyyyyyyyyyyy, zzzzzzzzzzzzzzzz, wwwwww): AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA; + + x : u32 - 1u32 / 10f32 : u32 +} diff --git a/tests/target/type-ascription.rs b/tests/target/type-ascription.rs new file mode 100644 index 0000000000000..22f037133888a --- /dev/null +++ b/tests/target/type-ascription.rs @@ -0,0 +1,14 @@ +fn main() { + let xxxxxxxxxxx = yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy: SomeTrait; + + let xxxxxxxxxxxxxxx = + yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA; + + let z = funk(yyyyyyyyyyyyyyy, + zzzzzzzzzzzzzzzz, + wwwwww): AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA; + + x: u32 - 1u32 / 10f32: u32 +}