diff --git a/src/types.rs b/src/types.rs index 7eeee2ac979a..6e1fc8fc387f 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 eb4600e5bce9..57f31dc901e7 100644 --- a/tests/source/type.rs +++ b/tests/source/type.rs @@ -166,3 +166,9 @@ impl Foo { 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 20e97440e7cf..e7761251688a 100644 --- a/tests/target/type.rs +++ b/tests/target/type.rs @@ -177,3 +177,7 @@ impl Foo { Self(t) } } + +// #4357 +type T = typeof(1); +impl T for .. {}