-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Changing module order causes specialization to fail #50452
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
Comments
Minimized: #![feature(specialization)]
pub trait Foo {
fn foo();
}
impl Foo for i32 {}
impl Foo for i64 {
// fn foo() {}
}
impl<T> Foo for T {
fn foo() {}
} In the current nightly, changing the order of the items or uncommenting the line will make it compile. The latter behavior is also strange. |
Ah, this is likely caused by a bug in specialization graph construction. Consider the following specialization graph:
When we try to construct the graph by adding
Then the compiler compares
I will prepare a fix for this. |
This commit fixes the issue rust-lang#50452.
Reattach all grandchildren when constructing specialization graph. Specialization graphs are constructed by incrementally adding impls in the order of declaration. If the impl being added has its specializations in the graph already, they should be reattached under the impl. However, the current implementation only reattaches the one found first. Therefore, in the following specialization graph, ``` Tr1 | I3 / \ I1 I2 ``` If `I1`, `I2`, and `I3` are declared in this order, the compiler mistakenly constructs the following graph: ``` Tr1 / \ I3 I2 | I1 ``` This patch fixes the reattach procedure to include all specializing grandchildren-to-be. Fixes rust-lang#50452.
Reattach all grandchildren when constructing specialization graph. Specialization graphs are constructed by incrementally adding impls in the order of declaration. If the impl being added has its specializations in the graph already, they should be reattached under the impl. However, the current implementation only reattaches the one found first. Therefore, in the following specialization graph, ``` Tr1 | I3 / \ I1 I2 ``` If `I1`, `I2`, and `I3` are declared in this order, the compiler mistakenly constructs the following graph: ``` Tr1 / \ I3 I2 | I1 ``` This patch fixes the reattach procedure to include all specializing grandchildren-to-be. Fixes #50452.
The below example fails to compile with error
"not all trait items implemented, missing: trait_1".
Swapping modules
one
andtwo
causes the code to compile correctly.The same issue happens when
one
andtwo
are defined in external files.Version: rustc 1.27.0-nightly (e82261d 2018-05-03)
The text was updated successfully, but these errors were encountered: