Skip to content

Commit eb2cc10

Browse files
committed
Adapt tests for correct behavior
1 parent 190f37a commit eb2cc10

File tree

1 file changed

+44
-4
lines changed

1 file changed

+44
-4
lines changed

crates/hir_ty/src/tests/coercion.rs

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ fn test() {
390390
let _: &Foo<[usize]> = &Foo { t: [1, 2, 3] };
391391
//^^^^^^^^^ expected [usize], got [usize; 3]
392392
let _: &Bar<[usize]> = &Bar(Foo { t: [1, 2, 3] });
393-
//^^^^^^^^^^^^^^^^^^^^^^^^^^ expected &Bar<[usize]>, got &Bar<[i32; 3]>
393+
//^^^^^^^^^ expected [usize], got [usize; 3]
394394
}
395395
"#,
396396
);
@@ -522,8 +522,7 @@ fn main() {
522522

523523
#[test]
524524
fn coerce_unsize_expected_type_2() {
525-
// FIXME: this is wrong, #9560
526-
check(
525+
check_no_mismatches(
527526
r#"
528527
//- minicore: coerce_unsized
529528
struct InFile<T>;
@@ -540,7 +539,48 @@ fn test() {
540539
let x: InFile<()> = InFile;
541540
let n = &RecordField;
542541
takes_dyn(x.with_value(n));
543-
// ^^^^^^^^^^^^^^^ expected InFile<&dyn AstNode>, got InFile<&RecordField>
542+
}
543+
"#,
544+
);
545+
}
546+
547+
#[test]
548+
fn coerce_unsize_expected_type_3() {
549+
check_no_mismatches(
550+
r#"
551+
//- minicore: coerce_unsized
552+
enum Option<T> { Some(T), None }
553+
struct RecordField;
554+
trait AstNode {}
555+
impl AstNode for RecordField {}
556+
557+
fn takes_dyn(it: Option<&dyn AstNode>) {}
558+
559+
fn test() {
560+
let x: InFile<()> = InFile;
561+
let n = &RecordField;
562+
takes_dyn(Option::Some(n));
563+
}
564+
"#,
565+
);
566+
}
567+
568+
#[test]
569+
fn coerce_unsize_expected_type_4() {
570+
check_no_mismatches(
571+
r#"
572+
//- minicore: coerce_unsized
573+
use core::{marker::Unsize, ops::CoerceUnsized};
574+
575+
struct B<T: ?Sized>(*const T);
576+
impl<T: ?Sized> B<T> {
577+
fn new(t: T) -> Self { B(&t) }
578+
}
579+
580+
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<B<U>> for B<T> {}
581+
582+
fn test() {
583+
let _: B<[isize]> = B::new({ [1, 2, 3] });
544584
}
545585
"#,
546586
);

0 commit comments

Comments
 (0)