diff options
Diffstat (limited to 'crates/ra_hir_ty/src/tests')
-rw-r--r-- | crates/ra_hir_ty/src/tests/traits.rs | 93 |
1 files changed, 34 insertions, 59 deletions
diff --git a/crates/ra_hir_ty/src/tests/traits.rs b/crates/ra_hir_ty/src/tests/traits.rs index 529d9e253..85bcd0050 100644 --- a/crates/ra_hir_ty/src/tests/traits.rs +++ b/crates/ra_hir_ty/src/tests/traits.rs | |||
@@ -3000,69 +3000,44 @@ fn infer_box_fn_arg() { | |||
3000 | 3000 | ||
3001 | #[test] | 3001 | #[test] |
3002 | fn infer_dyn_fn_output() { | 3002 | fn infer_dyn_fn_output() { |
3003 | assert_snapshot!( | 3003 | check_types( |
3004 | infer( | 3004 | r#" |
3005 | r#" | 3005 | //- /lib.rs |
3006 | //- /lib.rs deps:std | 3006 | #[lang = "fn_once"] |
3007 | 3007 | pub trait FnOnce<Args> { | |
3008 | #[lang = "fn_once"] | 3008 | type Output; |
3009 | pub trait FnOnce<Args> { | 3009 | extern "rust-call" fn call_once(self, args: Args) -> Self::Output; |
3010 | type Output; | 3010 | } |
3011 | |||
3012 | extern "rust-call" fn call_once(self, args: Args) -> Self::Output; | ||
3013 | } | ||
3014 | |||
3015 | #[lang = "fn"] | ||
3016 | pub trait Fn<Args>:FnOnce<Args> { | ||
3017 | extern "rust-call" fn call(&self, args: Args) -> Self::Output; | ||
3018 | } | ||
3019 | |||
3020 | #[lang = "deref"] | ||
3021 | pub trait Deref { | ||
3022 | type Target: ?Sized; | ||
3023 | |||
3024 | fn deref(&self) -> &Self::Target; | ||
3025 | } | ||
3026 | 3011 | ||
3027 | #[lang = "owned_box"] | 3012 | #[lang = "fn"] |
3028 | pub struct Box<T: ?Sized> { | 3013 | pub trait Fn<Args>: FnOnce<Args> { |
3029 | inner: *mut T, | 3014 | extern "rust-call" fn call(&self, args: Args) -> Self::Output; |
3030 | } | 3015 | } |
3031 | 3016 | ||
3032 | impl<T: ?Sized> Deref for Box<T> { | 3017 | fn foo() { |
3033 | type Target = T; | 3018 | let f: &dyn Fn() -> i32; |
3019 | f(); | ||
3020 | //^^^ i32 | ||
3021 | }"#, | ||
3022 | ); | ||
3023 | } | ||
3034 | 3024 | ||
3035 | fn deref(&self) -> &T { | 3025 | #[test] |
3036 | &self.inner | 3026 | fn infer_dyn_fn_once_output() { |
3037 | } | 3027 | check_types( |
3038 | } | 3028 | r#" |
3029 | //- /lib.rs | ||
3030 | #[lang = "fn_once"] | ||
3031 | pub trait FnOnce<Args> { | ||
3032 | type Output; | ||
3033 | extern "rust-call" fn call_once(self, args: Args) -> Self::Output; | ||
3034 | } | ||
3039 | 3035 | ||
3040 | fn foo() { | 3036 | fn foo() { |
3041 | let f: Box<dyn Fn() -> i32> = box(|| 5); | 3037 | let f: dyn FnOnce() -> i32; |
3042 | let x = f(); | 3038 | f(); |
3043 | } | 3039 | //^^^ i32 |
3044 | "# | 3040 | }"#, |
3045 | ), | ||
3046 | @r###" | ||
3047 | 100..104 'self': Self | ||
3048 | 106..110 'args': Args | ||
3049 | 219..223 'self': &Self | ||
3050 | 225..229 'args': Args | ||
3051 | 333..337 'self': &Self | ||
3052 | 503..507 'self': &Box<T> | ||
3053 | 515..542 '{ ... }': &T | ||
3054 | 525..536 '&self.inner': &*mut T | ||
3055 | 526..530 'self': &Box<T> | ||
3056 | 526..536 'self.inner': *mut T | ||
3057 | 555..620 '{ ...f(); }': () | ||
3058 | 565..566 'f': Box<dyn Fn<(), Output = i32>> | ||
3059 | 591..600 'box(|| 5)': Box<|| -> i32> | ||
3060 | 595..599 '|| 5': || -> i32 | ||
3061 | 598..599 '5': i32 | ||
3062 | 610..611 'x': FnOnce::Output<dyn Fn<(), Output = i32>, ()> | ||
3063 | 614..615 'f': Box<dyn Fn<(), Output = i32>> | ||
3064 | 614..617 'f()': FnOnce::Output<dyn Fn<(), Output = i32>, ()> | ||
3065 | "### | ||
3066 | ); | 3041 | ); |
3067 | } | 3042 | } |
3068 | 3043 | ||