Skip to content

Const generics and structural match. #71415

Closed
@crlf0710

Description

@crlf0710

Not sure whether this has been reported before.
I tried this code:

#![feature(const_generics)]
#![feature(structural_match)]

use std::marker::{StructuralPartialEq, StructuralEq};

struct Container<T: StructuralPartialEq + StructuralEq, const V: T>;

fn main() {
    let container1: Container<i32, {42}> = Container;
    let container2: Container<&'static str, "Hello world"> = Container;
}

I expected to see this happen: The compile passes.

Instead, this happened:

error[E0741]: the types of const generic parameters must derive `PartialEq` and `Eq`
 --> src/main.rs:6:66
  |
6 | struct Container<T: StructuralPartialEq + StructuralEq, const V: T>;
  |                                                                  ^ `T` doesn't derive both `PartialEq` and `Eq`

Meta

rustc --version --verbose:

Nightly channel
Build using the Nightly version: 1.44.0-nightly

(2020-04-21 45d050cde277b22a7558)
Backtrace

<backtrace>

@rustbot modify labels to +A-const generics F-const generics T-compiler requires-nightly

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-genericsArea: const generics (parameters and arguments)C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions