Skip to content

Commit 89505d9

Browse files
topecongirocalebcartwright
authored andcommitted
Format error and typeof types (rust-lang#4416)
* Add a test for rust-lang#4357 * Format error and typeof types
1 parent ca8776a commit 89505d9

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

Diff for: src/types.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ use rustc_span::{symbol::kw, BytePos, Pos, Span};
77
use crate::comment::{combine_strs_with_missing_comments, contains_comment};
88
use crate::config::lists::*;
99
use crate::config::{IndentStyle, TypeDensity, Version};
10-
use crate::expr::{format_expr, rewrite_assign_rhs, rewrite_tuple, rewrite_unary_prefix, ExprType};
10+
use crate::expr::{
11+
format_expr, rewrite_assign_rhs, rewrite_call, rewrite_tuple, rewrite_unary_prefix, ExprType,
12+
};
1113
use crate::lists::{
1214
definitive_tactic, itemize_list, write_list, ListFormatting, ListItem, Separator,
1315
};
@@ -797,7 +799,14 @@ impl Rewrite for ast::Ty {
797799
})
798800
}
799801
ast::TyKind::CVarArgs => Some("...".to_owned()),
800-
ast::TyKind::Err | ast::TyKind::Typeof(..) => unreachable!(),
802+
ast::TyKind::Err => Some(context.snippet(self.span).to_owned()),
803+
ast::TyKind::Typeof(ref anon_const) => rewrite_call(
804+
context,
805+
"typeof",
806+
&[anon_const.value.clone()],
807+
self.span,
808+
shape,
809+
),
801810
}
802811
}
803812
}

Diff for: 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+
}

Diff for: 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)