Skip to content
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

borrow_interior_mutable_const interacts poorly with the http crate #3825

Closed
sfackler opened this issue Feb 26, 2019 · 1 comment · Fixed by #6110
Closed

borrow_interior_mutable_const interacts poorly with the http crate #3825

sfackler opened this issue Feb 26, 2019 · 1 comment · Fixed by #6110
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@sfackler
Copy link
Member

The http crate defines constants for common header names, but any use of them triggers this lint:

use http::header::HOST;
use http::HeaderMap;

fn main() {
    let map = HeaderMap::new();
    println!("{}", map.contains_key(&HOST));
}
error: a const item with interior mutability should not be borrowed
 --> src/main.rs:6:38
  |
6 |     println!("{}", map.contains_key(&HOST));
  |                                      ^^^^
  |
  = note: #[deny(clippy::borrow_interior_mutable_const)] on by default
  = help: assign this const to a local or static variable, and use the variable here
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#borrow_interior_mutable_const
@jebrosen
Copy link

This looks like the same or similar underlying cause as #3962, through a few layers of enums and macros. HOST is pub const HOST: HeaderName { inner: Repr::Standard(StandardHeader::Host) }, where Repr::Standard is a non-interior-mutable variant. The Repr enum contains a Bytes in one of the variants (cc #5812).

rail-rain added a commit to rail-rain/rust-clippy that referenced this issue Oct 4, 2020
fix a false positive in two `interior_mutable_const` lints where a constant with enums gets linted
even if it uses a clearly unfrozen variant. Note that the code uses the MIR interpreter, which
the author of rust-lang#3962 thought unlikely to be a solution. This might be over-engineering;
but, I think it's important to be able to work with the 'http' crate (rust-lang#3825).
rail-rain added a commit to rail-rain/rust-clippy that referenced this issue Oct 4, 2020
fix a false positive in two `interior_mutable_const` lints where a constant with enums gets linted
even if it uses a clearly unfrozen variant. Note that the code uses the MIR interpreter, which
the author of rust-lang#3962 thought unlikely to be a solution. This might be over-engineering;
but, I think it's important to be able to work with the 'http' crate (rust-lang#3825).
@bors bors closed this as completed in 694cec1 Nov 7, 2020
Ryan1729 pushed a commit to Ryan1729/rust-clippy that referenced this issue Nov 7, 2020
fix a false positive in two `interior_mutable_const` lints where a constant with enums gets linted
even if it uses a clearly unfrozen variant. Note that the code uses the MIR interpreter, which
the author of rust-lang#3962 thought unlikely to be a solution. This might be over-engineering;
but, I think it's important to be able to work with the 'http' crate (rust-lang#3825).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants