Way to disable const_item_mutation lint for one specific const #77425
Labels
A-lints
Area: Lints (warnings about flaws in source code) such as unused_mut.
C-feature-request
Category: A feature request, i.e: not implemented / a PR.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
The lint added in Rust 1.48 by #75573 warns on anything that looks like mutation of a
const
, such asCONST.field = some_val
orVEC.push(0)
.However, there is at least one compelling reason that a library would want one of its
const
items with aDrop
impl to not trigger that new lint in downstream code. See #77251 (comment). We useCFG.field = some_val
to expose safe global configuration of a library in a way that deliberately strongly triggers "okay I am writing to a global (though safely)" neurons, which an alternative like::set_whatever(...)
does not.#77251 weakens the lint to avoid triggering on expressions resembling
CONST.field = some_val
when there is a Drop impl on CONST, though still triggering onVEC.push(0)
i.e. when a const with a Drop impl is used as a&mut self
receiver.However, this compromise is likely to hit false negatives that reduce the overall usefulness of the const item mutation lint. We would rather have a (likely attribute-based) way to disable the lint at the granularity of specific const items only. Something substantially equivalent to:
An actual such attribute still requires more design work, since there are similar lints that we are interested in creating/uplifting in the future (e.g. const items with interior mutability) which also will need granular opt outs, and it may not be ideal to introduce a single-purpose new opt-out attribute for each one of them.
@Aaron1011
The text was updated successfully, but these errors were encountered: