diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index 94c15094f5251..e0368745f8aab 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -2488,8 +2488,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/token.rs b/compiler/rustc_ast/src/token.rs index e1231312a2afd..1a1bcb4b08ce6 100644 --- a/compiler/rustc_ast/src/token.rs +++ b/compiler/rustc_ast/src/token.rs @@ -321,7 +321,7 @@ fn ident_can_begin_type(name: Symbol, span: Span, is_raw: IdentIsRaw) -> bool { !ident_token.is_reserved_ident() || ident_token.is_path_segment_keyword() - || [kw::Underscore, kw::For, kw::Impl, kw::Fn, kw::Unsafe, kw::Extern, kw::Typeof, kw::Dyn] + || [kw::Underscore, kw::For, kw::Impl, kw::Fn, kw::Unsafe, kw::Extern, kw::Dyn] .contains(&name) } 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 be9db9257356c..5ec64e1bcb19d 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -1361,7 +1361,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 a5e2bcaa3bd06..645353a660171 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_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_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index 533ab67053095..623d1654ea786 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -1644,18 +1644,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 65347496599d7..b1c2dd057fb24 100644 --- a/compiler/rustc_parse/src/parser/ty.rs +++ b/compiler/rustc_parse/src/parser/ty.rs @@ -328,8 +328,6 @@ impl<'a> Parser<'a> { // Reference self.expect_and()?; self.parse_borrowed_pointee()? - } else if self.eat_keyword_noexpect(kw::Typeof) { - self.parse_typeof_ty()? } else if self.eat_keyword(exp!(Underscore)) { // A type to be inferred `_` TyKind::Infer @@ -763,15 +761,6 @@ 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> { - self.expect(exp!(OpenParen))?; - let expr = self.parse_expr_anon_const()?; - self.expect(exp!(CloseParen))?; - Ok(TyKind::Typeof(expr)) - } - /// Parses a function pointer type (`TyKind::FnPtr`). /// ```ignore (illustrative) /// [unsafe] [extern "ABI"] fn (S) -> T diff --git a/compiler/rustc_passes/src/input_stats.rs b/compiler/rustc_passes/src/input_stats.rs index c83610da1aad2..7daaf4d466953 100644 --- a/compiler/rustc_passes/src/input_stats.rs +++ b/compiler/rustc_passes/src/input_stats.rs @@ -683,7 +683,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 fd7ace368aa67..ac92680c956f8 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -944,9 +944,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/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/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 deleted file mode 100644 index f81b98cdadc8e..0000000000000 --- a/tests/ui/error-codes/E0516.rs +++ /dev/null @@ -1,4 +0,0 @@ -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 deleted file mode 100644 index f4127678d5b99..0000000000000 --- a/tests/ui/error-codes/E0516.stderr +++ /dev/null @@ -1,15 +0,0 @@ -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; - | - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0516`. 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`.