From 3f94a90c7bbc1b3116a7960ae9f25ebe35d68ad0 Mon Sep 17 00:00:00 2001 From: adamrk Date: Sun, 7 Jun 2020 21:57:29 +0200 Subject: Infer FnSig from Fn traits --- crates/ra_ide/src/hover.rs | 99 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) (limited to 'crates/ra_ide/src') diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs index d870e4cbc..9a88b4977 100644 --- a/crates/ra_ide/src/hover.rs +++ b/crates/ra_ide/src/hover.rs @@ -2410,4 +2410,103 @@ fn func(foo: i32) { if true { <|>foo; }; } ] "###); } + + #[test] + fn infer_closure_arg() { + check_hover_result( + r#" + //- /lib.rs + + enum Option { + None, + Some(T) + } + + fn foo() { + let s<|> = Option::None; + let f = |x: Option| {}; + (&f)(s) + } + "#, + &["Option"], + ); + } + + #[test] + fn infer_fn_trait_arg() { + check_hover_result( + r#" + //- /lib.rs deps:std + + #[lang = "fn"] + pub trait Fn { + type Output; + + extern "rust-call" fn call(&self, args: Args) -> Self::Output; + } + + enum Option { + None, + Some(T) + } + + fn foo(f: F) -> T + where + F: Fn(Option) -> T, + { + let s<|> = None; + f(s) + } + "#, + &["Option"], + ); + } + + #[test] + fn infer_box_fn_arg() { + check_hover_result( + r#" + //- /lib.rs deps:std + + #[lang = "fn_once"] + pub trait FnOnce { + type Output; + + extern "rust-call" fn call_once(self, args: Args) -> Self::Output; + } + + #[lang = "deref"] + pub trait Deref { + type Target: ?Sized; + + fn deref(&self) -> &Self::Target; + } + + #[lang = "owned_box"] + pub struct Box { + inner: *mut T, + } + + impl Deref for Box { + type Target = T; + + fn deref(&self) -> &T { + &self.inner + } + } + + enum Option { + None, + Some(T) + } + + fn foo() { + let s<|> = Option::None; + let f: Box)> = box (|ps| {}); + f(&s) + } + "#, + &["Option"], + ); + } } -- cgit v1.2.3