Skip to content

remove support for typeof #940

@lcnr

Description

@lcnr

Proposal

We currently have support for the typeof keyword, resulting in the following error message:

error[E0516]: `typeof` is a reserved keyword but unimplemented
 --> src/lib.rs:1:10
  |
1 | const F: typeof(1) = 1;
  |          ^^^^^^^^^ reserved keyword
  |
help: consider replacing `typeof(...)` with an actual type
  |
1 - const F: typeof(1) = 1;
1 + const F: i32 = 1;
  |

This does provide the benefit of suggesting the proper type, so it may be useful to users, even if it's always a hard error. The same can be achieved via _ as the type of a constant or a return type

error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants
 --> src/lib.rs:1:10
  |
1 | const F: _ = 1;
  |          ^ not allowed in type signatures
  |
help: replace this with a fully-specified type
  |
1 - const F: _ = 1;
1 + const F: i32 = 1;
  |

Supporting this does add a small maintenance cost however:

  • we now need to support unnameable types in part of the type system where they otherwise can't exist, making it harder to reason about this code
  • we have an additional place where constants can exist in the type system

Given this small cost and the little benefit together with from what I can tell no path towards stabilization, I am in favor of ripping this out. I've implemented this in rust-lang/rust#148256.

Mentors or Reviewers

If you have a reviewer or mentor in mind for this work, mention them here. You can put your own name here if you are planning to mentor the work.

Process

The main points of the Major Change Process are as follows:

  • File an issue describing the proposal.
  • A compiler team member who is knowledgeable in the area can second by writing @rustbot second or kickoff a team FCP with @rfcbot fcp $RESOLUTION.
  • Once an MCP is seconded, the Final Comment Period begins.
    • Final Comment Period lasts for 10 days after all outstanding concerns are solved.
    • Outstanding concerns will block the Final Comment Period from finishing. Once all concerns are resolved, the 10 day countdown is restarted.
    • If no concerns are raised after 10 days since the resolution of the last outstanding concern, the MCP is considered approved.

You can read more about Major Change Proposals on forge.

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-compilerAdd this label so rfcbot knows to poll the compiler teamfinal-comment-periodThe FCP has started, most (if not all) team members are in agreementmajor-changeA proposal to make a major change to rustcto-announceAnnounce this issue on triage meeting

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions