From 15e4aae82329e5c53e488c54fb0561bb289f5c21 Mon Sep 17 00:00:00 2001 From: cynecx Date: Sat, 20 Mar 2021 17:12:49 +0100 Subject: hir_ty: fix tests by making required methods public --- crates/hir_ty/src/tests/macros.rs | 4 ++-- crates/hir_ty/src/tests/traits.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'crates/hir_ty/src/tests') diff --git a/crates/hir_ty/src/tests/macros.rs b/crates/hir_ty/src/tests/macros.rs index c1e605740..88ba9b118 100644 --- a/crates/hir_ty/src/tests/macros.rs +++ b/crates/hir_ty/src/tests/macros.rs @@ -31,12 +31,12 @@ struct S; #[cfg(not(test))] impl S { - fn foo3(&self) -> i32 { 0 } + pub fn foo3(&self) -> i32 { 0 } } #[cfg(test)] impl S { - fn foo4(&self) -> i32 { 0 } + pub fn foo4(&self) -> i32 { 0 } } "#, ); diff --git a/crates/hir_ty/src/tests/traits.rs b/crates/hir_ty/src/tests/traits.rs index 8f2bdffc0..f7ee6def6 100644 --- a/crates/hir_ty/src/tests/traits.rs +++ b/crates/hir_ty/src/tests/traits.rs @@ -187,8 +187,8 @@ mod iter { mod collections { struct Vec {} impl Vec { - fn new() -> Self { Vec {} } - fn push(&mut self, t: T) { } + pub fn new() -> Self { Vec {} } + pub fn push(&mut self, t: T) { } } impl IntoIterator for Vec { -- cgit v1.2.3 From edfd741c5bdd9bbc044e3e362f5b446db7d817ef Mon Sep 17 00:00:00 2001 From: cynecx Date: Sat, 20 Mar 2021 17:13:58 +0100 Subject: hir_ty: add tests around autoderef with visibility checking --- crates/hir_ty/src/tests/method_resolution.rs | 119 +++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) (limited to 'crates/hir_ty/src/tests') 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() { "#, ); } + +#[test] +fn autoderef_visibility_field() { + check_infer( + r#" +#[lang = "deref"] +pub trait Deref { + type Target; + fn deref(&self) -> &Self::Target; +} +mod a { + pub struct Foo(pub char); + pub struct Bar(i32); + impl Bar { + pub fn new() -> Self { + Self(0) + } + } + impl super::Deref for Bar { + type Target = Foo; + fn deref(&self) -> &Foo { + &Foo('z') + } + } +} +mod b { + fn foo() { + let x = super::a::Bar::new().0; + } +} + "#, + expect![[r#" + 67..71 'self': &Self + 200..231 '{ ... }': Bar + 214..218 'Self': Bar(i32) -> Bar + 214..221 'Self(0)': Bar + 219..220 '0': i32 + 315..319 'self': &Bar + 329..362 '{ ... }': &Foo + 343..352 '&Foo('z')': &Foo + 344..347 'Foo': Foo(char) -> Foo + 344..352 'Foo('z')': Foo + 348..351 ''z'': char + 392..439 '{ ... }': () + 406..407 'x': char + 410..428 'super:...r::new': fn new() -> Bar + 410..430 'super:...:new()': Bar + 410..432 'super:...ew().0': char + "#]], + ) +} + +#[test] +fn autoderef_visibility_method() { + check_infer( + r#" +#[lang = "deref"] +pub trait Deref { + type Target; + fn deref(&self) -> &Self::Target; +} +mod a { + pub struct Foo(pub char); + + impl Foo { + pub fn mango(&self) -> char { + self.0 + } + } + pub struct Bar(i32); + impl Bar { + pub fn new() -> Self { + Self(0) + } + fn mango(&self) -> i32 { + self.0 + } + } + impl super::Deref for Bar { + type Target = Foo; + fn deref(&self) -> &Foo { + &Foo('z') + } + } +} +mod b { + fn foo() { + let x = super::a::Bar::new().mango(); + } +} + "#, + expect![[r#" + 67..71 'self': &Self + 173..177 'self': &Foo + 187..217 '{ ... }': char + 201..205 'self': &Foo + 201..207 'self.0': char + 293..324 '{ ... }': Bar + 307..311 'Self': Bar(i32) -> Bar + 307..314 'Self(0)': Bar + 312..313 '0': i32 + 343..347 'self': &Bar + 356..386 '{ ... }': i32 + 370..374 'self': &Bar + 370..376 'self.0': i32 + 470..474 'self': &Bar + 484..517 '{ ... }': &Foo + 498..507 '&Foo('z')': &Foo + 499..502 'Foo': Foo(char) -> Foo + 499..507 'Foo('z')': Foo + 503..506 ''z'': char + 547..600 '{ ... }': () + 561..562 'x': char + 565..583 'super:...r::new': fn new() -> Bar + 565..585 'super:...:new()': Bar + 565..593 'super:...ango()': char + "#]], + ) +} -- cgit v1.2.3 From 66d295d72df72640573522df527deb90abc94fcd Mon Sep 17 00:00:00 2001 From: cynecx Date: Sat, 20 Mar 2021 19:47:14 +0100 Subject: hir_ty: fix visibility in infer_inherent_method test --- crates/hir_ty/src/tests/simple.rs | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'crates/hir_ty/src/tests') diff --git a/crates/hir_ty/src/tests/simple.rs b/crates/hir_ty/src/tests/simple.rs index bcc43ed70..361cd6302 100644 --- a/crates/hir_ty/src/tests/simple.rs +++ b/crates/hir_ty/src/tests/simple.rs @@ -1103,7 +1103,7 @@ fn infer_inherent_method() { mod b { impl super::A { - fn bar(&self, x: u64) -> i64 {} + pub fn bar(&self, x: u64) -> i64 {} } } @@ -1117,21 +1117,21 @@ fn infer_inherent_method() { 31..35 'self': A 37..38 'x': u32 52..54 '{}': () - 102..106 'self': &A - 108..109 'x': u64 - 123..125 '{}': () - 143..144 'a': A - 149..197 '{ ...(1); }': () - 155..156 'a': A - 155..163 'a.foo(1)': i32 - 161..162 '1': u32 - 169..180 '(&a).bar(1)': i64 - 170..172 '&a': &A - 171..172 'a': A - 178..179 '1': u64 - 186..187 'a': A - 186..194 'a.bar(1)': i64 - 192..193 '1': u64 + 106..110 'self': &A + 112..113 'x': u64 + 127..129 '{}': () + 147..148 'a': A + 153..201 '{ ...(1); }': () + 159..160 'a': A + 159..167 'a.foo(1)': i32 + 165..166 '1': u32 + 173..184 '(&a).bar(1)': i64 + 174..176 '&a': &A + 175..176 'a': A + 182..183 '1': u64 + 190..191 'a': A + 190..198 'a.bar(1)': i64 + 196..197 '1': u64 "#]], ); } -- cgit v1.2.3 From 2dc85f739a678682d6b112d2d990802ffa4ffd90 Mon Sep 17 00:00:00 2001 From: cynecx Date: Sat, 20 Mar 2021 19:58:00 +0100 Subject: hir_ty: fix test by removing trailing whitespace --- crates/hir_ty/src/tests/method_resolution.rs | 47 ++++++++++++++-------------- 1 file changed, 23 insertions(+), 24 deletions(-) (limited to 'crates/hir_ty/src/tests') diff --git a/crates/hir_ty/src/tests/method_resolution.rs b/crates/hir_ty/src/tests/method_resolution.rs index 751a7ce54..6e74763ca 100644 --- a/crates/hir_ty/src/tests/method_resolution.rs +++ b/crates/hir_ty/src/tests/method_resolution.rs @@ -1236,7 +1236,6 @@ pub trait Deref { } mod a { pub struct Foo(pub char); - impl Foo { pub fn mango(&self) -> char { self.0 @@ -1266,29 +1265,29 @@ mod b { "#, expect![[r#" 67..71 'self': &Self - 173..177 'self': &Foo - 187..217 '{ ... }': char - 201..205 'self': &Foo - 201..207 'self.0': char - 293..324 '{ ... }': Bar - 307..311 'Self': Bar(i32) -> Bar - 307..314 'Self(0)': Bar - 312..313 '0': i32 - 343..347 'self': &Bar - 356..386 '{ ... }': i32 - 370..374 'self': &Bar - 370..376 'self.0': i32 - 470..474 'self': &Bar - 484..517 '{ ... }': &Foo - 498..507 '&Foo('z')': &Foo - 499..502 'Foo': Foo(char) -> Foo - 499..507 'Foo('z')': Foo - 503..506 ''z'': char - 547..600 '{ ... }': () - 561..562 'x': char - 565..583 'super:...r::new': fn new() -> Bar - 565..585 'super:...:new()': Bar - 565..593 'super:...ango()': char + 168..172 'self': &Foo + 182..212 '{ ... }': char + 196..200 'self': &Foo + 196..202 'self.0': char + 288..319 '{ ... }': Bar + 302..306 'Self': Bar(i32) -> Bar + 302..309 'Self(0)': Bar + 307..308 '0': i32 + 338..342 'self': &Bar + 351..381 '{ ... }': i32 + 365..369 'self': &Bar + 365..371 'self.0': i32 + 465..469 'self': &Bar + 479..512 '{ ... }': &Foo + 493..502 '&Foo('z')': &Foo + 494..497 'Foo': Foo(char) -> Foo + 494..502 'Foo('z')': Foo + 498..501 ''z'': char + 542..595 '{ ... }': () + 556..557 'x': char + 560..578 'super:...r::new': fn new() -> Bar + 560..580 'super:...:new()': Bar + 560..588 'super:...ango()': char "#]], ) } -- cgit v1.2.3 From 42abfa0f885834c3c2bf61a4d0fafaa3f570debd Mon Sep 17 00:00:00 2001 From: cynecx Date: Sat, 20 Mar 2021 20:35:57 +0100 Subject: hir_ty: add coverage testing for autoderef_visibility_method test --- crates/hir_ty/src/tests/method_resolution.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'crates/hir_ty/src/tests') diff --git a/crates/hir_ty/src/tests/method_resolution.rs b/crates/hir_ty/src/tests/method_resolution.rs index 6e74763ca..61f18b0d2 100644 --- a/crates/hir_ty/src/tests/method_resolution.rs +++ b/crates/hir_ty/src/tests/method_resolution.rs @@ -1227,6 +1227,7 @@ mod b { #[test] fn autoderef_visibility_method() { + cov_mark::check!(autoderef_candidate_not_visible); check_infer( r#" #[lang = "deref"] -- cgit v1.2.3