Skip to content

Conflicting implementation of trait with generic_const_exprs feature #92186

Open
@minseongg

Description

@minseongg

I tried this code:

#![allow(incomplete_features)]
#![feature(adt_const_params)]
#![feature(generic_const_exprs)]

use std::marker::PhantomData;

pub struct Foo<const P: Protocol, T> {
    _marker: PhantomData<T>,
}

#[derive(PartialEq, Eq)]
pub enum Protocol {
    Variant1,
    Variant2,
}

pub trait Bar {}

impl<T> Bar for Foo<{ Protocol::Variant1 }, T> {}
impl<T> Bar for Foo<{ Protocol::Variant2 }, T> {}

I expected to see this happen: This is the result when I commented generic_const_exprs feature.

$ cargo build
   Compiling test-nightly v0.1.0
    Finished dev [unoptimized + debuginfo] target(s) in 0.22s

Instead, this happened:

$ cargo build
   Compiling test-nightly v0.1.0
error[E0119]: conflicting implementations of trait `Bar` for type `Foo<{ Protocol::Variant1 }, _>`
  --> src/lib.rs:28:1
   |
27 | impl<T> Bar for Foo<{ Protocol::Variant1 }, T> {}
   | -------------------- first implementation here
28 | impl<T> Bar for Foo<{ Protocol::Variant2 }, T> {}
   | ^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `Foo<{ Protocol::Variant1 }, _>`

For more information about this error, try `rustc --explain E0119`.
error: could not compile `test-nightly` due to previous error

Meta

rustc --version --verbose:

rustc 1.59.0-nightly (23f69235a 2021-12-20)
binary: rustc
commit-hash: 23f69235ad2eb9b44ac1a55eeaa3f9b484d9de4a
commit-date: 2021-12-20
host: x86_64-unknown-linux-gnu
release: 1.59.0-nightly
LLVM version: 13.0.0
Backtrace

$ RUST_BACKTRACE=1 cargo build
   Compiling test-nightly v0.1.0
error[E0119]: conflicting implementations of trait `Bar` for type `Foo<{ Protocol::Variant1 }, _>`
  --> src/lib.rs:20:1
   |
19 | impl<T> Bar for Foo<{ Protocol::Variant1 }, T> {}
   | -------------------- first implementation here
20 | impl<T> Bar for Foo<{ Protocol::Variant2 }, T> {}
   | ^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `Foo<{ Protocol::Variant1 }, _>`

For more information about this error, try `rustc --explain E0119`.
error: could not compile `test-nightly` due to previous error

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-genericsArea: const generics (parameters and arguments)C-bugCategory: This is a bug.F-generic_const_exprs`#![feature(generic_const_exprs)]`requires-incomplete-featuresThis issue requires the use of incomplete features.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