Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

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

Closed
BGR360 opened this issue Mar 21, 2022 · 1 comment · Fixed by #95292
Closed

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

BGR360 opened this issue Mar 21, 2022 · 1 comment · 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)]

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

@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)]` requires-nightly This issue requires a nightly compiler in some way. labels Mar 21, 2022
@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in 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