Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Ty>),
/// 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,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

q: is there a chance this affects macros?

Copy link
Member

@fmease fmease Oct 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the following artificial snippet will go from pass→fail:

macro_rules! ck { ($ty:ty) => {}; }
ck!(typeof(0));

After this PR it'll fail with no rules expected keyword `typeof` (and hypothetically if typeof were to be demoted to a normal identifier, it would start failing with expected type, found `0`).

However, it's very unlikely anybody is relying on it. So it's not really a concern. MBE is notoriously forward incompatible.

.contains(&name)
}

Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_ast/src/util/classify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand Down
5 changes: 0 additions & 5 deletions compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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("_");
}
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_error_codes/src/error_codes/E0516.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
9 changes: 5 additions & 4 deletions compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(_) => {
Comment on lines +198 to +202
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

q: How is this related to this PR?

Copy link
Member

@fmease fmease Oct 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the removal of typeof inference, it should now be impossible to sneak these unnameable types into an impl (even with TAIT you can't do that IINM). The typeof removal is partially motivated by being able to perform this exact change as lcnr alluded to in the MCP. CC #147219, #146620 #147146.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the removal of typeof inference, it should now be impossible to sneak these unnameable types into an impl (even with TAIT you can't do that IINM)

Yes, there's currently no way to get unnameable types into impl headers or encounter them in coherence, and it's nice to be able to reason about that

bug!("unexpected impl self type of impl: {:?} {:?}", id, self_ty);
}
// We could bail out here, but that will silence other useful errors.
Expand Down
14 changes: 6 additions & 8 deletions compiler/rustc_hir_analysis/src/coherence/orphan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
12 changes: 0 additions & 12 deletions compiler/rustc_lint/src/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}

_ => {}
}
}
Expand Down
33 changes: 7 additions & 26 deletions compiler/rustc_next_trait_solver/src/coherence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,6 @@ where
| ty::Uint(..)
| ty::Float(..)
| ty::Str
| ty::FnDef(..)
| ty::Pat(..)
| ty::FnPtr(..)
| ty::Array(..)
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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.
Expand Down
11 changes: 0 additions & 11 deletions compiler/rustc_parse/src/parser/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,6 @@ impl<'a> Parser<'a> {
// Reference
self.expect_and()?;
self.parse_borrowed_pointee()?
} else if self.eat_keyword_noexpect(kw::Typeof) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be nice to keep a precise error message here and recover into an error type

self.parse_typeof_ty()?
} else if self.eat_keyword(exp!(Underscore)) {
// A type to be inferred `_`
TyKind::Infer
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_passes/src/input_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,6 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> {
TraitObject,
ImplTrait,
Paren,
Typeof,
Infer,
ImplicitSelf,
MacCall,
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 0 additions & 3 deletions src/tools/tidy/src/issues.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 0 additions & 7 deletions tests/ui/closures/impl-closure-147146.rs

This file was deleted.

15 changes: 0 additions & 15 deletions tests/ui/closures/impl-closure-147146.stderr

This file was deleted.

4 changes: 0 additions & 4 deletions tests/ui/error-codes/E0516.rs

This file was deleted.

15 changes: 0 additions & 15 deletions tests/ui/error-codes/E0516.stderr

This file was deleted.

6 changes: 0 additions & 6 deletions tests/ui/typeof/issue-100183.rs

This file was deleted.

15 changes: 0 additions & 15 deletions tests/ui/typeof/issue-100183.stderr

This file was deleted.

3 changes: 0 additions & 3 deletions tests/ui/typeof/issue-29184.rs

This file was deleted.

15 changes: 0 additions & 15 deletions tests/ui/typeof/issue-29184.stderr

This file was deleted.

11 changes: 0 additions & 11 deletions tests/ui/typeof/issue-42060.rs

This file was deleted.

40 changes: 0 additions & 40 deletions tests/ui/typeof/issue-42060.stderr

This file was deleted.

12 changes: 0 additions & 12 deletions tests/ui/typeof/type_mismatch.rs

This file was deleted.

Loading
Loading