try enabling typeof for fun error messages

This commit is contained in:
Jane Lusby 2020-09-26 16:34:09 -07:00
parent 9a35232611
commit 2ac171f94c
2 changed files with 7 additions and 3 deletions

View File

@ -2277,9 +2277,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
let array_ty = tcx.mk_ty(ty::Array(self.ast_ty_to_ty(&ty), length));
self.normalize_ty(ast_ty.span, array_ty)
}
hir::TyKind::Typeof(ref _e) => {
hir::TyKind::Typeof(ref e) => {
tcx.sess.emit_err(TypeofReservedKeywordUsed { span: ast_ty.span });
tcx.ty_error()
tcx.type_of(e.hir_id.owner)
}
hir::TyKind::Infer => {
// Infer also appears as the type of arguments or return

View File

@ -417,12 +417,16 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
let parent_node = tcx.hir().get(tcx.hir().get_parent_node(hir_id));
match parent_node {
Node::Ty(&Ty { kind: TyKind::Array(_, ref constant), .. })
| Node::Ty(&Ty { kind: TyKind::Typeof(ref constant), .. })
| Node::Expr(&Expr { kind: ExprKind::Repeat(_, ref constant), .. })
if constant.hir_id == hir_id =>
{
tcx.types.usize
}
Node::Ty(&Ty { kind: TyKind::Typeof(ref constant), .. })
if constant.hir_id == hir_id =>
{
tcx.typeck(def_id).node_type(constant.hir_id)
}
Node::Expr(&Expr { kind: ExprKind::ConstBlock(ref anon_const), .. })
if anon_const.hir_id == hir_id =>