aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/tests/method_resolution.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty/src/tests/method_resolution.rs')
-rw-r--r--crates/hir_ty/src/tests/method_resolution.rs119
1 files changed, 119 insertions, 0 deletions
diff --git a/crates/hir_ty/src/tests/method_resolution.rs b/crates/hir_ty/src/tests/method_resolution.rs
index 4e3f9a9b6..61f18b0d2 100644
--- a/crates/hir_ty/src/tests/method_resolution.rs
+++ b/crates/hir_ty/src/tests/method_resolution.rs
@@ -1173,3 +1173,122 @@ fn main() {
1173"#, 1173"#,
1174 ); 1174 );
1175} 1175}
1176
1177#[test]
1178fn autoderef_visibility_field() {
1179 check_infer(
1180 r#"
1181#[lang = "deref"]
1182pub trait Deref {
1183 type Target;
1184 fn deref(&self) -> &Self::Target;
1185}
1186mod a {
1187 pub struct Foo(pub char);
1188 pub struct Bar(i32);
1189 impl Bar {
1190 pub fn new() -> Self {
1191 Self(0)
1192 }
1193 }
1194 impl super::Deref for Bar {
1195 type Target = Foo;
1196 fn deref(&self) -> &Foo {
1197 &Foo('z')
1198 }
1199 }
1200}
1201mod b {
1202 fn foo() {
1203 let x = super::a::Bar::new().0;
1204 }
1205}
1206 "#,
1207 expect![[r#"
1208 67..71 'self': &Self
1209 200..231 '{ ... }': Bar
1210 214..218 'Self': Bar(i32) -> Bar
1211 214..221 'Self(0)': Bar
1212 219..220 '0': i32
1213 315..319 'self': &Bar
1214 329..362 '{ ... }': &Foo
1215 343..352 '&Foo('z')': &Foo
1216 344..347 'Foo': Foo(char) -> Foo
1217 344..352 'Foo('z')': Foo
1218 348..351 ''z'': char
1219 392..439 '{ ... }': ()
1220 406..407 'x': char
1221 410..428 'super:...r::new': fn new() -> Bar
1222 410..430 'super:...:new()': Bar
1223 410..432 'super:...ew().0': char
1224 "#]],
1225 )
1226}
1227
1228#[test]
1229fn autoderef_visibility_method() {
1230 cov_mark::check!(autoderef_candidate_not_visible);
1231 check_infer(
1232 r#"
1233#[lang = "deref"]
1234pub trait Deref {
1235 type Target;
1236 fn deref(&self) -> &Self::Target;
1237}
1238mod a {
1239 pub struct Foo(pub char);
1240 impl Foo {
1241 pub fn mango(&self) -> char {
1242 self.0
1243 }
1244 }
1245 pub struct Bar(i32);
1246 impl Bar {
1247 pub fn new() -> Self {
1248 Self(0)
1249 }
1250 fn mango(&self) -> i32 {
1251 self.0
1252 }
1253 }
1254 impl super::Deref for Bar {
1255 type Target = Foo;
1256 fn deref(&self) -> &Foo {
1257 &Foo('z')
1258 }
1259 }
1260}
1261mod b {
1262 fn foo() {
1263 let x = super::a::Bar::new().mango();
1264 }
1265}
1266 "#,
1267 expect![[r#"
1268 67..71 'self': &Self
1269 168..172 'self': &Foo
1270 182..212 '{ ... }': char
1271 196..200 'self': &Foo
1272 196..202 'self.0': char
1273 288..319 '{ ... }': Bar
1274 302..306 'Self': Bar(i32) -> Bar
1275 302..309 'Self(0)': Bar
1276 307..308 '0': i32
1277 338..342 'self': &Bar
1278 351..381 '{ ... }': i32
1279 365..369 'self': &Bar
1280 365..371 'self.0': i32
1281 465..469 'self': &Bar
1282 479..512 '{ ... }': &Foo
1283 493..502 '&Foo('z')': &Foo
1284 494..497 'Foo': Foo(char) -> Foo
1285 494..502 'Foo('z')': Foo
1286 498..501 ''z'': char
1287 542..595 '{ ... }': ()
1288 556..557 'x': char
1289 560..578 'super:...r::new': fn new() -> Bar
1290 560..580 'super:...:new()': Bar
1291 560..588 'super:...ango()': char
1292 "#]],
1293 )
1294}