-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-inferenceArea: Type inferenceArea: Type inferenceA-specializationArea: Trait impl specializationArea: Trait impl specializationA-trait-systemArea: Trait systemArea: Trait systemC-bugCategory: This is a bug.Category: This is a bug.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.requires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.
Description
STR
#![feature(specialization)]
struct My<T>(T);
trait Conv<T> {
fn conv(self) -> T;
}
impl<T> Conv<T> for My<T> {
default fn conv(self) -> T { self.0 }
}
#[cfg(broken)]
impl Conv<u32> for My<u32> {
default fn conv(self) -> u32 { self.0 }
}
fn main() {
let x = My(0);
x.conv() + 0i32;
}
Expected Result
Adding a specialized impl will not affect type inference.
Actual Result
After adding the specialized impl, inference is guided to take it:
error[E0308]: mismatched types
--> <anon>:20:16
|
20 | x.conv() + 0i32;
| ^^^^ expected u32, found i32
error[E0277]: the trait bound `u32: std::ops::Add<i32>` is not satisfied
--> <anon>:20:5
|
20 | x.conv() + 0i32;
| ^^^^^^^^^^^^^^^ trait `u32: std::ops::Add<i32>` not satisfied
|
= help: the following implementations were found:
= help: <u32 as std::ops::Add>
= help: <&'a u32 as std::ops::Add<u32>>
= help: <u32 as std::ops::Add<&'a u32>>
= help: <&'b u32 as std::ops::Add<&'a u32>>
error: aborting due to 2 previous errors
dodheim
Metadata
Metadata
Assignees
Labels
A-inferenceArea: Type inferenceArea: Type inferenceA-specializationArea: Trait impl specializationArea: Trait impl specializationA-trait-systemArea: Trait systemArea: Trait systemC-bugCategory: This is a bug.Category: This is a bug.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.requires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.