File tree Expand file tree Collapse file tree 3 files changed +39
-1
lines changed Expand file tree Collapse file tree 3 files changed +39
-1
lines changed Original file line number Diff line number Diff line change @@ -105,4 +105,15 @@ fn issue_12138() {
105
105
}
106
106
}
107
107
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
+
108
119
fn main() {}
Original file line number Diff line number Diff line change @@ -105,4 +105,15 @@ fn issue_12138() {
105
105
}
106
106
}
107
107
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
+
108
119
fn main ( ) { }
Original file line number Diff line number Diff line change @@ -107,5 +107,21 @@ LL |
107
107
LL ~ fn from(val: Hello) {}
108
108
|
109
109
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
111
127
You can’t perform that action at this time.
0 commit comments