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