Skip to content

Inconsistent behavior of auto_traits+negative_impls across crates. #108995

Open
@booti386

Description

@booti386

I tried this code:

// Crate a

#![feature(auto_traits)]
#![feature(negative_impls)]

pub auto trait NotVoid {}
impl !NotVoid for () {}

pub trait A<I, O> {}

impl<T, I: NotVoid> A<I, ()> for T {}
impl<T, O: NotVoid> A<(), O> for T {} // OK

use b::ExternNotVoid;

pub trait B<I, O> {}

impl<T, I: ExternNotVoid> B<I, ()> for T {}
impl<T, O: ExternNotVoid> B<(), O> for T {} // Error
// Crate b

#![feature(auto_traits)]
#![feature(negative_impls)]

pub auto trait ExternNotVoid {}
impl !ExternNotVoid for () {}

I expected to see this happen:
Identical behavior when NotVoid is declared in an external crate.

Instead, this happened:

error[E0119]: conflicting implementations of trait `B<(), ()>`
  --> a.rs:19:1
   |
18 | impl<T, I: ExternNotVoid> B<I, ()> for T {} // Error
   | ---------------------------------------- first implementation here
19 | impl<T, O: ExternNotVoid> B<(), O> for T {} // Error
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation

error: aborting due to previous error

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

An error is produced when NotVoid is declared in an external crate (ExternNotVoid).

Meta

rustc --version --verbose:

rustc 1.70.0-nightly (e3dfeeaa4 2023-03-07)
binary: rustc
commit-hash: e3dfeeaa45f117281b19773d67f3f253de65cee1
commit-date: 2023-03-07
host: x86_64-unknown-linux-gnu
release: 1.70.0-nightly
LLVM version: 15.0.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-auto-traitsArea: auto traits (e.g., `auto trait Send {}`)A-trait-systemArea: Trait systemC-bugCategory: This is a bug.F-auto_traits`#![feature(auto_traits)]`F-negative_impls#![feature(negative_impls)]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