Skip to content

Commit 35ad744

Browse files
committed
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.
1 parent 919fb28 commit 35ad744

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
[bytecount#92]: https://github.com/llogiq/bytecount/pull/92
99
[bytecount#93]: https://github.com/llogiq/bytecount/pull/93
1010

11+
- Output correct syntax for type ascription builtin [#6159](https://github.com/rust-lang/rustfmt/issues/6159)
12+
```rust
13+
fn main() {
14+
builtin # type_ascribe(10, usize)
15+
}
16+
```
1117

1218
## [1.7.0] 2023-10-22
1319

src/expr.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -253,14 +253,6 @@ pub(crate) fn format_expr(
253253
shape,
254254
SeparatorPlace::Front,
255255
),
256-
ast::ExprKind::Type(ref expr, ref ty) => rewrite_pair(
257-
&**expr,
258-
&**ty,
259-
PairParts::infix(": "),
260-
context,
261-
shape,
262-
SeparatorPlace::Back,
263-
),
264256
ast::ExprKind::Index(ref expr, ref index, _) => {
265257
rewrite_index(&**expr, &**index, context, shape)
266258
}
@@ -402,6 +394,7 @@ pub(crate) fn format_expr(
402394
}
403395
ast::ExprKind::Underscore => Some("_".to_owned()),
404396
ast::ExprKind::FormatArgs(..)
397+
| ast::ExprKind::Type(..)
405398
| ast::ExprKind::IncludedBytes(..)
406399
| ast::ExprKind::OffsetOf(..) => {
407400
// These don't normally occur in the AST because macros aren't expanded. However,

tests/target/issue_6159.rs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
builtin # type_ascribe(10, usize)
3+
}

0 commit comments

Comments
 (0)