Skip to content

Derived PartialEq cannot be used in a const function #77695

Closed
@mbartlett21

Description

@mbartlett21

The derived PartialEq implementation cannot be used in a const context.

The code below gives error E0015

#[derive(PartialEq)]
struct A(u8);

const fn is_eq(left: &A, right: &A) -> bool {
    left == right
}
error[E0015]: calls in constant functions are limited to constant functions, tuple structs and tuple variants
 --> derive_eq_partialeq.rs:5:2
  |
5 |     left == right
  |     ^^^^^^^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0015`.

Meta

rustc --version --verbose:

rustc 1.49.0-nightly (91a79fb29 2020-10-07)
binary: rustc
commit-hash: 91a79fb29ac78d057d04dbe86be13d5dcc64309a
commit-date: 2020-10-07
host: x86_64-pc-windows-msvc
release: 1.49.0-nightly
LLVM version: 11.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)C-feature-requestCategory: A feature request, i.e: not implemented / a PR.F-const_trait_impl`#![feature(const_trait_impl)]`PG-const-traitsProject group: Const traitsT-langRelevant to the language 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