-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Open
Labels
A-type-systemArea: Type systemArea: Type systemC-bugCategory: This is a bug.Category: This is a bug.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.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
Description
I tried this code:
fn foo<T>(x: T, y: i32) -> f64 where f64: From<T> {
f64::from(y)
}
I expected to see this happen: should compile and do the right thing.
Instead, this happened:
error[E0308]: mismatched types
--> src/lib.rs:2:15
|
1 | fn foo<T>(x: T, y: i32) -> f64 where f64: From<T> {
| - this type parameter
2 | f64::from(y)
| ^ expected type parameter `T`, found `i32`
|
= note: expected type parameter `T`
found type `i32`
= help: type parameters must be constrained to match other types
= note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
On the other hand, this code compiles fine:
fn foo<T>(_: T, y: i32) -> f64 {
f64::from(y)
}
Meta
I was surprised about this, so after running this with 1.44.0 and 1.44.1 I checked older versions, but 1.39.0, 1.31.0 and 1.15.0 all give the same error. Seems likely that there is an issue about this already, but no clue how to look for it.
Metadata
Metadata
Assignees
Labels
A-type-systemArea: Type systemArea: Type systemC-bugCategory: This is a bug.Category: This is a bug.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.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.