diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index f2061f3088a25..e40d86dbb7b2d 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -2513,8 +2513,6 @@ pub enum TyKind { ImplTrait(NodeId, #[visitable(extra = BoundKind::Impl)] GenericBounds), /// No-op; kept solely so that we can pretty-print faithfully. Paren(Box), - /// Unused for now. - Typeof(AnonConst), /// This means the type should be inferred instead of it having been /// specified. This can appear anywhere in a type. Infer, diff --git a/compiler/rustc_ast/src/util/classify.rs b/compiler/rustc_ast/src/util/classify.rs index f7daec4b0648c..2e494b968b6bd 100644 --- a/compiler/rustc_ast/src/util/classify.rs +++ b/compiler/rustc_ast/src/util/classify.rs @@ -294,7 +294,6 @@ fn type_trailing_braced_mac_call(mut ty: &ast::Ty) -> Option<&ast::MacCall> { | ast::TyKind::Never | ast::TyKind::Tup(..) | ast::TyKind::Paren(..) - | ast::TyKind::Typeof(..) | ast::TyKind::Infer | ast::TyKind::ImplicitSelf | ast::TyKind::CVarArgs diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 1f36454ec861a..dff46ece65430 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -1367,7 +1367,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { self.lower_ty(ty, itctx), self.lower_array_length_to_const_arg(length), ), - TyKind::Typeof(expr) => hir::TyKind::Typeof(self.lower_anon_const_to_anon_const(expr)), TyKind::TraitObject(bounds, kind) => { let mut lifetime_bound = None; let (bounds, lifetime_bound) = self.with_dyn_type_scope(true, |this| { diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs index 21b14f1610779..3dce0498efbf9 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state.rs @@ -1325,11 +1325,6 @@ impl<'a> State<'a> { self.print_expr(&length.value, FixupContext::default()); self.word("]"); } - ast::TyKind::Typeof(e) => { - self.word("typeof("); - self.print_expr(&e.value, FixupContext::default()); - self.word(")"); - } ast::TyKind::Infer => { self.word("_"); } diff --git a/compiler/rustc_error_codes/src/error_codes/E0516.md b/compiler/rustc_error_codes/src/error_codes/E0516.md index 935c31bbab98a..baaa4903a3576 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0516.md +++ b/compiler/rustc_error_codes/src/error_codes/E0516.md @@ -1,3 +1,5 @@ +#### Note: this error code is no longer emitted by the compiler. + The `typeof` keyword is currently reserved but unimplemented. Erroneous code example: diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index db88de828aafd..5ea5bf406cf67 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -3680,8 +3680,6 @@ pub enum TyKind<'hir, Unambig = ()> { /// We use pointer tagging to represent a `&'hir Lifetime` and `TraitObjectSyntax` pair /// as otherwise this type being `repr(C)` would result in `TyKind` increasing in size. TraitObject(&'hir [PolyTraitRef<'hir>], TaggedRef<'hir, Lifetime, TraitObjectSyntax>), - /// Unused for now. - Typeof(&'hir AnonConst), /// Placeholder for a type that has failed to be defined. Err(rustc_span::ErrorGuaranteed), /// Pattern types (`pattern_type!(u32 is 1..)`) diff --git a/compiler/rustc_hir/src/intravisit.rs b/compiler/rustc_hir/src/intravisit.rs index 0b83e7239a992..625766f8bd3da 100644 --- a/compiler/rustc_hir/src/intravisit.rs +++ b/compiler/rustc_hir/src/intravisit.rs @@ -1029,7 +1029,6 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty<'v, AmbigArg>) - } try_visit!(visitor.visit_lifetime(lifetime)); } - TyKind::Typeof(ref expression) => try_visit!(visitor.visit_anon_const(expression)), TyKind::InferDelegation(..) | TyKind::Err(_) => {} TyKind::Pat(ty, pat) => { try_visit!(visitor.visit_ty_unambig(ty)); diff --git a/compiler/rustc_hir_analysis/messages.ftl b/compiler/rustc_hir_analysis/messages.ftl index a313b91ef9bda..bcf4d7f59e34a 100644 --- a/compiler/rustc_hir_analysis/messages.ftl +++ b/compiler/rustc_hir_analysis/messages.ftl @@ -552,11 +552,6 @@ hir_analysis_ty_param_some = type parameter `{$param}` must be used as the type hir_analysis_type_of = {$ty} -hir_analysis_typeof_reserved_keyword_used = - `typeof` is a reserved keyword but unimplemented - .suggestion = consider replacing `typeof(...)` with an actual type - .label = reserved keyword - hir_analysis_unconstrained_generic_parameter = the {$param_def_kind} `{$param_name}` is not constrained by the impl trait, self type, or predicates .label = unconstrained {$param_def_kind} .const_param_note = expressions using a const parameter must map each value to a distinct output value diff --git a/compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs b/compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs index b069a74bf5adc..38ae7852ca99f 100644 --- a/compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs +++ b/compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs @@ -195,10 +195,11 @@ impl<'tcx> InherentCollect<'tcx> { | ty::Closure(..) | ty::CoroutineClosure(..) | ty::Coroutine(..) - | ty::CoroutineWitness(..) => { - Err(self.tcx.dcx().delayed_bug("cannot define inherent `impl` for closure types")) - } - ty::Alias(ty::Free, _) | ty::Bound(..) | ty::Placeholder(_) | ty::Infer(_) => { + | ty::CoroutineWitness(..) + | ty::Alias(ty::Free, _) + | ty::Bound(..) + | ty::Placeholder(_) + | ty::Infer(_) => { bug!("unexpected impl self type of impl: {:?} {:?}", id, self_ty); } // We could bail out here, but that will silence other useful errors. diff --git a/compiler/rustc_hir_analysis/src/coherence/orphan.rs b/compiler/rustc_hir_analysis/src/coherence/orphan.rs index 69921893fce40..f1e138dbcb97a 100644 --- a/compiler/rustc_hir_analysis/src/coherence/orphan.rs +++ b/compiler/rustc_hir_analysis/src/coherence/orphan.rs @@ -217,21 +217,19 @@ pub(crate) fn orphan_check_impl( | ty::Slice(..) | ty::RawPtr(..) | ty::Ref(..) - | ty::FnDef(..) | ty::FnPtr(..) | ty::Never | ty::Tuple(..) | ty::UnsafeBinder(_) => (LocalImpl::Allow, NonlocalImpl::DisallowOther), - ty::Closure(..) + ty::FnDef(..) + | ty::Closure(..) | ty::CoroutineClosure(..) | ty::Coroutine(..) - | ty::CoroutineWitness(..) => { - return Err(tcx - .dcx() - .delayed_bug("cannot define inherent `impl` for closure types")); - } - ty::Bound(..) | ty::Placeholder(..) | ty::Infer(..) => { + | ty::CoroutineWitness(..) + | ty::Bound(..) + | ty::Placeholder(..) + | ty::Infer(..) => { let sp = tcx.def_span(impl_def_id); span_bug!(sp, "weird self type for autotrait impl") } diff --git a/compiler/rustc_hir_analysis/src/collect/type_of.rs b/compiler/rustc_hir_analysis/src/collect/type_of.rs index 9f87381887b30..180589340b4cb 100644 --- a/compiler/rustc_hir_analysis/src/collect/type_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/type_of.rs @@ -7,15 +7,12 @@ use rustc_hir::{self as hir, AmbigArg, HirId}; use rustc_middle::query::plumbing::CyclePlaceholder; use rustc_middle::ty::print::with_forced_trimmed_paths; use rustc_middle::ty::util::IntTypeExt; -use rustc_middle::ty::{ - self, DefiningScopeKind, IsSuggestable, Ty, TyCtxt, TypeVisitableExt, fold_regions, -}; +use rustc_middle::ty::{self, DefiningScopeKind, IsSuggestable, Ty, TyCtxt, TypeVisitableExt}; use rustc_middle::{bug, span_bug}; use rustc_span::{DUMMY_SP, Ident, Span}; use super::{HirPlaceholderCollector, ItemCtxt, bad_placeholder}; use crate::check::wfcheck::check_static_item; -use crate::errors::TypeofReservedKeywordUsed; use crate::hir_ty_lowering::HirTyLowerer; mod opaque; @@ -48,21 +45,6 @@ fn anon_const_type_of<'tcx>(icx: &ItemCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx Node::Variant(Variant { disr_expr: Some(e), .. }) if e.hir_id == hir_id => { tcx.adt_def(tcx.hir_get_parent_item(hir_id)).repr().discr_type().to_ty(tcx) } - // Sort of affects the type system, but only for the purpose of diagnostics - // so no need for ConstArg. - Node::Ty(&hir::Ty { kind: TyKind::Typeof(ref e), span, .. }) if e.hir_id == hir_id => { - let ty = tcx.typeck(def_id).node_type(tcx.local_def_id_to_hir_id(def_id)); - let ty = fold_regions(tcx, ty, |r, _| { - if r.is_erased() { ty::Region::new_error_misc(tcx) } else { r } - }); - let (ty, opt_sugg) = if let Some(ty) = ty.make_suggestable(tcx, false, None) { - (ty, Some((span, Applicability::MachineApplicable))) - } else { - (ty, None) - }; - tcx.dcx().emit_err(TypeofReservedKeywordUsed { span, ty, opt_sugg }); - return ty; - } Node::Field(&hir::FieldDef { default: Some(c), def_id: field_def_id, .. }) if c.hir_id == hir_id => diff --git a/compiler/rustc_hir_analysis/src/errors.rs b/compiler/rustc_hir_analysis/src/errors.rs index 209b0156de323..f8809e051b600 100644 --- a/compiler/rustc_hir_analysis/src/errors.rs +++ b/compiler/rustc_hir_analysis/src/errors.rs @@ -378,17 +378,6 @@ pub(crate) struct ParenthesizedFnTraitExpansion { pub expanded_type: String, } -#[derive(Diagnostic)] -#[diag(hir_analysis_typeof_reserved_keyword_used, code = E0516)] -pub(crate) struct TypeofReservedKeywordUsed<'tcx> { - pub ty: Ty<'tcx>, - #[primary_span] - #[label] - pub span: Span, - #[suggestion(style = "verbose", code = "{ty}")] - pub opt_sugg: Option<(Span, Applicability)>, -} - #[derive(Diagnostic)] #[diag(hir_analysis_value_of_associated_struct_already_specified, code = E0719)] pub(crate) struct ValueOfAssociatedStructAlreadySpecified { diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs index c881c77f38f15..4db9a4c2bcdd8 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs @@ -2582,7 +2582,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { let length = self.lower_const_arg(length, FeedConstTy::No); Ty::new_array_with_const_len(tcx, self.lower_ty(ty), length) } - hir::TyKind::Typeof(e) => tcx.type_of(e.def_id).instantiate_identity(), hir::TyKind::Infer(()) => { // Infer also appears as the type of arguments or return // values in an ExprKind::Closure, or as diff --git a/compiler/rustc_hir_pretty/src/lib.rs b/compiler/rustc_hir_pretty/src/lib.rs index b818a697960ac..b3b416955230f 100644 --- a/compiler/rustc_hir_pretty/src/lib.rs +++ b/compiler/rustc_hir_pretty/src/lib.rs @@ -445,11 +445,6 @@ impl<'a> State<'a> { self.print_const_arg(length); self.word("]"); } - hir::TyKind::Typeof(ref e) => { - self.word("typeof("); - self.print_anon_const(e); - self.word(")"); - } hir::TyKind::Err(_) => { self.popen(); self.word("/*ERROR*/"); diff --git a/compiler/rustc_hir_typeck/src/lib.rs b/compiler/rustc_hir_typeck/src/lib.rs index d090eb6338284..734d8963d6fda 100644 --- a/compiler/rustc_hir_typeck/src/lib.rs +++ b/compiler/rustc_hir_typeck/src/lib.rs @@ -296,11 +296,6 @@ fn infer_type_if_missing<'tcx>(fcx: &FnCtxt<'_, 'tcx>, node: Node<'tcx>) -> Opti } else if let Node::AnonConst(_) = node { let id = tcx.local_def_id_to_hir_id(def_id); match tcx.parent_hir_node(id) { - Node::Ty(&hir::Ty { kind: hir::TyKind::Typeof(anon_const), span, .. }) - if anon_const.hir_id == id => - { - Some(fcx.next_ty_var(span)) - } Node::Expr(&hir::Expr { kind: hir::ExprKind::InlineAsm(asm), span, .. }) | Node::Item(&hir::Item { kind: hir::ItemKind::GlobalAsm { asm, .. }, span, .. }) => { asm.operands.iter().find_map(|(op, _op_sp)| match op { diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index 79c8d61461005..0ba54e3829f51 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -1660,18 +1660,6 @@ impl EarlyLintPass for UnusedBraces { ); } - ast::TyKind::Typeof(ref anon_const) => { - self.check_unused_delims_expr( - cx, - &anon_const.value, - UnusedDelimsCtx::AnonConst, - false, - None, - None, - false, - ); - } - _ => {} } } diff --git a/compiler/rustc_next_trait_solver/src/coherence.rs b/compiler/rustc_next_trait_solver/src/coherence.rs index b949deb119269..c370fd24a1bb3 100644 --- a/compiler/rustc_next_trait_solver/src/coherence.rs +++ b/compiler/rustc_next_trait_solver/src/coherence.rs @@ -336,7 +336,6 @@ where | ty::Uint(..) | ty::Float(..) | ty::Str - | ty::FnDef(..) | ty::Pat(..) | ty::FnPtr(..) | ty::Array(..) @@ -403,7 +402,6 @@ where // implement, so we don't use this behavior. // Addendum: Moreover, revealing the underlying type is likely to cause cycle // errors as we rely on coherence / the specialization graph during typeck. - self.found_non_local_ty(ty) } } @@ -435,31 +433,14 @@ where } } ty::Error(_) => ControlFlow::Break(OrphanCheckEarlyExit::LocalTy(ty)), - ty::Closure(did, ..) => { - if self.def_id_is_local(did) { - ControlFlow::Break(OrphanCheckEarlyExit::LocalTy(ty)) - } else { - self.found_non_local_ty(ty) - } - } - ty::CoroutineClosure(did, ..) => { - if self.def_id_is_local(did) { - ControlFlow::Break(OrphanCheckEarlyExit::LocalTy(ty)) - } else { - self.found_non_local_ty(ty) - } - } - ty::Coroutine(did, ..) => { - if self.def_id_is_local(did) { - ControlFlow::Break(OrphanCheckEarlyExit::LocalTy(ty)) - } else { - self.found_non_local_ty(ty) - } + + ty::FnDef(..) + | ty::Closure(..) + | ty::CoroutineClosure(..) + | ty::Coroutine(..) + | ty::CoroutineWitness(..) => { + unreachable!("unnameable type in coherence: {ty:?}"); } - // This should only be created when checking whether we have to check whether some - // auto trait impl applies. There will never be multiple impls, so we can just - // act as if it were a local type here. - ty::CoroutineWitness(..) => ControlFlow::Break(OrphanCheckEarlyExit::LocalTy(ty)), }; // A bit of a hack, the `OrphanChecker` is only used to visit a `TraitRef`, so // the first type we visit is always the self type. diff --git a/compiler/rustc_parse/src/parser/ty.rs b/compiler/rustc_parse/src/parser/ty.rs index df69adce142b8..c79b99a80e87a 100644 --- a/compiler/rustc_parse/src/parser/ty.rs +++ b/compiler/rustc_parse/src/parser/ty.rs @@ -7,7 +7,7 @@ use rustc_ast::{ TyKind, UnsafeBinderTy, }; use rustc_data_structures::stack::ensure_sufficient_stack; -use rustc_errors::{Applicability, Diag, PResult}; +use rustc_errors::{Applicability, Diag, E0516, PResult}; use rustc_span::{ErrorGuaranteed, Ident, Span, kw, sym}; use thin_vec::{ThinVec, thin_vec}; @@ -328,7 +328,7 @@ impl<'a> Parser<'a> { self.expect_and()?; self.parse_borrowed_pointee()? } else if self.eat_keyword_noexpect(kw::Typeof) { - self.parse_typeof_ty()? + self.parse_typeof_ty(lo)? } else if self.eat_keyword(exp!(Underscore)) { // A type to be inferred `_` TyKind::Infer @@ -784,13 +784,20 @@ impl<'a> Parser<'a> { } } - // Parses the `typeof(EXPR)`. - // To avoid ambiguity, the type is surrounded by parentheses. - fn parse_typeof_ty(&mut self) -> PResult<'a, TyKind> { + /// Parses the `typeof(EXPR)` for better diagnostics before returning + /// an error type. + fn parse_typeof_ty(&mut self, lo: Span) -> PResult<'a, TyKind> { self.expect(exp!(OpenParen))?; - let expr = self.parse_expr_anon_const()?; + let _expr = self.parse_expr_anon_const()?; self.expect(exp!(CloseParen))?; - Ok(TyKind::Typeof(expr)) + let span = lo.to(self.prev_token.span); + let guar = self + .dcx() + .struct_span_err(span, "`typeof` is a reserved keyword but unimplemented") + .with_note("consider replacing `typeof(...)` with an actual type") + .with_code(E0516) + .emit(); + Ok(TyKind::Err(guar)) } /// Parses a function pointer type (`TyKind::FnPtr`). diff --git a/compiler/rustc_passes/src/input_stats.rs b/compiler/rustc_passes/src/input_stats.rs index fe50b730256b7..35101624bd68e 100644 --- a/compiler/rustc_passes/src/input_stats.rs +++ b/compiler/rustc_passes/src/input_stats.rs @@ -408,7 +408,6 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { OpaqueDef, TraitAscription, TraitObject, - Typeof, Infer, Pat, Err @@ -683,7 +682,6 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> { TraitObject, ImplTrait, Paren, - Typeof, Infer, ImplicitSelf, MacCall, diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index a92bc77b5b508..df620ddb66529 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -954,9 +954,6 @@ impl<'ast, 'ra, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'ra, 'tc self.visit_ty(element_ty); self.resolve_anon_const(length, AnonConstKind::ConstArg(IsRepeatExpr::No)); } - TyKind::Typeof(ct) => { - self.resolve_anon_const(ct, AnonConstKind::ConstArg(IsRepeatExpr::No)) - } _ => visit::walk_ty(self, ty), } self.diag_metadata.current_trait_object = prev; diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 38b12405ea821..1642293138369 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1841,7 +1841,6 @@ pub(crate) fn clean_ty<'tcx>(ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> T // Rustdoc handles `TyKind::Err`s by turning them into `Type::Infer`s. TyKind::Infer(()) | TyKind::Err(_) - | TyKind::Typeof(..) | TyKind::InferDelegation(..) | TyKind::TraitAscription(_) => Infer, } diff --git a/src/tools/clippy/clippy_lints/src/dereference.rs b/src/tools/clippy/clippy_lints/src/dereference.rs index de1362081323a..548f03c9f2059 100644 --- a/src/tools/clippy/clippy_lints/src/dereference.rs +++ b/src/tools/clippy/clippy_lints/src/dereference.rs @@ -830,7 +830,6 @@ impl TyCoercionStability { TyKind::OpaqueDef(..) | TyKind::TraitAscription(..) | TyKind::Infer(()) - | TyKind::Typeof(..) | TyKind::TraitObject(..) | TyKind::InferDelegation(..) | TyKind::Err(_) => Self::Reborrow, @@ -911,7 +910,7 @@ fn ty_contains_infer(ty: &hir::Ty<'_>) -> bool { } fn visit_ty(&mut self, ty: &hir::Ty<'_, AmbigArg>) { - if self.0 || matches!(ty.kind, TyKind::OpaqueDef(..) | TyKind::Typeof(_) | TyKind::Err(_)) { + if self.0 || matches!(ty.kind, TyKind::OpaqueDef(..) | TyKind::Err(_)) { self.0 = true; } else { walk_ty(self, ty); diff --git a/src/tools/clippy/clippy_utils/src/ast_utils/mod.rs b/src/tools/clippy/clippy_utils/src/ast_utils/mod.rs index 04a64e0fe9485..4bdbfc8853662 100644 --- a/src/tools/clippy/clippy_utils/src/ast_utils/mod.rs +++ b/src/tools/clippy/clippy_utils/src/ast_utils/mod.rs @@ -875,7 +875,6 @@ pub fn eq_ty(l: &Ty, r: &Ty) -> bool { (Path(lq, lp), Path(rq, rp)) => both(lq.as_deref(), rq.as_deref(), eq_qself) && eq_path(lp, rp), (TraitObject(lg, ls), TraitObject(rg, rs)) => ls == rs && over(lg, rg, eq_generic_bound), (ImplTrait(_, lg), ImplTrait(_, rg)) => over(lg, rg, eq_generic_bound), - (Typeof(l), Typeof(r)) => eq_expr(&l.value, &r.value), (MacCall(l), MacCall(r)) => eq_mac_call(l, r), _ => false, } diff --git a/src/tools/clippy/clippy_utils/src/check_proc_macro.rs b/src/tools/clippy/clippy_utils/src/check_proc_macro.rs index 544218e09930a..50d9136b8b4dc 100644 --- a/src/tools/clippy/clippy_utils/src/check_proc_macro.rs +++ b/src/tools/clippy/clippy_utils/src/check_proc_macro.rs @@ -524,11 +524,10 @@ fn ast_ty_search_pat(ty: &ast::Ty) -> (Pat, Pat) { TyKind::ImplicitSelf // experimental - |TyKind::Pat(..) + | TyKind::Pat(..) // unused | TyKind::CVarArgs - | TyKind::Typeof(_) // placeholder | TyKind::Dummy diff --git a/src/tools/clippy/clippy_utils/src/hir_utils.rs b/src/tools/clippy/clippy_utils/src/hir_utils.rs index b286701fbed11..c6d82c0e63fa6 100644 --- a/src/tools/clippy/clippy_utils/src/hir_utils.rs +++ b/src/tools/clippy/clippy_utils/src/hir_utils.rs @@ -1309,9 +1309,6 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { TyKind::TraitObject(_, lifetime) => { self.hash_lifetime(lifetime); }, - TyKind::Typeof(anon_const) => { - self.hash_body(anon_const.body); - }, TyKind::UnsafeBinder(binder) => { self.hash_ty(binder.inner_ty); }, diff --git a/src/tools/rustfmt/src/types.rs b/src/tools/rustfmt/src/types.rs index 242d8c23113c3..2d7bc59c62788 100644 --- a/src/tools/rustfmt/src/types.rs +++ b/src/tools/rustfmt/src/types.rs @@ -8,8 +8,7 @@ use crate::comment::{combine_strs_with_missing_comments, contains_comment}; use crate::config::lists::*; use crate::config::{IndentStyle, StyleEdition, TypeDensity}; use crate::expr::{ - ExprType, RhsAssignKind, format_expr, rewrite_assign_rhs, rewrite_call, rewrite_tuple, - rewrite_unary_prefix, + ExprType, RhsAssignKind, format_expr, rewrite_assign_rhs, rewrite_tuple, rewrite_unary_prefix, }; use crate::lists::{ ListFormatting, ListItem, Separator, definitive_tactic, itemize_list, write_list, @@ -1031,13 +1030,6 @@ impl Rewrite for ast::Ty { } ast::TyKind::CVarArgs => Ok("...".to_owned()), ast::TyKind::Dummy | ast::TyKind::Err(_) => Ok(context.snippet(self.span).to_owned()), - ast::TyKind::Typeof(ref anon_const) => rewrite_call( - context, - "typeof", - &[anon_const.value.clone()], - self.span, - shape, - ), ast::TyKind::Pat(ref ty, ref pat) => { let ty = ty.rewrite_result(context, shape)?; let pat = pat.rewrite_result(context, shape)?; diff --git a/src/tools/rustfmt/tests/source/type.rs b/src/tools/rustfmt/tests/source/type.rs index 213fad7cb16b7..09ec22cf8d14c 100644 --- a/src/tools/rustfmt/tests/source/type.rs +++ b/src/tools/rustfmt/tests/source/type.rs @@ -158,9 +158,3 @@ impl Foo { Self(t) } } - -// #4357 -type T = typeof( -1); -impl T for .. { -} diff --git a/src/tools/rustfmt/tests/target/type.rs b/src/tools/rustfmt/tests/target/type.rs index 93479f8b484cb..623192b72b8b7 100644 --- a/src/tools/rustfmt/tests/target/type.rs +++ b/src/tools/rustfmt/tests/target/type.rs @@ -167,7 +167,3 @@ impl Foo { Self(t) } } - -// #4357 -type T = typeof(1); -impl T for .. {} diff --git a/src/tools/tidy/src/issues.txt b/src/tools/tidy/src/issues.txt index 849dcb9e88fb1..68d472791fe77 100644 --- a/src/tools/tidy/src/issues.txt +++ b/src/tools/tidy/src/issues.txt @@ -2983,9 +2983,6 @@ ui/typeck/issue-96530.rs ui/typeck/issue-96738.rs ui/typeck/issue-98260.rs ui/typeck/issue-98982.rs -ui/typeof/issue-100183.rs -ui/typeof/issue-29184.rs -ui/typeof/issue-42060.rs ui/unboxed-closures/issue-18652.rs ui/unboxed-closures/issue-18661.rs ui/unboxed-closures/issue-30906.rs diff --git a/tests/rustdoc-ui/issues/ice-typeof-102986.rs b/tests/rustdoc-ui/issues/ice-typeof-102986.rs deleted file mode 100644 index b1ad19cb9ff47..0000000000000 --- a/tests/rustdoc-ui/issues/ice-typeof-102986.rs +++ /dev/null @@ -1,5 +0,0 @@ -// https://github.com/rust-lang/rust/issues/102986 -struct Struct { - y: (typeof("hey"),), - //~^ ERROR `typeof` is a reserved keyword but unimplemented -} diff --git a/tests/rustdoc-ui/issues/ice-typeof-102986.stderr b/tests/rustdoc-ui/issues/ice-typeof-102986.stderr deleted file mode 100644 index 02e257a9163c1..0000000000000 --- a/tests/rustdoc-ui/issues/ice-typeof-102986.stderr +++ /dev/null @@ -1,15 +0,0 @@ -error[E0516]: `typeof` is a reserved keyword but unimplemented - --> $DIR/ice-typeof-102986.rs:3:9 - | -LL | y: (typeof("hey"),), - | ^^^^^^^^^^^^^ reserved keyword - | -help: consider replacing `typeof(...)` with an actual type - | -LL - y: (typeof("hey"),), -LL + y: (&str,), - | - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0516`. diff --git a/tests/ui/closures/impl-closure-147146.rs b/tests/ui/closures/impl-closure-147146.rs deleted file mode 100644 index b709e577354e5..0000000000000 --- a/tests/ui/closures/impl-closure-147146.rs +++ /dev/null @@ -1,7 +0,0 @@ -impl typeof(|| {}) {} -//~^ ERROR `typeof` is a reserved keyword but unimplemented - -unsafe impl Send for typeof(|| {}) {} -//~^ ERROR `typeof` is a reserved keyword but unimplemented - -fn main() {} diff --git a/tests/ui/closures/impl-closure-147146.stderr b/tests/ui/closures/impl-closure-147146.stderr deleted file mode 100644 index 6da16b5d450fd..0000000000000 --- a/tests/ui/closures/impl-closure-147146.stderr +++ /dev/null @@ -1,15 +0,0 @@ -error[E0516]: `typeof` is a reserved keyword but unimplemented - --> $DIR/impl-closure-147146.rs:1:6 - | -LL | impl typeof(|| {}) {} - | ^^^^^^^^^^^^^ reserved keyword - -error[E0516]: `typeof` is a reserved keyword but unimplemented - --> $DIR/impl-closure-147146.rs:4:22 - | -LL | unsafe impl Send for typeof(|| {}) {} - | ^^^^^^^^^^^^^ reserved keyword - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0516`. diff --git a/tests/ui/error-codes/E0516.rs b/tests/ui/error-codes/E0516.rs index f81b98cdadc8e..52b7ba441c14f 100644 --- a/tests/ui/error-codes/E0516.rs +++ b/tests/ui/error-codes/E0516.rs @@ -1,4 +1,3 @@ fn main() { let x: typeof(92) = 92; //~ ERROR E0516 - //~| NOTE reserved keyword } diff --git a/tests/ui/error-codes/E0516.stderr b/tests/ui/error-codes/E0516.stderr index f4127678d5b99..b1a9faedf1e77 100644 --- a/tests/ui/error-codes/E0516.stderr +++ b/tests/ui/error-codes/E0516.stderr @@ -2,13 +2,9 @@ error[E0516]: `typeof` is a reserved keyword but unimplemented --> $DIR/E0516.rs:2:12 | LL | let x: typeof(92) = 92; - | ^^^^^^^^^^ reserved keyword - | -help: consider replacing `typeof(...)` with an actual type - | -LL - let x: typeof(92) = 92; -LL + let x: i32 = 92; + | ^^^^^^^^^^ | + = note: consider replacing `typeof(...)` with an actual type error: aborting due to 1 previous error diff --git a/tests/ui/typeof/issue-100183.rs b/tests/ui/typeof/issue-100183.rs deleted file mode 100644 index 13e9493eaa59b..0000000000000 --- a/tests/ui/typeof/issue-100183.rs +++ /dev/null @@ -1,6 +0,0 @@ -struct Struct { - y: (typeof("hey"),), - //~^ ERROR `typeof` is a reserved keyword but unimplemented -} - -fn main() {} diff --git a/tests/ui/typeof/issue-100183.stderr b/tests/ui/typeof/issue-100183.stderr deleted file mode 100644 index 765a5c54428f8..0000000000000 --- a/tests/ui/typeof/issue-100183.stderr +++ /dev/null @@ -1,15 +0,0 @@ -error[E0516]: `typeof` is a reserved keyword but unimplemented - --> $DIR/issue-100183.rs:2:9 - | -LL | y: (typeof("hey"),), - | ^^^^^^^^^^^^^ reserved keyword - | -help: consider replacing `typeof(...)` with an actual type - | -LL - y: (typeof("hey"),), -LL + y: (&str,), - | - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0516`. diff --git a/tests/ui/typeof/issue-29184.rs b/tests/ui/typeof/issue-29184.rs deleted file mode 100644 index c77e364c3b83c..0000000000000 --- a/tests/ui/typeof/issue-29184.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - let x: typeof(92) = 92; //~ ERROR `typeof` is a reserved keyword -} diff --git a/tests/ui/typeof/issue-29184.stderr b/tests/ui/typeof/issue-29184.stderr deleted file mode 100644 index d8d43504d7224..0000000000000 --- a/tests/ui/typeof/issue-29184.stderr +++ /dev/null @@ -1,15 +0,0 @@ -error[E0516]: `typeof` is a reserved keyword but unimplemented - --> $DIR/issue-29184.rs:2:12 - | -LL | let x: typeof(92) = 92; - | ^^^^^^^^^^ reserved keyword - | -help: consider replacing `typeof(...)` with an actual type - | -LL - let x: typeof(92) = 92; -LL + let x: i32 = 92; - | - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0516`. diff --git a/tests/ui/typeof/issue-42060.rs b/tests/ui/typeof/issue-42060.rs deleted file mode 100644 index 1740b238343c8..0000000000000 --- a/tests/ui/typeof/issue-42060.rs +++ /dev/null @@ -1,11 +0,0 @@ -fn main() { - let thing = (); - let other: typeof(thing) = thing; //~ ERROR attempt to use a non-constant value in a constant - //~^ ERROR `typeof` is a reserved keyword but unimplemented [E0516] -} - -fn f(){ - let q = 1; - ::N //~ ERROR attempt to use a non-constant value in a constant - //~^ ERROR `typeof` is a reserved keyword but unimplemented [E0516] -} diff --git a/tests/ui/typeof/issue-42060.stderr b/tests/ui/typeof/issue-42060.stderr deleted file mode 100644 index 733ad37693bec..0000000000000 --- a/tests/ui/typeof/issue-42060.stderr +++ /dev/null @@ -1,40 +0,0 @@ -error[E0435]: attempt to use a non-constant value in a constant - --> $DIR/issue-42060.rs:3:23 - | -LL | let other: typeof(thing) = thing; - | ^^^^^ non-constant value - | -help: consider using `const` instead of `let` - | -LL - let thing = (); -LL + const thing: /* Type */ = (); - | - -error[E0435]: attempt to use a non-constant value in a constant - --> $DIR/issue-42060.rs:9:13 - | -LL | ::N - | ^ non-constant value - | -help: consider using `const` instead of `let` - | -LL - let q = 1; -LL + const q: /* Type */ = 1; - | - -error[E0516]: `typeof` is a reserved keyword but unimplemented - --> $DIR/issue-42060.rs:3:16 - | -LL | let other: typeof(thing) = thing; - | ^^^^^^^^^^^^^ reserved keyword - -error[E0516]: `typeof` is a reserved keyword but unimplemented - --> $DIR/issue-42060.rs:9:6 - | -LL | ::N - | ^^^^^^^^^ reserved keyword - -error: aborting due to 4 previous errors - -Some errors have detailed explanations: E0435, E0516. -For more information about an error, try `rustc --explain E0435`. diff --git a/tests/ui/typeof/type_mismatch.rs b/tests/ui/typeof/type_mismatch.rs deleted file mode 100644 index a3444d6c2078c..0000000000000 --- a/tests/ui/typeof/type_mismatch.rs +++ /dev/null @@ -1,12 +0,0 @@ -// Test that using typeof results in the correct type mismatch errors instead of always assuming -// `usize`, in addition to the pre-existing "typeof is reserved and unimplemented" error - -//@ dont-require-annotations: NOTE - -fn main() { - const a: u8 = 1; - let b: typeof(a) = 1i8; - //~^ ERROR `typeof` is a reserved keyword but unimplemented - //~| ERROR mismatched types - //~| NOTE expected `u8`, found `i8` -} diff --git a/tests/ui/typeof/type_mismatch.stderr b/tests/ui/typeof/type_mismatch.stderr deleted file mode 100644 index 6a414c11f384c..0000000000000 --- a/tests/ui/typeof/type_mismatch.stderr +++ /dev/null @@ -1,30 +0,0 @@ -error[E0516]: `typeof` is a reserved keyword but unimplemented - --> $DIR/type_mismatch.rs:8:12 - | -LL | let b: typeof(a) = 1i8; - | ^^^^^^^^^ reserved keyword - | -help: consider replacing `typeof(...)` with an actual type - | -LL - let b: typeof(a) = 1i8; -LL + let b: u8 = 1i8; - | - -error[E0308]: mismatched types - --> $DIR/type_mismatch.rs:8:24 - | -LL | let b: typeof(a) = 1i8; - | --------- ^^^ expected `u8`, found `i8` - | | - | expected due to this - | -help: change the type of the numeric literal from `i8` to `u8` - | -LL - let b: typeof(a) = 1i8; -LL + let b: typeof(a) = 1u8; - | - -error: aborting due to 2 previous errors - -Some errors have detailed explanations: E0308, E0516. -For more information about an error, try `rustc --explain E0308`.