1 use super::{check, check_no_mismatches, check_types};
4 fn block_expr_type_mismatch() {
5 // FIXME fix double type mismatch
10 // ^^^^^^^^ expected i32, got i64
11 // ^^^^ expected i32, got i64
21 //- minicore: coerce_unsized
24 fn f<T>(_: &[T]) -> T { loop {} }
25 fn g<T>(_: S<&[T]>) -> T { loop {} }
27 fn gen<T>() -> *mut [T; 2] { loop {} }
28 fn test1<U>() -> *mut [U] {
33 let arr: &[u8; 1] = &[1];
37 let c: &[_] = { arr };
38 let d = g(S { a: arr });
39 let e: [&[_]; 1] = [arr];
40 let f: [&[_]; 2] = [arr; 2];
41 let g: (&[_], &[_]) = (arr, arr);
48 fn let_stmt_coerce() {
51 //- minicore: coerce_unsized
53 let x: &[isize] = &[1];
54 // ^^^^ adjustments: Deref(None), Borrow(Ref(Not)), Pointer(Unsize)
55 let x: *const [isize] = &[1];
56 // ^^^^ adjustments: Deref(None), Borrow(RawPtr(Not)), Pointer(Unsize)
63 fn custom_coerce_unsized() {
66 //- minicore: coerce_unsized
67 use core::{marker::Unsize, ops::CoerceUnsized};
69 struct A<T: ?Sized>(*const T);
70 struct B<T: ?Sized>(*const T);
71 struct C<T: ?Sized> { inner: *const T }
73 impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<B<U>> for B<T> {}
74 impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<C<U>> for C<T> {}
76 fn foo1<T>(x: A<[T]>) -> A<[T]> { x }
77 fn foo2<T>(x: B<[T]>) -> B<[T]> { x }
78 fn foo3<T>(x: C<[T]>) -> C<[T]> { x }
80 fn test(a: A<[u8; 2]>, b: B<[u8; 2]>, c: C<[u8; 2]>) {
82 // ^ expected A<[{unknown}]>, got A<[u8; 2]>
96 //- minicore: coerce_unsized
97 fn foo<T>(x: &[T]) -> &[T] { x }
101 // ^^^^ adjustments: Deref(None), Borrow(Ref(Not)), Pointer(Unsize)
111 fn if_else_coerce() {
114 //- minicore: coerce_unsized
115 fn foo<T>(x: &[T]) -> &[T] { x }
128 fn match_first_coerce() {
131 //- minicore: coerce_unsized
132 fn foo<T>(x: &[T]) -> &[T] { x }
136 // ^^^^ adjustments: Deref(None), Borrow(Ref(Not)), Pointer(Unsize)
146 fn match_second_coerce() {
149 //- minicore: coerce_unsized
150 fn foo<T>(x: &[T]) -> &[T] { loop {} }
151 // ^^^^^^^ adjustments: NeverToAny
164 fn coerce_merge_one_by_one1() {
165 cov_mark::check!(coerce_merge_fail_fallback);
174 //^^^^^^^^^ expected *mut i32, got &i32
175 _ => t as *const i32,
176 // ^^^^^^^^^^^^^^^ adjustments: Pointer(MutToConstPointer)
188 fn return_coerce_unknown() {
200 fn coerce_autoderef() {
204 fn takes_ref_foo(x: &Foo) {}
207 takes_ref_foo(&&Foo);
208 takes_ref_foo(&&&Foo);
214 fn coerce_autoderef_generic() {
218 fn takes_ref<T>(x: &T) -> T { *x }
229 fn coerce_autoderef_block() {
234 impl core::ops::Deref for String { type Target = str; }
235 fn takes_ref_str(x: &str) {}
236 fn returns_string() -> String { loop {} }
238 takes_ref_str(&{ returns_string() });
245 fn closure_return_coerce() {
260 fn coerce_fn_item_to_fn_ptr() {
263 fn foo(x: u32) -> isize { 1 }
265 let f: fn(u32) -> isize = foo;
266 // ^^^ adjustments: Pointer(ReifyFnPointer)
267 let f: unsafe fn(u32) -> isize = foo;
268 // ^^^ adjustments: Pointer(ReifyFnPointer)
274 fn coerce_fn_items_in_match_arms() {
275 cov_mark::check!(coerce_fn_reification);
279 fn foo1(x: u32) -> isize { 1 }
280 fn foo2(x: u32) -> isize { 2 }
281 fn foo3(x: u32) -> isize { 3 }
295 fn coerce_closure_to_fn_ptr() {
299 let f: fn(u32) -> isize = |x| { 1 };
305 fn coerce_placeholder_ref() {
306 // placeholders should unify, even behind references
311 fn get(&self) -> &TT {
319 fn coerce_unsize_array() {
322 //- minicore: coerce_unsized
324 let f: &[usize] = &[1, 2, 3];
331 fn coerce_unsize_trait_object_simple() {
334 //- minicore: coerce_unsized
336 trait Bar<U, T, X>: Foo<T, U> {}
337 trait Baz<T, X>: Bar<usize, T, X> {}
340 impl<T, X> Foo<T, usize> for S<T, X> {}
341 impl<T, X> Bar<usize, T, X> for S<T, X> {}
342 impl<T, X> Baz<T, X> for S<T, X> {}
345 let obj: &dyn Baz<i8, i16> = &S;
347 let obj: &dyn Bar<_, i8, i16> = &S;
349 let obj: &dyn Foo<i8, _> = &S;
356 fn coerce_unsize_super_trait_cycle() {
359 //- minicore: coerce_unsized
372 let obj: &dyn D = &S;
373 let obj: &dyn A = &S;
380 fn coerce_unsize_generic() {
381 // FIXME: fix the type mismatches here
384 //- minicore: coerce_unsized
385 struct Foo<T> { t: T };
386 struct Bar<T>(Foo<T>);
389 let _: &Foo<[usize]> = &Foo { t: [1, 2, 3] };
390 //^^^^^^^^^ expected [usize], got [usize; 3]
391 let _: &Bar<[usize]> = &Bar(Foo { t: [1, 2, 3] });
392 //^^^^^^^^^^^^^^^^^^^^^^^^^^ expected &Bar<[usize]>, got &Bar<[i32; 3]>
399 fn coerce_unsize_apit() {
403 //- minicore: coerce_unsized
406 fn test(f: impl Foo) {
407 let _: &dyn Foo = &f;
408 //^^ expected &dyn Foo, got &impl Foo
415 fn two_closures_lub() {
419 let add = |a: i32, b: i32| a + b;
420 let sub = |a, b| a - b;
421 //^^^^^^^^^^^^ |i32, i32| -> i32
422 if c > 42 { add } else { sub };
423 //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ fn(i32, i32) -> i32
430 fn match_diverging_branch_1() {
433 enum Result<T> { Ok(T), Err }
434 fn parse<T>() -> T { loop {} }
437 let a = match parse() {
449 fn match_diverging_branch_2() {
450 // same as 1 except for order of branches
453 enum Result<T> { Ok(T), Err }
454 fn parse<T>() -> T { loop {} }
457 let a = match parse() {
474 pub macro panic_2015 {
476 $crate::panicking::panic()
482 pub fn panic() -> ! { loop {} }
485 #[rustc_builtin_macro = "core_panic"]
487 // Expands to either `$crate::panic::panic_2015` or `$crate::panic::panic_2021`
488 // depending on the edition of the caller.
490 /* compiler built-in */
502 fn coerce_unsize_expected_type() {
505 //- minicore: coerce_unsized
507 let foo: &[u32] = &[1, 2];
508 let foo: &[u32] = match true {
512 let foo: &[u32] = if true {
523 fn coerce_array_elems_lub() {