hyperium / http

Rust HTTP types
Apache License 2.0
1.12k stars 283 forks source link

Clippy considers HeaderName to be "interior mutable" #607

Closed rawler closed 1 year ago

rawler commented 1 year ago

When augmenting the header constants defined in http::header with my own custom header, clippy warns me that HeaderName is "interior mutable".

warning: a const item should never be interior mutable --> src/my_source.rs:39:1 39 const X_REQUEST_ID_HEADER: HeaderName = HeaderName::from_static("x-request-id"); -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
make this a static item (maybe with lazy_static)

= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#declare_interior_mutable_const = note: #[warn(clippy::declare_interior_mutable_const)] on by default

rawler commented 1 year ago

Haven't had time to dig into whether HeaderName really is interior-mutable yet, or if clippy is just misdetecting. If it really is correct, I'm guessing the same interior mutability could be detect by compiler when not used as const, preventing some optimizations at compile-time?

Regardess, this right now gets in the way from defining custom HeaderName as const.

seanmonstar commented 1 year ago

See #599.

rawler commented 1 year ago

Ugh. I thought I search for duplicates.