Skip to content

min_specialization does not allow specializing on ~const trait bounds #95186

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
BGR360 opened this issue Mar 21, 2022 · 2 comments · Fixed by #95292
Closed

min_specialization does not allow specializing on ~const trait bounds #95186

BGR360 opened this issue Mar 21, 2022 · 2 comments · Fixed by #95292
Assignees
Labels
A-specialization Area: Trait impl specialization A-trait-system Area: Trait system C-bug Category: This is a bug. F-const_trait_impl `#![feature(const_trait_impl)]` F-specialization `#![feature(specialization)]` requires-nightly This issue requires a nightly compiler in some way.

Comments

@BGR360
Copy link
Contributor

BGR360 commented Mar 21, 2022

Given the following code (playground):

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

#[rustc_specialization_trait]
trait Specialize {}

trait Foo {}

impl<T> const Foo for T {}

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

The following error is produced:

error: cannot specialize on `Binder(~const TraitPredicate(<T as Specialize>, polarity:Positive), [])`
  --> src/main.rs:12:1
   |
12 | / impl<T> const Foo for T
13 | | where
14 | |     T: ~const Specialize
15 | | {}
   | |__^

What I expect is that the compilation succeeds, as it does without the const trait impl and corresponding ~const trait bound (playground):

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

#[rustc_specialization_trait]
trait Specialize {}

trait Foo {}

impl<T> Foo for T {}

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

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

@BGR360 BGR360 added the C-bug Category: This is a bug. label Mar 21, 2022
@rustbot rustbot added A-specialization Area: Trait impl specialization A-trait-system Area: Trait system F-const_trait_impl `#![feature(const_trait_impl)]` F-specialization `#![feature(specialization)]` labels Mar 21, 2022
@BGR360
Copy link
Contributor Author

BGR360 commented Mar 21, 2022

@rustbot label +requires-nightly

@BGR360
Copy link
Contributor Author

BGR360 commented Mar 22, 2022

@rustbot claim

BGR360 added a commit to BGR360/rust that referenced this issue Mar 25, 2022
Manishearth added a commit to Manishearth/rust that referenced this issue Nov 11, 2022
Allow specialized const trait impls.

Fixes rust-lang#95186.
Fixes rust-lang#95187.

I've done my best to create a comprehensive test suite for the interaction between `min_specialization` and `const_trait_impls`. I wouldn't be surprised if there are interesting cases I haven't tested, please let me know.
Manishearth added a commit to Manishearth/rust that referenced this issue Nov 11, 2022
Allow specialized const trait impls.

Fixes rust-lang#95186.
Fixes rust-lang#95187.

I've done my best to create a comprehensive test suite for the interaction between `min_specialization` and `const_trait_impls`. I wouldn't be surprised if there are interesting cases I haven't tested, please let me know.
@bors bors closed this as completed in 5c25d30 Nov 11, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-specialization Area: Trait impl specialization A-trait-system Area: Trait system C-bug Category: This is a bug. F-const_trait_impl `#![feature(const_trait_impl)]` F-specialization `#![feature(specialization)]` requires-nightly This issue requires a nightly compiler in some way.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants