aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/tests/traits.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty/src/tests/traits.rs')
-rw-r--r--crates/hir_ty/src/tests/traits.rs46
1 files changed, 36 insertions, 10 deletions
diff --git a/crates/hir_ty/src/tests/traits.rs b/crates/hir_ty/src/tests/traits.rs
index 41d097519..7ad8b5830 100644
--- a/crates/hir_ty/src/tests/traits.rs
+++ b/crates/hir_ty/src/tests/traits.rs
@@ -384,12 +384,12 @@ fn infer_project_associated_type() {
384 108..261 '{ ...ter; }': () 384 108..261 '{ ...ter; }': ()
385 118..119 'x': u32 385 118..119 'x': u32
386 145..146 '1': u32 386 145..146 '1': u32
387 156..157 'y': Iterable::Item<T> 387 156..157 'y': <T as Iterable>::Item
388 183..192 'no_matter': Iterable::Item<T> 388 183..192 'no_matter': <T as Iterable>::Item
389 202..203 'z': Iterable::Item<T> 389 202..203 'z': <T as Iterable>::Item
390 215..224 'no_matter': Iterable::Item<T> 390 215..224 'no_matter': <T as Iterable>::Item
391 234..235 'a': Iterable::Item<T> 391 234..235 'a': <T as Iterable>::Item
392 249..258 'no_matter': Iterable::Item<T> 392 249..258 'no_matter': <T as Iterable>::Item
393 "#]], 393 "#]],
394 ); 394 );
395} 395}
@@ -908,7 +908,6 @@ fn test<T: Trait>(t: T) { (*t); }
908 908
909#[test] 909#[test]
910fn associated_type_placeholder() { 910fn associated_type_placeholder() {
911 // inside the generic function, the associated type gets normalized to a placeholder `ApplL::Out<T>` [https://rust-lang.github.io/rustc-guide/traits/associated-types.html#placeholder-associated-types].
912 check_types( 911 check_types(
913 r#" 912 r#"
914pub trait ApplyL { 913pub trait ApplyL {
@@ -924,7 +923,7 @@ impl<T> ApplyL for RefMutL<T> {
924fn test<T: ApplyL>() { 923fn test<T: ApplyL>() {
925 let y: <RefMutL<T> as ApplyL>::Out = no_matter; 924 let y: <RefMutL<T> as ApplyL>::Out = no_matter;
926 y; 925 y;
927} //^ ApplyL::Out<T> 926} //^ <T as ApplyL>::Out
928"#, 927"#,
929 ); 928 );
930} 929}
@@ -941,7 +940,7 @@ fn foo<T: ApplyL>(t: T) -> <T as ApplyL>::Out;
941fn test<T: ApplyL>(t: T) { 940fn test<T: ApplyL>(t: T) {
942 let y = foo(t); 941 let y = foo(t);
943 y; 942 y;
944} //^ ApplyL::Out<T> 943} //^ <T as ApplyL>::Out
945"#, 944"#,
946 ); 945 );
947} 946}
@@ -2120,7 +2119,7 @@ fn unselected_projection_on_impl_self() {
2120 "#, 2119 "#,
2121 expect![[r#" 2120 expect![[r#"
2122 40..44 'self': &Self 2121 40..44 'self': &Self
2123 46..47 'x': Trait::Item<Self> 2122 46..47 'x': <Self as Trait>::Item
2124 126..130 'self': &S 2123 126..130 'self': &S
2125 132..133 'x': u32 2124 132..133 'x': u32
2126 147..161 '{ let y = x; }': () 2125 147..161 '{ let y = x; }': ()
@@ -3151,3 +3150,30 @@ fn test() {
3151 "#, 3150 "#,
3152 ); 3151 );
3153} 3152}
3153
3154#[test]
3155fn infer_call_method_return_associated_types_with_generic() {
3156 check_infer(
3157 r#"
3158 pub trait Default {
3159 fn default() -> Self;
3160 }
3161 pub trait Foo {
3162 type Bar: Default;
3163 }
3164
3165 pub fn quux<T: Foo>() -> T::Bar {
3166 let y = Default::default();
3167
3168 y
3169 }
3170 "#,
3171 expect![[r#"
3172 122..164 '{ ... y }': <T as Foo>::Bar
3173 132..133 'y': <T as Foo>::Bar
3174 136..152 'Defaul...efault': fn default<<T as Foo>::Bar>() -> <T as Foo>::Bar
3175 136..154 'Defaul...ault()': <T as Foo>::Bar
3176 161..162 'y': <T as Foo>::Bar
3177 "#]],
3178 );
3179}