-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Tracking Issue: Procedural Macro Diagnostics (RFC 1566) #54140
Copy link
Copy link
Open
Labels
A-decl-macros-1-2Area: Declarative macros 1.2Area: Declarative macros 1.2A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsB-experimentalBlocker: In-tree experiment; RFC pending, not yet approved or unneeded (requires FCP to stabilize).Blocker: In-tree experiment; RFC pending, not yet approved or unneeded (requires FCP to stabilize).B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCF-proc_macro_diagnostic`#![feature(proc_macro_diagnostic)]``#![feature(proc_macro_diagnostic)]`I-lang-radarItems that are on lang's radar and will need eventual work or consideration.Items that are on lang's radar and will need eventual work or consideration.Libs-TrackedLibs issues that are tracked on the team's project board.Libs issues that are tracked on the team's project board.T-langRelevant to the language teamRelevant to the language teamT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-decl-macros-1-2Area: Declarative macros 1.2Area: Declarative macros 1.2A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsB-experimentalBlocker: In-tree experiment; RFC pending, not yet approved or unneeded (requires FCP to stabilize).Blocker: In-tree experiment; RFC pending, not yet approved or unneeded (requires FCP to stabilize).B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCF-proc_macro_diagnostic`#![feature(proc_macro_diagnostic)]``#![feature(proc_macro_diagnostic)]`I-lang-radarItems that are on lang's radar and will need eventual work or consideration.Items that are on lang's radar and will need eventual work or consideration.Libs-TrackedLibs issues that are tracked on the team's project board.Libs issues that are tracked on the team's project board.T-langRelevant to the language teamRelevant to the language teamT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Projects
Status
Exploration
This is a tracking issue for diagnostics for procedural macros spawned off from #38356.
Overview
Current Status
feature(proc_macro_diagnostic)Next Steps
Summary
The initial API was implemented in #44125 and is being used by crates like Rocket and Diesel to emit user-friendly diagnostics. Apart from thorough documentation, I see two blockers for stabilization:
Multi-Span Support
At present, it is not possible to create/emit a diagnostic via
proc_macrothat points to more than oneSpan. The internal diagnostics API makes this possible, and we should expose this as well.The changes necessary to support this are fairly minor: a
Diagnosticshould encapsulate aVec<Span>as opposed to aSpan, and thespan_methods should be made generic such that either aSpanor aVec<Span>(ideally also a&[Vec]) can be passed in. This makes it possible for a user to pass in an emptyVec, but this case can be handled as if noSpanwas explicitly set.Lint-Associated Warnings
At present, if a
proc_macroemits a warning, it is unconditional as it is not associated with a lint: the user can never silence the warning. I propose that we require proc-macro authors to associate every warning with a lint-level so that the consumer can turn it off.No API has been formally proposed for this feature. I informally proposed that we allow proc-macros to create lint-levels in an ad-hoc manner; this differs from what happens internally, where all lint-levels have to be known apriori. In code, such an API might look lIke:
The
lint!macro might check for uniqueness and generate a (hidden) structure for internal use. Alternatively, the proc-macro author could simply pass in a string:"unknown_media_type".