Skip to content

min_specialization does not equate T: ~const Trait with T: Trait #95187

Closed

Description

@BGR360

Given the following code (playground):

#![feature(rustc_attrs)]
#![feature(min_specialization)]
#![feature(const_trait_impl)]

trait DefaultBound {}

#[rustc_specialization_trait]
trait SpecializedBound {}

trait Foo {}

impl<T> const Foo for T
where
    T: ~const DefaultBound
{}

impl<T> Foo for T
where
    T: DefaultBound + SpecializedBound
{}

The following error is produced:

error: cannot specialize on trait `DefaultBound`
  --> src/main.rs:17:1
   |
17 | / impl<T> Foo for T
18 | | where
19 | |     T: DefaultBound + SpecializedBound
20 | | {}
   | |__^

This indicates that rustc is not equating the T: ~const DefaultBound in the default impl with the T: DefaultBound in the specialized impl. Rather, it thinks it's a newly-introduced trait bound, and thus it says "cannot specialize on it" since it's not annotated as rustc_specialization_trait.

In my opinion, the T: ~const DefaultBound and T: DefaultBound should be considered equivalent in the context of specialization, and the above code should compile just as the following code does (playground):

#![feature(rustc_attrs)]
#![feature(min_specialization)]

trait DefaultBound {}

#[rustc_specialization_trait]
trait SpecializedBound {}

trait Foo {}

impl<T> Foo for T
where
    T: DefaultBound
{}

impl<T> Foo for T
where
    T: DefaultBound + SpecializedBound
{}

See also #95186

@rustbot label +F-const_trait_impl +F-specialization +A-specialization +A-traits +requires-nightly

Activity

  1. added
    requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.
    on Mar 21, 2022
  2. BGR360 commented on Mar 22, 2022

    @BGR360
    ContributorAuthor

    @rustbot claim

  3. added a commit that references this issue on Mar 25, 2022
    946bf54
  4. added 2 commits that reference this issue on Nov 11, 2022
    cd30ccf
    24feb92
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-specializationArea: Trait impl specializationA-trait-systemArea: Trait systemC-bugCategory: This is a bug.F-const_trait_impl`#![feature(const_trait_impl)]`F-specialization`#![feature(specialization)]`requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions