Skip to content

Conversation

@lcnr
Copy link
Contributor

@lcnr lcnr commented Oct 29, 2025

see rust-lang/compiler-team#940 closes #148700

This also enables checks for invariants previously broken by typeof again.

r? types

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Oct 29, 2025
@lcnr lcnr marked this pull request as ready for review October 29, 2025 15:57
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. A-tidy Area: The tidy tool T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 29, 2025
@lcnr lcnr changed the title orphan check: don't support unnameable types remove support for typeof Oct 29, 2025
@lcnr lcnr added the S-waiting-on-MCP Status: PR has a compiler MCP and is waiting for the compiler MCP to complete. label Oct 29, 2025
@traviscross traviscross added the I-lang-radar Items that are on lang's radar and will need eventual work or consideration. label Oct 29, 2025
!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.

Comment on lines +198 to +202
| ty::CoroutineWitness(..)
| ty::Alias(ty::Free, _)
| ty::Bound(..)
| ty::Placeholder(_)
| ty::Infer(_) => {
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

// 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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

how do you do that? It's not immediately obvious to me how to impl that and don't want to spend much time on figuring this out 🤔

Copy link
Member

@fmease fmease Nov 18, 2025

Choose a reason for hiding this comment

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

how do you do that? It's not immediately obvious to me how to impl that

Instead of removing this eat_keyword_noexpect branch + fn parse_typeof_ty, keep both but change parse_typeof_ty to no longer return a TyKind::Typeof(expr) but instead a TyKind::Err(guar) (this variant already exists) where obv. let guar = dcx.struct_span_err(…, "…");.

Copy link
Member

Choose a reason for hiding this comment

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

This made me realize that we do accept this on stable (and have been since ~forever), lol:

#[cfg(false)]
type X = typeof(0);

So forget what I said about MBEs, this is a far more obvious demonstration why removing typeof is a theoretical breaking change, not that anybody would care ^^.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done that I think? @fmease do you think this is relevant enough to do a crater run or sth like that here?

Copy link
Member

Choose a reason for hiding this comment

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

I think the most likely scenario would be something like #[mydsl] fn f() { … typeof(…) … } but even that seems farfetched (esp. since this would still compile if mydsl is a proc-macro attr).

I've also skimmed the results of GH Search: /(?-i)\btypeof\([^)"]/ language:Rust but couldn't find anything that would break.

So, I don't think this warrants a crater run, let's just ship it.

@spastorino
Copy link
Member

This looks good to me, r=me once the MCP finishes and addressing @Noratrieb's comment.

@rustbot
Copy link
Collaborator

rustbot commented Nov 25, 2025

HIR ty lowering was modified

cc @fmease

@rustbot

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented Nov 25, 2025

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@rust-log-analyzer

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented Nov 25, 2025

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

Some changes occurred in src/tools/rustfmt

cc @rust-lang/rustfmt

@rustbot rustbot added T-clippy Relevant to the Clippy team. T-rustfmt Relevant to the rustfmt team, which will review and decide on the PR/issue. labels Nov 25, 2025
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer
Copy link
Collaborator

The job aarch64-gnu-llvm-20-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)

failures:

---- [ui] tests/rustdoc-ui/issues/ice-typeof-102986.rs stdout ----
Saved the actual stderr to `/checkout/obj/build/aarch64-unknown-linux-gnu/test/rustdoc-ui/issues/ice-typeof-102986/ice-typeof-102986.stderr`
diff of stderr:

2   --> $DIR/ice-typeof-102986.rs:3:9
3    |
4 LL |     y: (typeof("hey"),),
-    |         ^^^^^^^^^^^^^ reserved keyword
+    |         ^^^^^^^^^^^^^
6    |
- help: consider replacing `typeof(...)` with an actual type
-    |
- LL -     y: (typeof("hey"),),
- LL +     y: (&str,),
-    |
+    = note: consider replacing `typeof(...)` with an actual type
12 
- error: aborting due to 1 previous error
+ error: Compilation failed, aborting rustdoc
---
To only update this specific test, also pass `--test-args issues/ice-typeof-102986.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustdoc" "/checkout/tests/rustdoc-ui/issues/ice-typeof-102986.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "-o" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/rustdoc-ui/issues/ice-typeof-102986" "-A" "internal_features" "-A" "unused_parens" "-A" "unused_braces" "-Cdebuginfo=0"
stdout: none
--- stderr -------------------------------
error[E0516]: `typeof` is a reserved keyword but unimplemented
##[error]  --> /checkout/tests/rustdoc-ui/issues/ice-typeof-102986.rs:3:9
   |
LL |     y: (typeof("hey"),),
   |         ^^^^^^^^^^^^^
   |
   = note: consider replacing `typeof(...)` with an actual type

error: Compilation failed, aborting rustdoc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-tidy Area: The tidy tool I-lang-radar Items that are on lang's radar and will need eventual work or consideration. S-waiting-on-MCP Status: PR has a compiler MCP and is waiting for the compiler MCP to complete. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustfmt Relevant to the rustfmt team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tracking issue for MCP 940: remove support for typeof ICE on typeof(CT_PARAM) due to incorrect generic param substitution / instantiation somewhere

8 participants