-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-specializationArea: Trait impl specializationArea: Trait impl specializationC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.F-specialization`#![feature(specialization)]``#![feature(specialization)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
The current nightly compiler gives the error "overflow evaluating requirement" when a type is used as a trait with a default impl. For example:
#![feature(specialization)]
fn main() {
println!("{}", <(usize) as TypeString>::type_string());
}
trait TypeString {
fn type_string() -> &'static str;
}
default impl<T> TypeString for T {
fn type_string() -> &'static str {
"unknown type"
}
}
impl TypeString for () {
fn type_string() -> &'static str {
"()"
}
}
...gives the following error:
error[E0275]: overflow evaluating the requirement `usize: TypeString`
--> src/main.rs:4:20
|
4 | println!("{}", <(usize) as TypeString>::type_string());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: required by `TypeString::type_string`
--> src/main.rs:8:5
|
8 | fn type_string() -> &'static str;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Note that if we change <(usize) as TypeString>::type_string()
to <() as TypeString>::type_string()
- ()
has a specialized impl - it compiles and runs correctly.
stepancheg and MingweiSamuel
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-specializationArea: Trait impl specializationArea: Trait impl specializationC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.F-specialization`#![feature(specialization)]``#![feature(specialization)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.