From c82f5379de49344eb418cc6aaf5bf8c35bc4aaef Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 10 Jul 2020 18:30:32 +0200 Subject: Enable Chalk tracing in hir_ty tests --- crates/ra_hir_ty/src/tests/traits.rs | 93 +++++++++++++----------------------- 1 file changed, 34 insertions(+), 59 deletions(-) (limited to 'crates/ra_hir_ty/src/tests') 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() { #[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; - } + check_types( + r#" +//- /lib.rs +#[lang = "fn_once"] +pub trait FnOnce { + type Output; + extern "rust-call" fn call_once(self, args: Args) -> Self::Output; +} - #[lang = "owned_box"] - pub struct Box { - inner: *mut T, - } +#[lang = "fn"] +pub trait Fn: FnOnce { + extern "rust-call" fn call(&self, args: Args) -> Self::Output; +} - impl Deref for Box { - type Target = T; +fn foo() { + let f: &dyn Fn() -> i32; + f(); + //^^^ i32 +}"#, + ); +} - fn deref(&self) -> &T { - &self.inner - } - } +#[test] +fn infer_dyn_fn_once_output() { + check_types( + r#" +//- /lib.rs +#[lang = "fn_once"] +pub trait FnOnce { + type Output; + extern "rust-call" fn call_once(self, args: Args) -> Self::Output; +} - fn foo() { - let f: Box i32> = box(|| 5); - let x = f(); - } - "# - ), - @r###" - 100..104 'self': Self - 106..110 'args': Args - 219..223 'self': &Self - 225..229 'args': Args - 333..337 'self': &Self - 503..507 'self': &Box - 515..542 '{ ... }': &T - 525..536 '&self.inner': &*mut T - 526..530 'self': &Box - 526..536 'self.inner': *mut T - 555..620 '{ ...f(); }': () - 565..566 'f': Box> - 591..600 'box(|| 5)': Box<|| -> i32> - 595..599 '|| 5': || -> i32 - 598..599 '5': i32 - 610..611 'x': FnOnce::Output, ()> - 614..615 'f': Box> - 614..617 'f()': FnOnce::Output, ()> - "### +fn foo() { + let f: dyn FnOnce() -> i32; + f(); + //^^^ i32 +}"#, ); } -- cgit v1.2.3 From 00bda1cafb1086b9669000aed5703f9e6324fbd7 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 11 Jul 2020 18:42:30 +0200 Subject: Adapt trait object coercion tests to the status quo --- crates/ra_hir_ty/src/tests/coercion.rs | 55 +++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 4 deletions(-) (limited to 'crates/ra_hir_ty/src/tests') diff --git a/crates/ra_hir_ty/src/tests/coercion.rs b/crates/ra_hir_ty/src/tests/coercion.rs index 136d28a91..d7fb6a962 100644 --- a/crates/ra_hir_ty/src/tests/coercion.rs +++ b/crates/ra_hir_ty/src/tests/coercion.rs @@ -662,7 +662,53 @@ fn test() { } #[test] -fn coerce_unsize_trait_object() { +fn coerce_unsize_trait_object_simple() { + assert_snapshot!( + infer_with_mismatches(r#" +#[lang = "sized"] +pub trait Sized {} +#[lang = "unsize"] +pub trait Unsize {} +#[lang = "coerce_unsized"] +pub trait CoerceUnsized {} + +impl, U> CoerceUnsized<&U> for &T {} + +trait Foo {} +trait Bar: Foo {} +trait Baz: Bar {} + +struct S; +impl Foo for S {} +impl Bar for S {} +impl Baz for S {} + +fn test() { + let obj: &dyn Baz = &S; + let obj: &dyn Bar<_, i8, i16> = &S; + let obj: &dyn Foo = &S; +} +"#, true), + @r###" + 424..539 '{ ... &S; }': () + 434..437 'obj': &dyn Baz + 459..461 '&S': &S + 460..461 'S': S + 471..474 'obj': &dyn Bar + 499..501 '&S': &S + 500..501 'S': S + 511..514 'obj': &dyn Foo + 534..536 '&S': &S + 535..536 'S': S + "### + ); +} + +#[test] +// The rust reference says this should be possible, but rustc doesn't implement +// it. We used to support it, but Chalk doesn't. +#[ignore] +fn coerce_unsize_trait_object_to_trait_object() { assert_snapshot!( infer_with_mismatches(r#" #[lang = "sized"] @@ -735,16 +781,17 @@ impl D for S {} fn test() { let obj: &dyn D = &S; - let obj: &dyn A = obj; + let obj: &dyn A = &S; } "#, true), @r###" - 328..384 '{ ...obj; }': () + 328..383 '{ ... &S; }': () 338..341 'obj': &dyn D 352..354 '&S': &S 353..354 'S': S 364..367 'obj': &dyn A - 378..381 'obj': &dyn D + 378..380 '&S': &S + 379..380 'S': S "### ); } -- cgit v1.2.3 From 7e9c4d58f189d4ac3c390a6ea345f2578dd5f661 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 11 Jul 2020 19:12:10 +0200 Subject: Search more efficiently for int/float impls --- crates/ra_hir_ty/src/tests/traits.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'crates/ra_hir_ty/src/tests') diff --git a/crates/ra_hir_ty/src/tests/traits.rs b/crates/ra_hir_ty/src/tests/traits.rs index 85bcd0050..511ed8fe3 100644 --- a/crates/ra_hir_ty/src/tests/traits.rs +++ b/crates/ra_hir_ty/src/tests/traits.rs @@ -3042,7 +3042,7 @@ fn foo() { } #[test] -fn variable_kinds() { +fn variable_kinds_1() { check_types( r#" trait Trait { fn get(self, t: T) -> T; } @@ -3058,3 +3058,20 @@ fn test() { "#, ); } + +#[test] +fn variable_kinds_2() { + check_types( + r#" +trait Trait { fn get(self) -> Self; } +impl Trait for u128 {} +impl Trait for f32 {} +fn test() { + 1.get(); + //^^^^^^^ u128 + (1.).get(); + //^^^^^^^^^^ f32 +} + "#, + ); +} -- cgit v1.2.3 From c6f53aaaa4d640cff809bba11af80051f29c6be5 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 11 Jul 2020 19:55:11 +0200 Subject: Add test for #4281 Fixes #4281. --- crates/ra_hir_ty/src/tests/traits.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'crates/ra_hir_ty/src/tests') diff --git a/crates/ra_hir_ty/src/tests/traits.rs b/crates/ra_hir_ty/src/tests/traits.rs index 511ed8fe3..05a56215f 100644 --- a/crates/ra_hir_ty/src/tests/traits.rs +++ b/crates/ra_hir_ty/src/tests/traits.rs @@ -1991,6 +1991,29 @@ fn test() { ); } +#[test] +fn fn_item_fn_trait() { + check_types( + r#" +//- /main.rs +#[lang = "fn_once"] +trait FnOnce { + type Output; +} + +struct S; + +fn foo() -> S {} + +fn takes_closure U>(f: F) -> U { f() } + +fn test() { + takes_closure(foo); +} //^^^^^^^^^^^^^^^^^^ S +"#, + ); +} + #[test] fn unselected_projection_in_trait_env_1() { check_types( -- cgit v1.2.3 From d885f38011b6d4265b527744234b3c317fe86501 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sun, 12 Jul 2020 19:59:43 +0200 Subject: Remove some unnecessary file names --- crates/ra_hir_ty/src/tests/traits.rs | 3 --- 1 file changed, 3 deletions(-) (limited to 'crates/ra_hir_ty/src/tests') diff --git a/crates/ra_hir_ty/src/tests/traits.rs b/crates/ra_hir_ty/src/tests/traits.rs index 05a56215f..27737fa94 100644 --- a/crates/ra_hir_ty/src/tests/traits.rs +++ b/crates/ra_hir_ty/src/tests/traits.rs @@ -1995,7 +1995,6 @@ fn test() { fn fn_item_fn_trait() { check_types( r#" -//- /main.rs #[lang = "fn_once"] trait FnOnce { type Output; @@ -3025,7 +3024,6 @@ fn infer_box_fn_arg() { fn infer_dyn_fn_output() { check_types( r#" -//- /lib.rs #[lang = "fn_once"] pub trait FnOnce { type Output; @@ -3049,7 +3047,6 @@ fn foo() { fn infer_dyn_fn_once_output() { check_types( r#" -//- /lib.rs #[lang = "fn_once"] pub trait FnOnce { type Output; -- cgit v1.2.3