From eb2cc1036afd99f36c3784d36da64b1282ba8d3c Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Thu, 15 Jul 2021 20:02:48 +0200 Subject: [PATCH] Adapt tests for correct behavior --- crates/hir_ty/src/tests/coercion.rs | 48 ++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/crates/hir_ty/src/tests/coercion.rs b/crates/hir_ty/src/tests/coercion.rs index 8db1592c916..8b022b6be9b 100644 --- a/crates/hir_ty/src/tests/coercion.rs +++ b/crates/hir_ty/src/tests/coercion.rs @@ -390,7 +390,7 @@ fn test() { let _: &Foo<[usize]> = &Foo { t: [1, 2, 3] }; //^^^^^^^^^ expected [usize], got [usize; 3] let _: &Bar<[usize]> = &Bar(Foo { t: [1, 2, 3] }); - //^^^^^^^^^^^^^^^^^^^^^^^^^^ expected &Bar<[usize]>, got &Bar<[i32; 3]> + //^^^^^^^^^ expected [usize], got [usize; 3] } "#, ); @@ -522,8 +522,7 @@ fn main() { #[test] fn coerce_unsize_expected_type_2() { - // FIXME: this is wrong, #9560 - check( + check_no_mismatches( r#" //- minicore: coerce_unsized struct InFile; @@ -540,7 +539,48 @@ fn test() { let x: InFile<()> = InFile; let n = &RecordField; takes_dyn(x.with_value(n)); - // ^^^^^^^^^^^^^^^ expected InFile<&dyn AstNode>, got InFile<&RecordField> +} + "#, + ); +} + +#[test] +fn coerce_unsize_expected_type_3() { + check_no_mismatches( + r#" +//- minicore: coerce_unsized +enum Option { Some(T), None } +struct RecordField; +trait AstNode {} +impl AstNode for RecordField {} + +fn takes_dyn(it: Option<&dyn AstNode>) {} + +fn test() { + let x: InFile<()> = InFile; + let n = &RecordField; + takes_dyn(Option::Some(n)); +} + "#, + ); +} + +#[test] +fn coerce_unsize_expected_type_4() { + check_no_mismatches( + r#" +//- minicore: coerce_unsized +use core::{marker::Unsize, ops::CoerceUnsized}; + +struct B(*const T); +impl B { + fn new(t: T) -> Self { B(&t) } +} + +impl, U: ?Sized> CoerceUnsized> for B {} + +fn test() { + let _: B<[isize]> = B::new({ [1, 2, 3] }); } "#, );