Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-ty/src/tests/traits.rs')
-rw-r--r--crates/hir-ty/src/tests/traits.rs69
1 files changed, 38 insertions, 31 deletions
diff --git a/crates/hir-ty/src/tests/traits.rs b/crates/hir-ty/src/tests/traits.rs
index 38591f486e..390553c0d7 100644
--- a/crates/hir-ty/src/tests/traits.rs
+++ b/crates/hir-ty/src/tests/traits.rs
@@ -429,7 +429,7 @@ fn associated_type_shorthand_from_method_bound() {
trait Iterable {
type Item;
}
-struct S<T>;
+struct S<T>(T);
impl<T> S<T> {
fn foo(self) -> T::Item where T: Iterable { loop {} }
}
@@ -1103,40 +1103,50 @@ fn test() {
fn argument_impl_trait_type_args_2() {
check_infer_with_mismatches(
r#"
-//- minicore: sized
+//- minicore: sized, phantom_data
+use core::marker::PhantomData;
+
trait Trait {}
struct S;
impl Trait for S {}
-struct F<T>;
+struct F<T>(PhantomData<T>);
impl<T> F<T> {
fn foo<U>(self, x: impl Trait) -> (T, U) { loop {} }
}
fn test() {
- F.foo(S);
- F::<u32>.foo(S);
- F::<u32>.foo::<i32>(S);
- F::<u32>.foo::<i32, u32>(S); // extraneous argument should be ignored
+ F(PhantomData).foo(S);
+ F::<u32>(PhantomData).foo(S);
+ F::<u32>(PhantomData).foo::<i32>(S);
+ F::<u32>(PhantomData).foo::<i32, u32>(S); // extraneous argument should be ignored
}"#,
expect![[r#"
- 87..91 'self': F<T>
- 93..94 'x': impl Trait
- 118..129 '{ loop {} }': (T, U)
- 120..127 'loop {}': !
- 125..127 '{}': ()
- 143..283 '{ ...ored }': ()
- 149..150 'F': F<{unknown}>
- 149..157 'F.foo(S)': ({unknown}, {unknown})
- 155..156 'S': S
- 163..171 'F::<u32>': F<u32>
- 163..178 'F::<u32>.foo(S)': (u32, {unknown})
- 176..177 'S': S
- 184..192 'F::<u32>': F<u32>
- 184..206 'F::<u3...32>(S)': (u32, i32)
- 204..205 'S': S
- 212..220 'F::<u32>': F<u32>
- 212..239 'F::<u3...32>(S)': (u32, i32)
- 237..238 'S': S
+ 135..139 'self': F<T>
+ 141..142 'x': impl Trait
+ 166..177 '{ loop {} }': (T, U)
+ 168..175 'loop {}': !
+ 173..175 '{}': ()
+ 191..383 '{ ...ored }': ()
+ 197..198 'F': fn F<{unknown}>(PhantomData<{unknown}>) -> F<{unknown}>
+ 197..211 'F(PhantomData)': F<{unknown}>
+ 197..218 'F(Phan...foo(S)': ({unknown}, {unknown})
+ 199..210 'PhantomData': PhantomData<{unknown}>
+ 216..217 'S': S
+ 224..232 'F::<u32>': fn F<u32>(PhantomData<u32>) -> F<u32>
+ 224..245 'F::<u3...mData)': F<u32>
+ 224..252 'F::<u3...foo(S)': (u32, {unknown})
+ 233..244 'PhantomData': PhantomData<u32>
+ 250..251 'S': S
+ 258..266 'F::<u32>': fn F<u32>(PhantomData<u32>) -> F<u32>
+ 258..279 'F::<u3...mData)': F<u32>
+ 258..293 'F::<u3...32>(S)': (u32, i32)
+ 267..278 'PhantomData': PhantomData<u32>
+ 291..292 'S': S
+ 299..307 'F::<u32>': fn F<u32>(PhantomData<u32>) -> F<u32>
+ 299..320 'F::<u3...mData)': F<u32>
+ 299..339 'F::<u3...32>(S)': (u32, i32)
+ 308..319 'PhantomData': PhantomData<u32>
+ 337..338 'S': S
"#]],
);
}
@@ -4012,7 +4022,7 @@ fn f<F: Foo>() {
fn dyn_map() {
check_types(
r#"
-pub struct Key<K, V, P = (K, V)> {}
+pub struct Key<K, V, P = (K, V)>(K, V, P);
pub trait Policy {
type K;
@@ -4024,7 +4034,7 @@ impl<K, V> Policy for (K, V) {
type V = V;
}
-pub struct KeyMap<KEY> {}
+pub struct KeyMap<KEY>(KEY);
impl<P: Policy> KeyMap<Key<P::K, P::V, P>> {
pub fn get(&self, key: &P::K) -> P::V {
@@ -4859,7 +4869,6 @@ async fn baz<T: AsyncFnOnce(u32) -> i32>(c: T) {
expect![[r#"
37..38 'a': T
43..83 '{ ...ait; }': ()
- 43..83 '{ ...ait; }': impl Future<Output = ()>
53..57 'fut1': <T as AsyncFnMut<(u32,)>>::CallRefFuture<'?>
60..61 'a': T
60..64 'a(0)': <T as AsyncFnMut<(u32,)>>::CallRefFuture<'?>
@@ -4868,7 +4877,6 @@ async fn baz<T: AsyncFnOnce(u32) -> i32>(c: T) {
70..80 'fut1.await': i32
124..129 'mut b': T
134..174 '{ ...ait; }': ()
- 134..174 '{ ...ait; }': impl Future<Output = ()>
144..148 'fut2': <T as AsyncFnMut<(u32,)>>::CallRefFuture<'?>
151..152 'b': T
151..155 'b(0)': <T as AsyncFnMut<(u32,)>>::CallRefFuture<'?>
@@ -4877,7 +4885,6 @@ async fn baz<T: AsyncFnOnce(u32) -> i32>(c: T) {
161..171 'fut2.await': i32
216..217 'c': T
222..262 '{ ...ait; }': ()
- 222..262 '{ ...ait; }': impl Future<Output = ()>
232..236 'fut3': <T as AsyncFnOnce<(u32,)>>::CallOnceFuture
239..240 'c': T
239..243 'c(0)': <T as AsyncFnOnce<(u32,)>>::CallOnceFuture
@@ -5023,7 +5030,7 @@ fn main() {
278..280 '{}': ()
290..291 '_': Box<dyn Iterator<Item = &'? [u8]> + '?>
294..298 'iter': Box<dyn Iterator<Item = &'? [u8]> + 'static>
- 294..310 'iter.i...iter()': Box<dyn Iterator<Item = &'? [u8]> + 'static>
+ 294..310 'iter.i...iter()': Box<dyn Iterator<Item = &'? [u8]> + '?>
152..156 'self': &'? mut Box<I>
177..208 '{ ... }': Option<<I as Iterator>::Item>
191..198 'loop {}': !