From f07338bae2e4209d5e47e69f131bfa9efc56c890 Mon Sep 17 00:00:00 2001 From: adamrk Date: Sat, 20 Jun 2020 11:43:40 +0200 Subject: [PATCH] Add test for dyn Fn Output --- crates/ra_hir_ty/src/tests/traits.rs | 68 ++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/crates/ra_hir_ty/src/tests/traits.rs b/crates/ra_hir_ty/src/tests/traits.rs index 8efe058771..dd5bdd2d01 100644 --- a/crates/ra_hir_ty/src/tests/traits.rs +++ b/crates/ra_hir_ty/src/tests/traits.rs @@ -3043,3 +3043,71 @@ fn infer_box_fn_arg() { "### ); } + +#[test] +fn infer_dyn_fn_output() { + assert_snapshot!( + infer( + 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 = "fn"] + pub trait Fn:FnOnce { + extern "rust-call" fn call(&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 + } + } + + fn foo() { + let f: Box i32> = box(|| 5); + let x = f(); + } + "# + ), + @r###" + 182..186 'self': Self + 188..192 'args': Args + 349..353 'self': &Self + 355..359 'args': Args + 523..527 'self': &Self + 789..793 'self': &Box + 801..852 '{ ... }': &T + 823..834 '&self.inner': &*mut T + 824..828 'self': &Box + 824..834 'self.inner': *mut T + 889..990 '{ ... }': () + 911..912 'f': Box> + 937..946 'box(|| 5)': Box<|| -> i32> + 941..945 '|| 5': || -> i32 + 944..945 '5': i32 + 968..969 'x': i32 + 972..973 'f': Box> + 972..975 'f()': i32 + "### + ); +}