aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/tests
diff options
context:
space:
mode:
authorcynecx <[email protected]>2021-03-20 16:13:58 +0000
committercynecx <[email protected]>2021-03-20 16:26:18 +0000
commitedfd741c5bdd9bbc044e3e362f5b446db7d817ef (patch)
treefb9dfb9a6adcf7017287ecd59ef10d6ce5d2b90f /crates/hir_ty/src/tests
parent15e4aae82329e5c53e488c54fb0561bb289f5c21 (diff)
hir_ty: add tests around autoderef with visibility checking
Diffstat (limited to 'crates/hir_ty/src/tests')
-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..751a7ce54 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 check_infer(
1231 r#"
1232#[lang = "deref"]
1233pub trait Deref {
1234 type Target;
1235 fn deref(&self) -> &Self::Target;
1236}
1237mod a {
1238 pub struct Foo(pub char);
1239
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 173..177 'self': &Foo
1270 187..217 '{ ... }': char
1271 201..205 'self': &Foo
1272 201..207 'self.0': char
1273 293..324 '{ ... }': Bar
1274 307..311 'Self': Bar(i32) -> Bar
1275 307..314 'Self(0)': Bar
1276 312..313 '0': i32
1277 343..347 'self': &Bar
1278 356..386 '{ ... }': i32
1279 370..374 'self': &Bar
1280 370..376 'self.0': i32
1281 470..474 'self': &Bar
1282 484..517 '{ ... }': &Foo
1283 498..507 '&Foo('z')': &Foo
1284 499..502 'Foo': Foo(char) -> Foo
1285 499..507 'Foo('z')': Foo
1286 503..506 ''z'': char
1287 547..600 '{ ... }': ()
1288 561..562 'x': char
1289 565..583 'super:...r::new': fn new() -> Bar
1290 565..585 'super:...:new()': Bar
1291 565..593 'super:...ango()': char
1292 "#]],
1293 )
1294}