Closed
Description
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