mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-28 07:30:57 +00:00
f58a1695a6
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 #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 (#3825).
89 lines
3.8 KiB
Text
89 lines
3.8 KiB
Text
error: a `const` item should never be interior mutable
|
|
--> $DIR/enums.rs:12:1
|
|
|
|
|
LL | const UNFROZEN_VARIANT: OptionalCell = OptionalCell::Unfrozen(Cell::new(true)); //~ ERROR interior mutable
|
|
| -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
| |
|
|
| make this a static item (maybe with lazy_static)
|
|
|
|
|
= note: `-D clippy::declare-interior-mutable-const` implied by `-D warnings`
|
|
|
|
error: a `const` item should never be interior mutable
|
|
--> $DIR/enums.rs:23:1
|
|
|
|
|
LL | const UNFROZEN_VARIANT_FROM_FN: OptionalCell = unfrozen_variant(); //~ ERROR interior mutable
|
|
| -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
| |
|
|
| make this a static item (maybe with lazy_static)
|
|
|
|
error: a `const` item should never be interior mutable
|
|
--> $DIR/enums.rs:45:1
|
|
|
|
|
LL | const NESTED_UNFROZEN_VARIANT: NestedOutermost = NestedOutermost {
|
|
| ^----
|
|
| |
|
|
| _make this a static item (maybe with lazy_static)
|
|
| |
|
|
LL | | outer: NestedOuter::NestedInner(NestedInner {
|
|
LL | | inner: NestedInnermost::Unfrozen(AtomicUsize::new(2)),
|
|
LL | | }),
|
|
LL | | }; //~ ERROR interior mutable
|
|
| |__^
|
|
|
|
error: a `const` item should never be interior mutable
|
|
--> $DIR/enums.rs:59:5
|
|
|
|
|
LL | const TO_BE_UNFROZEN_VARIANT: OptionalCell; //~ ERROR interior mutable
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
error: a `const` item should never be interior mutable
|
|
--> $DIR/enums.rs:60:5
|
|
|
|
|
LL | const TO_BE_FROZEN_VARIANT: OptionalCell; //~ ERROR interior mutable
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
error: a `const` item should never be interior mutable
|
|
--> $DIR/enums.rs:63:5
|
|
|
|
|
LL | const DEFAULTED_ON_UNFROZEN_VARIANT: OptionalCell = OptionalCell::Unfrozen(Cell::new(false)); //~ ERROR interior mutable
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
error: a `const` item should never be interior mutable
|
|
--> $DIR/enums.rs:89:5
|
|
|
|
|
LL | const TO_BE_UNFROZEN_VARIANT: Option<Self::ToBeUnfrozen> = Some(Self::ToBeUnfrozen::new(4)); //~ ERROR interior mutable
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
error: a `const` item should never be interior mutable
|
|
--> $DIR/enums.rs:101:5
|
|
|
|
|
LL | const UNFROZEN_VARIANT: BothOfCellAndGeneric<T> = BothOfCellAndGeneric::Unfrozen(Cell::new(std::ptr::null())); //~ ERROR interior mut...
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
error: a `const` item should never be interior mutable
|
|
--> $DIR/enums.rs:104:5
|
|
|
|
|
LL | const GENERIC_VARIANT: BothOfCellAndGeneric<T> = BothOfCellAndGeneric::Generic(std::ptr::null()); //~ ERROR interior mutable
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
error: a `const` item should never be interior mutable
|
|
--> $DIR/enums.rs:110:5
|
|
|
|
|
LL | const NO_ENUM: Cell<*const T> = Cell::new(std::ptr::null()); //~ ERROR interior mutable
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
error: a `const` item should never be interior mutable
|
|
--> $DIR/enums.rs:117:5
|
|
|
|
|
LL | / const UNFROZEN_VARIANT: BothOfCellAndGeneric<Self::AssocType> =
|
|
LL | | BothOfCellAndGeneric::Unfrozen(Cell::new(std::ptr::null())); //~ ERROR interior mutable
|
|
| |____________________________________________________________________^
|
|
|
|
error: a `const` item should never be interior mutable
|
|
--> $DIR/enums.rs:119:5
|
|
|
|
|
LL | const GENERIC_VARIANT: BothOfCellAndGeneric<Self::AssocType> = BothOfCellAndGeneric::Generic(std::ptr::null()); //~ ERROR interior mu...
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
error: aborting due to 12 previous errors
|
|
|