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 let x: *const [isize] = &[1];
61 fn custom_coerce_unsized() {
64 //- minicore: coerce_unsized
65 use core::{marker::Unsize, ops::CoerceUnsized};
67 struct A<T: ?Sized>(*const T);
68 struct B<T: ?Sized>(*const T);
69 struct C<T: ?Sized> { inner: *const T }
71 impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<B<U>> for B<T> {}
72 impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<C<U>> for C<T> {}
74 fn foo1<T>(x: A<[T]>) -> A<[T]> { x }
75 fn foo2<T>(x: B<[T]>) -> B<[T]> { x }
76 fn foo3<T>(x: C<[T]>) -> C<[T]> { x }
78 fn test(a: A<[u8; 2]>, b: B<[u8; 2]>, c: C<[u8; 2]>) {
80 // ^ expected A<[{unknown}]>, got A<[u8; 2]>
94 //- minicore: coerce_unsized
95 fn foo<T>(x: &[T]) -> &[T] { x }
108 fn if_else_coerce() {
111 //- minicore: coerce_unsized
112 fn foo<T>(x: &[T]) -> &[T] { x }
125 fn match_first_coerce() {
128 //- minicore: coerce_unsized
129 fn foo<T>(x: &[T]) -> &[T] { x }
142 fn match_second_coerce() {
145 //- minicore: coerce_unsized
146 fn foo<T>(x: &[T]) -> &[T] { loop {} }
159 fn coerce_merge_one_by_one1() {
160 cov_mark::check!(coerce_merge_fail_fallback);
169 //^^^^^^^^^ expected *mut i32, got &i32
170 _ => t as *const i32,
180 fn return_coerce_unknown() {
192 fn coerce_autoderef() {
196 fn takes_ref_foo(x: &Foo) {}
199 takes_ref_foo(&&Foo);
200 takes_ref_foo(&&&Foo);
206 fn coerce_autoderef_generic() {
210 fn takes_ref<T>(x: &T) -> T { *x }
221 fn coerce_autoderef_block() {
226 impl core::ops::Deref for String { type Target = str; }
227 fn takes_ref_str(x: &str) {}
228 fn returns_string() -> String { loop {} }
230 takes_ref_str(&{ returns_string() });
237 fn closure_return_coerce() {
252 fn coerce_fn_item_to_fn_ptr() {
255 fn foo(x: u32) -> isize { 1 }
257 let f: fn(u32) -> isize = foo;
263 fn coerce_fn_items_in_match_arms() {
264 cov_mark::check!(coerce_fn_reification);
268 fn foo1(x: u32) -> isize { 1 }
269 fn foo2(x: u32) -> isize { 2 }
270 fn foo3(x: u32) -> isize { 3 }
284 fn coerce_closure_to_fn_ptr() {
288 let f: fn(u32) -> isize = |x| { 1 };
294 fn coerce_placeholder_ref() {
295 // placeholders should unify, even behind references
300 fn get(&self) -> &TT {
308 fn coerce_unsize_array() {
311 //- minicore: coerce_unsized
313 let f: &[usize] = &[1, 2, 3];
320 fn coerce_unsize_trait_object_simple() {
323 //- minicore: coerce_unsized
325 trait Bar<U, T, X>: Foo<T, U> {}
326 trait Baz<T, X>: Bar<usize, T, X> {}
329 impl<T, X> Foo<T, usize> for S<T, X> {}
330 impl<T, X> Bar<usize, T, X> for S<T, X> {}
331 impl<T, X> Baz<T, X> for S<T, X> {}
334 let obj: &dyn Baz<i8, i16> = &S;
336 let obj: &dyn Bar<_, i8, i16> = &S;
338 let obj: &dyn Foo<i8, _> = &S;
345 fn coerce_unsize_super_trait_cycle() {
348 //- minicore: coerce_unsized
361 let obj: &dyn D = &S;
362 let obj: &dyn A = &S;
369 fn coerce_unsize_generic() {
370 // FIXME: fix the type mismatches here
373 //- minicore: coerce_unsized
374 struct Foo<T> { t: T };
375 struct Bar<T>(Foo<T>);
378 let _: &Foo<[usize]> = &Foo { t: [1, 2, 3] };
379 //^^^^^^^^^ expected [usize], got [usize; 3]
380 let _: &Bar<[usize]> = &Bar(Foo { t: [1, 2, 3] });
381 //^^^^^^^^^^^^^^^^^^^^^^^^^^ expected &Bar<[usize]>, got &Bar<[i32; 3]>
388 fn coerce_unsize_apit() {
392 //- minicore: coerce_unsized
395 fn test(f: impl Foo) {
396 let _: &dyn Foo = &f;
397 //^^ expected &dyn Foo, got &impl Foo
404 fn two_closures_lub() {
408 let add = |a: i32, b: i32| a + b;
409 let sub = |a, b| a - b;
410 //^^^^^^^^^^^^ |i32, i32| -> i32
411 if c > 42 { add } else { sub };
412 //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ fn(i32, i32) -> i32
419 fn match_diverging_branch_1() {
422 enum Result<T> { Ok(T), Err }
423 fn parse<T>() -> T { loop {} }
426 let a = match parse() {
438 fn match_diverging_branch_2() {
439 // same as 1 except for order of branches
442 enum Result<T> { Ok(T), Err }
443 fn parse<T>() -> T { loop {} }
446 let a = match parse() {
463 pub macro panic_2015 {
465 $crate::panicking::panic()
471 pub fn panic() -> ! { loop {} }
474 #[rustc_builtin_macro = "core_panic"]
476 // Expands to either `$crate::panic::panic_2015` or `$crate::panic::panic_2021`
477 // depending on the edition of the caller.
479 /* compiler built-in */
491 fn coerce_unsize_expected_type() {
494 //- minicore: coerce_unsized
496 let foo: &[u32] = &[1, 2];
497 let foo: &[u32] = match true {
501 let foo: &[u32] = if true {