Skip to content

Macros follow-up: Support emitting diagnostics in the generated code #60062

@rrousselGit

Description

@rrousselGit

One very useful feature Macros proposed was the ability to emit custom errors/warnings.
This was helpful because code-generators often have some form of error cases.

Since macros are cancelled, could we maybe have some dumbed down version of this?

Proposal: A custom comment similar to // ignore for emitting diagnostics

One way generators could emit diagnostics could be through comments.
For example, we could imagine a generator output:

// @diagnostic kind=error line=10 colum=5 message="You must provide a constuctor"

This would output an error in the associated file, with the given parameters.

Bonus: Have build or source_gen automatically emit such comment when an exception is thrown by generators

Currently, generators rely on throwing InvalidSourceException to emit similar error reports.
The generation tooling could catch those and output a corresponding // @diagnostic,

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-toolsA meta category for issues that should be addressed by tooling (prefer more concrete areas).type-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions