about summary refs log tree commit diff
diff options
context:
space:
mode:
authorYacin Tmimi <yacintmimi@gmail.com>2024-05-06 13:26:54 -0400
committerYacin Tmimi <yacintmimi@gmail.com>2024-06-12 22:40:15 -0400
commit8e80f8aa3a2395d2bab4c4f62957fedf97da35b2 (patch)
treeb6e0e644ced17498765318566b870fec1a58cff9
parent8c4c336e37dd2125a23532111b11f6551205825e (diff)
downloadrust-8e80f8aa3a2395d2bab4c4f62957fedf97da35b2.tar.gz
rust-8e80f8aa3a2395d2bab4c4f62957fedf97da35b2.zip
don't apply formatting to builtin type ascription syntax
The syntax changed from `expr: ty` -> `builtin # type_ascribe(expr, ty)`
For now, rustfmt will just emit the contents of the span.
-rw-r--r--CHANGELOG.md7
-rw-r--r--src/expr.rs9
-rw-r--r--tests/target/issue_6159.rs3
3 files changed, 11 insertions, 8 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6d1701f90d7..fdb671ad4c2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,13 @@
 [bytecount#92]: https://github.com/llogiq/bytecount/pull/92
 [bytecount#93]: https://github.com/llogiq/bytecount/pull/93
 
+- Output correct syntax for type ascription builtin [#6159](https://github.com/rust-lang/rustfmt/issues/6159)
+  ```rust
+  fn main() {
+      builtin # type_ascribe(10, usize)
+  }
+  ```
+
 ## [1.7.0] 2023-10-22
 
 ### Fixed
diff --git a/src/expr.rs b/src/expr.rs
index f2fb2b4a83a..8266f95fd70 100644
--- a/src/expr.rs
+++ b/src/expr.rs
@@ -263,14 +263,6 @@ pub(crate) fn format_expr(
             shape,
             SeparatorPlace::Front,
         ),
-        ast::ExprKind::Type(ref expr, ref ty) => rewrite_pair(
-            &**expr,
-            &**ty,
-            PairParts::infix(": "),
-            context,
-            shape,
-            SeparatorPlace::Back,
-        ),
         ast::ExprKind::Index(ref expr, ref index, _) => {
             rewrite_index(&**expr, &**index, context, shape)
         }
@@ -412,6 +404,7 @@ pub(crate) fn format_expr(
         }
         ast::ExprKind::Underscore => Some("_".to_owned()),
         ast::ExprKind::FormatArgs(..)
+        | ast::ExprKind::Type(..)
         | ast::ExprKind::IncludedBytes(..)
         | ast::ExprKind::OffsetOf(..) => {
             // These don't normally occur in the AST because macros aren't expanded. However,
diff --git a/tests/target/issue_6159.rs b/tests/target/issue_6159.rs
new file mode 100644
index 00000000000..49fd539d3ef
--- /dev/null
+++ b/tests/target/issue_6159.rs
@@ -0,0 +1,3 @@
+fn main() {
+    builtin # type_ascribe(10, usize)
+}