From 2ac171f94cca347ff3b1ef4c3e13f3566b087e73 Mon Sep 17 00:00:00 2001 From: Jane Lusby Date: Sat, 26 Sep 2020 16:34:09 -0700 Subject: [PATCH] try enabling typeof for fun error messages --- compiler/rustc_typeck/src/astconv/mod.rs | 4 ++-- compiler/rustc_typeck/src/collect/type_of.rs | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_typeck/src/astconv/mod.rs b/compiler/rustc_typeck/src/astconv/mod.rs index b6de491911ab..34e06e2d5a01 100644 --- a/compiler/rustc_typeck/src/astconv/mod.rs +++ b/compiler/rustc_typeck/src/astconv/mod.rs @@ -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 diff --git a/compiler/rustc_typeck/src/collect/type_of.rs b/compiler/rustc_typeck/src/collect/type_of.rs index d8eea1ad80b0..74135c49d582 100644 --- a/compiler/rustc_typeck/src/collect/type_of.rs +++ b/compiler/rustc_typeck/src/collect/type_of.rs @@ -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 =>