-
Notifications
You must be signed in to change notification settings - Fork 299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
const
assignment of HeaderName::from_static
#599
Comments
I believe the clippy lint is wrong. Yes, there's an |
You are right,
Because of this, I don't thing that clippy is wrong. But, as I said, I also think that this is not a real problem since we inform the user that the warning is expected when assigning a |
With rust-lang/rust-clippy#12691 (using nightly), the error is now a warn:
Is there anything that can be done in hyper/http to smoothe it further, or are we happy closing once this hits stable? |
The lint is still wrong. I mean, the idea behind it makes sense. But the header name does not use interior mutability. So it's a false positive. |
rust-lang/rust-clippy#12691 hadn't quite reached the 2024-05-01 nightly as Clippy updates are synced with the main repo periodically This false positive no longer occurs on nightly and the fix will hit stable in a few days when 1.80 releases |
When using
HeaderName::from_static
inin order to create a
const(instead of a
static` variable), clippy triggers a warning. Indeed, the following code:Produces the following warning:
Playground
I could just ignore the issue and use
static
instead ofconst
, but I think that the lint exposes an interesting fact I would like to discuss.First of all, the reason behind the lint: there is an
AtomicPtr
deep down. The dependency chain is:Now, the issue itself... It is a non-problem, except for one detail: the fact that potentially we have internal mutability in a header string that obviously is meant to never change is unexpected. Don't get me wrong, I understand the reason behind this: we want to be able to reuse memory when receiving headers (thanks to
Bytes
) and at the same time it is extremely nice to have just oneHeaderName
abstraction (instead ofHeaderName
andConstHeaderName
, for instance). However, following the principle of least surprise, probably you would expect aconst HeaderName::from_static()
function to not have interior mutability.Now, what should be done? To be honest, I am not sure. I personally don't see a practical problem with the current approach, which is pretty ergonomic. Maybe we could consider adding a note in the documentation of
HeaderName::from_static
, suggesting to use astatic
variable instead of aconst
to avoid being flooded by clippy warnings.Do you have better ideas?
CC @paolobarbolini
Originally posted by @dodomorandi in #264 (comment)
The text was updated successfully, but these errors were encountered: