@@ -1079,6 +1079,11 @@ mod method_call_type_conversion {
1079
1079
#[ derive( Debug , Copy , Clone ) ]
1080
1080
struct S2 ;
1081
1081
1082
+ #[ derive( Debug , Copy , Clone , Default ) ]
1083
+ struct MyInt {
1084
+ a : i64 ,
1085
+ }
1086
+
1082
1087
impl < T > S < T > {
1083
1088
fn m1 ( self ) -> T {
1084
1089
self . 0 // $ fieldof=S
@@ -1093,6 +1098,24 @@ mod method_call_type_conversion {
1093
1098
}
1094
1099
}
1095
1100
1101
+ trait ATrait {
1102
+ fn method_on_borrow ( & self ) -> i64 ;
1103
+ fn method_not_on_borrow ( self ) -> i64 ;
1104
+ }
1105
+
1106
+ // Trait implementation on a borrow.
1107
+ impl ATrait for & MyInt {
1108
+ // MyInt::method_on_borrow
1109
+ fn method_on_borrow ( & self ) -> i64 {
1110
+ ( * ( * self ) ) . a // $ method=deref fieldof=MyInt
1111
+ }
1112
+
1113
+ // MyInt::method_not_on_borrow
1114
+ fn method_not_on_borrow ( self ) -> i64 {
1115
+ ( * self ) . a // $ method=deref fieldof=MyInt
1116
+ }
1117
+ }
1118
+
1096
1119
pub fn f ( ) {
1097
1120
let x1 = S ( S2 ) ;
1098
1121
println ! ( "{:?}" , x1. m1( ) ) ; // $ method=m1
@@ -1128,10 +1151,21 @@ mod method_call_type_conversion {
1128
1151
let t = x7. m1 ( ) ; // $ method=m1 type=t:& type=t:&T.S2
1129
1152
println ! ( "{:?}" , x7) ;
1130
1153
1131
- let x9 : String = "Hello" . to_string ( ) ; // $ type=x9:String
1154
+ let x9: String = "Hello" . to_string ( ) ; // $ type=x9:String
1155
+
1132
1156
// Implicit `String` -> `str` conversion happens via the `Deref` trait:
1133
1157
// https://doc.rust-lang.org/std/string/struct.String.html#deref.
1134
1158
let u = x9. parse :: < u32 > ( ) ; // $ method=parse type=u:T.u32
1159
+
1160
+ let my_thing = & MyInt { a : 37 } ;
1161
+ // implicit borrow of a `&`
1162
+ let a = my_thing. method_on_borrow ( ) ; // $ MISSING: method=MyInt::method_on_borrow
1163
+ println ! ( "{:?}" , a) ;
1164
+
1165
+ // no implicit borrow
1166
+ let my_thing = & MyInt { a : 38 } ;
1167
+ let a = my_thing. method_not_on_borrow ( ) ; // $ MISSING: method=MyInt::method_not_on_borrow
1168
+ println ! ( "{:?}" , a) ;
1135
1169
}
1136
1170
}
1137
1171
0 commit comments