-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
C-bugCategory: This is a bug.Category: This is a bug.P-highHigh priorityHigh priorityT-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
Summary from @pnkfelix : Self
used as a tuple-struct constructor function should use the fully type-substituted form from the impl
block, but does not.
Thus, today this code is accepted, but it should not be.
struct _Bar<T>(T);
impl<T> _Bar<T> {
fn _map1<U>(x: U) -> _Bar<U> {
Self(x)
}
}
(Fixing this would be a breaking-change, so we should take care in how we deploy it.)
Original bug report follows:
I tried this code:
struct _Foo<T> {
x: T
}
impl<T> _Foo<T> {
fn _map<U>(x: U) -> _Foo<U> {
Self { x }
}
}
struct _Bar<T>(T);
impl<T> _Bar<T> {
fn _map<U>(x: U) -> _Bar<U> {
Self(x)
}
}
In nightly rustc, _Bar
compiles while _Foo
yields a type mismatch error:
error[E0308]: mismatched types
--> src/main.rs:10:16
|
8 | impl<T> _Foo<T> {
| - expected type parameter
9 | fn _map<U>(x: U) -> _Foo<U> {
| - found type parameter
10 | Self { x }
| ^ expected type parameter `T`, found type parameter `U`
|
Metadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.P-highHigh priorityHigh priorityT-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.