Require a LintId for all proc-macro warnings #524
Labels
ACP-accepted
API Change Proposal is accepted (seconded with no objections)
api-change-proposal
A proposal to add or alter unstable APIs in the standard libraries
T-libs-api
Proposal
Problem statement
This proposal is designed as the minimal LintId integration that unblocks stabilization of a proc-macro warning API (rust-lang/rust#54140). Per rust-lang/rust#54140 (comment), macro-generated warnings should be associated with a namespaced identifier which can be used for setting lint level at the call site, and for rendering rustdoc documentation about the lints emitted by a macro.
Motivating examples or use cases
https://github.com/openvm-org/openvm/blob/ab01b0cdf95e18b3ac8f790838a1e467303454b7/extensions/algebra/moduli-setup/src/lib.rs#L69
https://github.com/diesel-rs/diesel/blob/94d5a0d4f918770fc6d6802382a0c133b29e2ba6/diesel_derives/src/deprecated/mod.rs
Solution sketch
Add a
proc_macro::LintId
type withCopy
,Clone
, andDebug
impl. Add a 4th proc-macro attribute#[proc_macro_warning]
for declaring a unique LintId at the crate root of a proc-macro crate. Update/rearrange existingDiagnostic
functions in the proc_macro crate to require passing aLintId
when creating a warning.Within the same proc macro crate, the static (
limbs_too_small
) exists in the value namespace. Downstream of the proc macro crate, the same static exists in the macro namespace for the purpose of re-exports. The use of 2 namespaces in such a way is identical to how all proc macro items already work.Alternatives
The 10 comments under rust-lang/rust#54140 (comment) explore a variety of designs.
No statically declared lint names. Proc macro can pass a runtime value for the lint name. Downside: you have only informed the compiler about the existence of a particular lint name if that lint is ever triggered. This means no ability to report
unknown_lints
on a typo like#![deny(openvm_macros::limbs_too_smal)]
, and worse rustdoc.No lint names. Lint level will be controllable only at the level of an entire proc macro crate's lints:
#![deny(diesel_derives::warnings)]
No lint names. Lint level will be controllable using the path of whichever macro produced them:
#![deny(diesel_derives::Selectable::warnings)]
No lint names. Lint level will be controllable universally for all macro-generated warnings:
#![deny(warning_from_proc_macro)]
Future work
The following enhancements would not need to block stabilization of a diagnostics API in proc_macro once
LintId
exists.Support
allow
/warn
/deny
lint level system in the code which calls the proc macro.Integrate with
unknown_lints
lint. If a user writesdeny(foo::ambiguous_thing)
whenfoo
is not a proc macro crate declaring aambiguous_thing
lint id, nor is this resolved as a re-export of such a lint id, this needs to triggerunknown_lints
.Render rustdoc documentation for lint ids.
Mechanism for a proc macro crate to set a default level for each of its lints. By default they are warn-by-default, but some lints might be better as allow-by-default or deny-by-default.
A style lint that enforces a case convention for lint ids (snake_case).
Rust-analyzer will want to provide autocomplete for proc macro lint ids inside
allow
/warn
/deny
.What happens now?
This issue contains an API change proposal (or ACP) and is part of the libs-api team feature lifecycle. Once this issue is filed, the libs-api team will review open proposals as capability becomes available. Current response times do not have a clear estimate, but may be up to several months.
Possible responses
The libs team may respond in various different ways. First, the team will consider the problem (this doesn't require any concrete solution or alternatives to have been proposed):
Second, if there's a concrete solution:
The text was updated successfully, but these errors were encountered: