compiler-team icon indicating copy to clipboard operation
compiler-team copied to clipboard

Create `#[rustc_on_type_error]` mimicking `#[rustc_on_unimplemented]` for E0308 customization

Open estebank opened this issue 1 year ago • 2 comments

Proposal

#[rustc_on_unimplemented] has shown its value, despite its many limitations. There are plenty of customized errors in the stdlib that would otherwise require careful customization of the error being emitted while it is being constructed. Type errors in particular currently have lots of special checks, looking at what types are involved to customize the output as appropriate to reduce confusion. We can mimic the same mechanism that #[rustc_on_unimplemented] uses in a new #[rustc_on_type_error] attribute. This would annotate stdlib types and let us replace or add additional output to E0308 errors. This would also lower the barrier to entry for new contributors desiring to customize the type error output.

This feature would only be an implementation detail for the stdlib, which means the API surface doesn't need strong stability guarantees and it enables the possibility of alternative Rust compilers can use these to provide similar diagnostics as rustc.

Mentors or Reviewers

estebank

Process

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

  • [x] File an issue describing the proposal.
  • [ ] A compiler team member or contributor who is knowledgeable in the area can second by writing @rustbot second.
    • Finding a "second" suffices for internal changes. If however, you are proposing a new public-facing feature, such as a -C flag, then full team check-off is required.
    • Compiler team members can initiate a check-off via @rfcbot fcp merge on either the MCP or the PR.
  • [ ] Once an MCP is seconded, the Final Comment Period begins. If no objections are raised after 10 days, the MCP is considered approved.

You can read more about Major Change Proposals on forge.

Comments

This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.

estebank avatar Jul 19 '22 19:07 estebank

This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.

cc @rust-lang/compiler @rust-lang/compiler-contributors

rustbot avatar Jul 19 '22 19:07 rustbot

@rustbot second

lcnr avatar Jul 20 '22 08:07 lcnr

@rustbot label -final-comment-period +major-change-accepted

apiraino avatar Aug 03 '22 15:08 apiraino