File tree 4 files changed +46
-8
lines changed
4 files changed +46
-8
lines changed Original file line number Diff line number Diff line change @@ -176,8 +176,8 @@ fn convert_to_from(
176
176
return None ;
177
177
} ;
178
178
let body = cx. tcx . hir_body ( body_id) ;
179
- let [ input ] = body. params else { return None } ;
180
- let PatKind :: Binding ( .., self_ident, None ) = input . pat . kind else {
179
+ let [ self_param ] = body. params else { return None } ;
180
+ let PatKind :: Binding ( .., self_ident, None ) = self_param . pat . kind else {
181
181
return None ;
182
182
} ;
183
183
@@ -194,12 +194,12 @@ fn convert_to_from(
194
194
// impl Into<T> for U -> impl Into<T> for T
195
195
// ~ ~
196
196
( self_ty. span, into. to_owned( ) ) ,
197
- // fn into(self) -> T -> fn from(self) -> T
198
- // ~~~~ ~~~~
197
+ // fn into(self: U ) -> T -> fn from(self) -> T
198
+ // ~~~~ ~~~~
199
199
( impl_item. ident. span, String :: from( "from" ) ) ,
200
- // fn into([mut] self) -> T -> fn into([mut] v : T) -> T
201
- // ~~~~ ~~~~
202
- ( self_ident. span, format!( "val: {from}" ) ) ,
200
+ // fn into([mut] self: U ) -> T -> fn into([mut] val : T) -> T
201
+ // ~~~~~~~ ~~ ~~~~
202
+ ( self_ident. span. to ( self_param . ty_span ) , format!( "val: {from}" ) ) ,
203
203
] ;
204
204
205
205
if let FnRetTy :: Return ( _) = sig. decl . output {
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