Repository navigation
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-min_specialization`#![feature(min_specialization)]``#![feature(min_specialization)]`S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.Status: This bug is tracked inside the repo by a `known-bug` test.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.fixed-by-next-solverFixed by the next-generation trait solver, `-Znext-solver`.Fixed by the next-generation trait solver, `-Znext-solver`.requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.This issue requires a nightly compiler in some way. When possible, use a F-* label instead.
Description
STR
#![feature(min_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 }
}
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
Reacted by 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-min_specialization`#![feature(min_specialization)]``#![feature(min_specialization)]`S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.Status: This bug is tracked inside the repo by a `known-bug` test.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.fixed-by-next-solverFixed by the next-generation trait solver, `-Znext-solver`.Fixed by the next-generation trait solver, `-Znext-solver`.requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.This issue requires a nightly compiler in some way. When possible, use a F-* label instead.
Activity
Mark-Simulacrum commentedon May 13, 2017
Another example:
oberien commentedon Dec 20, 2017
I don't have an sscce, but I produced this small patch for the current master branch of rust, which breaks type inference regarding specialization of iterators.
The interesting thing is, if I don't directly specialize the iterator, but instead create a new trait which I specialize, it compiles just fine. The patch for this can be found here.
Emerentius commentedon May 12, 2018
I have a patch specializing
SliceConcatExt<T>forT: Copywhich causes type inference to fail on a call to concat inside rustc. It happens even if I don't actually specialize anything. If I delete the empty impl block and leave the general impl block as-is, including thedefaults, it works. Just the existence of the specializing impl block is enough to break it.Edit: I've misinterpreted the issue. Explanation at the end
The call where inference breaks is src/librustc_typeck/collect.rs Line 1299
The error is:
Previously only one impl ofSliceConcatExt<T>could produce aVec<_>. With the specialization it's two, but one is a subset of the other.Edit:
Actually, the issue has not to do with the associated type but with the generic
T.concathas no information aboutT.joinhas aTseparator parameter and does not have the inference problem but concat could work for anyTfor whichV: Borrow<[T]>.That genericity might require one to add a turbofish but in that case above in the stdlib, it was not necessary. The specialization should not change that.
Rollup merge of rust-lang#160520 - jackh726:specialization-tests, r=n…
Rollup merge of rust-lang#160520 - jackh726:specialization-tests, r=n…
Rollup merge of rust-lang#160520 - jackh726:specialization-tests, r=n…
Rollup merge of rust-lang#160520 - jackh726:specialization-tests, r=n…
Rollup merge of rust-lang#160520 - jackh726:specialization-tests, r=n…
Unrolled build for #160520
Rollup merge of #160520 - jackh726:specialization-tests, r=nikomatsakis