Skip to content

Commit aa8e601

Browse files
authored
Format error and typeof types (#4416)
* Add a test for #4357 * Format error and typeof types
1 parent 6646248 commit aa8e601

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

src/formatting/types.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ use rustc_span::{symbol::kw, BytePos, Span};
66

77
use crate::config::{lists::*, IndentStyle, TypeDensity};
88
use crate::formatting::{
9-
expr::{format_expr, rewrite_assign_rhs, rewrite_tuple, rewrite_unary_prefix, ExprType},
9+
expr::{
10+
format_expr, rewrite_assign_rhs, rewrite_call, rewrite_tuple, rewrite_unary_prefix,
11+
ExprType,
12+
},
1013
lists::{definitive_tactic, itemize_list, write_list, ListFormatting, ListItem, Separator},
1114
macros::{rewrite_macro, MacroPosition},
1215
overflow,
@@ -756,7 +759,14 @@ impl Rewrite for ast::Ty {
756759
})
757760
}
758761
ast::TyKind::CVarArgs => Some("...".to_owned()),
759-
ast::TyKind::Err | ast::TyKind::Typeof(..) => unreachable!(),
762+
ast::TyKind::Err => Some(context.snippet(self.span).to_owned()),
763+
ast::TyKind::Typeof(ref anon_const) => rewrite_call(
764+
context,
765+
"typeof",
766+
&[anon_const.value.clone()],
767+
self.span,
768+
shape,
769+
),
760770
}
761771
}
762772
}

tests/source/type.rs

+6
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,9 @@ impl<T: ? const Trait> Foo<T> {
166166
Self(t)
167167
}
168168
}
169+
170+
// #4357
171+
type T = typeof(
172+
1);
173+
impl T for .. {
174+
}

tests/target/type.rs

+4
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,7 @@ impl<T: ?const Trait> Foo<T> {
177177
Self(t)
178178
}
179179
}
180+
181+
// #4357
182+
type T = typeof(1);
183+
impl T for .. {}

0 commit comments

Comments
 (0)