From ac961b261458bfeb23f7d4e896d5f957b0854a3a Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 6 Dec 2019 12:45:00 +0100 Subject: Add test for unifying impl Trait --- crates/ra_hir_ty/src/tests/traits.rs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 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 6139adb72..a926d01e5 100644 --- a/crates/ra_hir_ty/src/tests/traits.rs +++ b/crates/ra_hir_ty/src/tests/traits.rs @@ -1,4 +1,4 @@ -use super::{infer, type_at, type_at_pos}; +use super::{infer, infer_with_mismatches, type_at, type_at_pos}; use crate::test_db::TestDB; use insta::assert_snapshot; use ra_db::fixture::WithFixture; @@ -1486,3 +1486,29 @@ fn test() where T: Trait, U: Trait { // this is a legitimate cycle assert_eq!(t, "{unknown}"); } + +#[test] +fn unify_impl_trait() { + assert_snapshot!( + infer_with_mismatches(r#" +trait Trait {} + +fn foo(x: impl Trait) { loop {} } +fn bar(x: impl Trait) -> T { loop {} } + +struct S(T); +impl Trait for S {} + +fn default() -> T { loop {} } + +fn test() -> impl Trait { + let s1 = S(default()); + foo(s1); + let x: i32 = bar(S(default())); + S(default()) +} +"#, true), + @r###" + "### + ); +} -- cgit v1.2.3