From e52a48851054f7cab4a5f646f39ddc001032dd78 Mon Sep 17 00:00:00 2001 From: Seiichi Uchida Date: Mon, 7 Sep 2020 18:27:40 +0900 Subject: [PATCH 1/2] Add a test for #4357 --- tests/source/type.rs | 6 ++++++ tests/target/type.rs | 4 ++++ 2 files changed, 10 insertions(+) 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 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 20e97440e7c..e7761251688 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 .. {} From 526b1b87860055bc62b8ea958b9fb2ee1659d58f Mon Sep 17 00:00:00 2001 From: Seiichi Uchida Date: Mon, 7 Sep 2020 18:27:51 +0900 Subject: [PATCH 2/2] Format error and typeof types --- src/formatting/types.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/formatting/types.rs b/src/formatting/types.rs index be5745bd815..b4ead894f2f 100644 --- a/src/formatting/types.rs +++ b/src/formatting/types.rs @@ -6,7 +6,10 @@ use rustc_span::{symbol::kw, BytePos, Span}; use crate::config::{lists::*, IndentStyle, TypeDensity}; use crate::formatting::{ - expr::{format_expr, rewrite_assign_rhs, rewrite_tuple, rewrite_unary_prefix, ExprType}, + expr::{ + format_expr, rewrite_assign_rhs, rewrite_call, rewrite_tuple, rewrite_unary_prefix, + ExprType, + }, lists::{definitive_tactic, itemize_list, write_list, ListFormatting, ListItem, Separator}, macros::{rewrite_macro, MacroPosition}, overflow, @@ -756,7 +759,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, + ), } } }