Skip to content

Commit da910b1

Browse files
committed
Add failing from_over_into test case
1 parent f85331f commit da910b1

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

tests/ui/from_over_into.fixed

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,15 @@ fn issue_12138() {
105105
}
106106
}
107107

108+
fn issue_112502() {
109+
struct MyInt(i64);
110+
111+
impl From<MyInt> for i64 {
112+
//~^ from_over_into
113+
fn from(val: MyInt) -> Self {
114+
val.0
115+
}
116+
}
117+
}
118+
108119
fn main() {}

tests/ui/from_over_into.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,15 @@ fn issue_12138() {
105105
}
106106
}
107107

108+
fn issue_112502() {
109+
struct MyInt(i64);
110+
111+
impl Into<i64> for MyInt {
112+
//~^ from_over_into
113+
fn into(self: MyInt) -> i64 {
114+
self.0
115+
}
116+
}
117+
}
118+
108119
fn main() {}

tests/ui/from_over_into.stderr

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,5 +107,21 @@ LL |
107107
LL ~ fn from(val: Hello) {}
108108
|
109109

110-
error: aborting due to 7 previous errors
110+
error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
111+
--> tests/ui/from_over_into.rs:111:5
112+
|
113+
LL | impl Into<i64> for MyInt {
114+
| ^^^^^^^^^^^^^^^^^^^^^^^^
115+
|
116+
= help: `impl From<Local> for Foreign` is allowed by the orphan rules, for more information see
117+
https://doc.rust-lang.org/reference/items/implementations.html#trait-implementation-coherence
118+
help: replace the `Into` implementation with `From<issue_112502::MyInt>`
119+
|
120+
LL ~ impl From<MyInt> for i64 {
121+
LL |
122+
LL ~ fn from(val: MyInt) -> Self {
123+
LL ~ val.0
124+
|
125+
126+
error: aborting due to 8 previous errors
111127

0 commit comments

Comments
 (0)