Skip to content

error: could not evaluate constant pattern #66585

@MatsPalmgren

Description

@MatsPalmgren

In the Firefox style system we have this enum type and in the impl I'm adding a const, like so:
pub const INITIAL_VALUE: Self = Self::None;
That compiles fine. Then I'd like to add this function:

    pub fn is_initial(&self) -> bool {
        matches!(*self, Self::INITIAL_VALUE)
    }

which results in:

error: could not evaluate constant pattern
   --> servo/components/style/values/generics/grid.rs:770:25
    |
770 |         matches!(*self, Self::INITIAL_VALUE)
    |                         ^^^^^^^^^^^^^^^^^^^

which makes no sense to me given that matches!(*self, Self::None) compiles just fine.

(This is in a local mozilla-central build, and I think the compiler it uses is: rustc 1.39.0-nightly (6e19f3f 2019-09-06))

BTW, why is the type required in the const declaration? Why can't I just say:
pub const INITIAL_VALUE = Self::None;
It seems like the compiler should be able to deduce the type I wanted there...

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions