From eefe02ce6e1750b771cf99125429358e87485745 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 7 Feb 2020 18:27:54 +0100 Subject: Add two more tests --- crates/ra_hir_ty/src/tests/traits.rs | 51 ++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'crates') diff --git a/crates/ra_hir_ty/src/tests/traits.rs b/crates/ra_hir_ty/src/tests/traits.rs index c6851fb69..17611ddbf 100644 --- a/crates/ra_hir_ty/src/tests/traits.rs +++ b/crates/ra_hir_ty/src/tests/traits.rs @@ -1013,6 +1013,31 @@ fn test() { ); } +#[test] +fn argument_impl_trait_to_fn_pointer() { + assert_snapshot!( + infer_with_mismatches(r#" +trait Trait {} +fn foo(x: impl Trait) { loop {} } +struct S; +impl Trait for S {} + +fn test() { + let f: fn(S) -> () = foo; +} +"#, true), + @r###" + [23; 24) 'x': impl Trait + [38; 49) '{ loop {} }': () + [40; 47) 'loop {}': ! + [45; 47) '{}': () + [91; 124) '{ ...foo; }': () + [101; 102) 'f': fn(S) -> () + [118; 121) 'foo': fn foo(S) -> () + "### + ); +} + #[test] #[ignore] fn impl_trait() { @@ -1376,6 +1401,32 @@ fn test(x: T, y: U) { ); } +#[test] +fn super_trait_impl_trait_method_resolution() { + assert_snapshot!( + infer(r#" +mod foo { + trait SuperTrait { + fn foo(&self) -> u32 {} + } +} +trait Trait1: foo::SuperTrait {} + +fn test(x: &impl Trait1) { + x.foo(); +} +"#), + @r###" + [50; 54) 'self': &Self + [63; 65) '{}': () + [116; 117) 'x': &impl Trait1 + [133; 149) '{ ...o(); }': () + [139; 140) 'x': &impl Trait1 + [139; 146) 'x.foo()': u32 + "### + ); +} + #[test] fn super_trait_cycle() { // This just needs to not crash -- cgit v1.2.3