about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/types.rs13
-rw-r--r--tests/source/type.rs6
-rw-r--r--tests/target/type.rs4
3 files changed, 21 insertions, 2 deletions
diff --git a/src/types.rs b/src/types.rs
index 7eeee2ac979..6e1fc8fc387 100644
--- a/src/types.rs
+++ b/src/types.rs
@@ -7,7 +7,9 @@ use rustc_span::{symbol::kw, BytePos, Pos, Span};
 use crate::comment::{combine_strs_with_missing_comments, contains_comment};
 use crate::config::lists::*;
 use crate::config::{IndentStyle, TypeDensity, Version};
-use crate::expr::{format_expr, rewrite_assign_rhs, rewrite_tuple, rewrite_unary_prefix, ExprType};
+use crate::expr::{
+    format_expr, rewrite_assign_rhs, rewrite_call, rewrite_tuple, rewrite_unary_prefix, ExprType,
+};
 use crate::lists::{
     definitive_tactic, itemize_list, write_list, ListFormatting, ListItem, Separator,
 };
@@ -797,7 +799,14 @@ impl Rewrite for ast::Ty {
                 })
             }
             ast::TyKind::CVarArgs => Some("...".to_owned()),
-            ast::TyKind::Err | ast::TyKind::Typeof(..) => unreachable!(),
+            ast::TyKind::Err => Some(context.snippet(self.span).to_owned()),
+            ast::TyKind::Typeof(ref anon_const) => rewrite_call(
+                context,
+                "typeof",
+                &[anon_const.value.clone()],
+                self.span,
+                shape,
+            ),
         }
     }
 }
diff --git a/tests/source/type.rs b/tests/source/type.rs
index eb4600e5bce..57f31dc901e 100644
--- a/tests/source/type.rs
+++ b/tests/source/type.rs
@@ -166,3 +166,9 @@ impl<T:   ?  const Trait> Foo<T> {
         Self(t)
     }
 }
+
+// #4357
+type T = typeof(
+1);
+impl T for  .. {
+}
\ No newline at end of file
diff --git a/tests/target/type.rs b/tests/target/type.rs
index 20e97440e7c..e7761251688 100644
--- a/tests/target/type.rs
+++ b/tests/target/type.rs
@@ -177,3 +177,7 @@ impl<T: ?const Trait> Foo<T> {
         Self(t)
     }
 }
+
+// #4357
+type T = typeof(1);
+impl T for .. {}