]> git.lizzy.rs Git - rust.git/blob - tests/codegen/deduced-param-attrs.rs
Rollup merge of #106715 - BoxyUwU:new_solver_triagebot, r=lcnr
[rust.git] / tests / codegen / deduced-param-attrs.rs
1 // compile-flags: -O
2
3 #![crate_type = "lib"]
4 #![allow(incomplete_features)]
5 #![feature(unsized_locals, unsized_fn_params)]
6
7 use std::cell::Cell;
8 use std::hint;
9
10 // Check to make sure that we can deduce the `readonly` attribute from function bodies for
11 // parameters passed indirectly.
12
13 pub struct BigStruct {
14     blah: [i32; 1024],
15 }
16
17 pub struct BigCellContainer {
18     blah: [Cell<i32>; 1024],
19 }
20
21 // The by-value parameter for this big struct can be marked readonly.
22 //
23 // CHECK: @use_big_struct_immutably({{.*}} readonly {{.*}} %big_struct)
24 #[no_mangle]
25 pub fn use_big_struct_immutably(big_struct: BigStruct) {
26     hint::black_box(&big_struct);
27 }
28
29 // The by-value parameter for this big struct can't be marked readonly, because we mutate it.
30 //
31 // CHECK-NOT: @use_big_struct_mutably({{.*}} readonly {{.*}} %big_struct)
32 #[no_mangle]
33 pub fn use_big_struct_mutably(mut big_struct: BigStruct) {
34     big_struct.blah[987] = 654;
35     hint::black_box(&big_struct);
36 }
37
38 // The by-value parameter for this big struct can't be marked readonly, because it contains
39 // UnsafeCell.
40 //
41 // CHECK-NOT: @use_big_cell_container({{.*}} readonly {{.*}} %big_cell_container)
42 #[no_mangle]
43 pub fn use_big_cell_container(big_cell_container: BigCellContainer) {
44     hint::black_box(&big_cell_container);
45 }
46
47 // Make sure that we don't mistakenly mark a big struct as `readonly` when passed through a generic
48 // type parameter if it contains UnsafeCell.
49 //
50 // CHECK-NOT: @use_something({{.*}} readonly {{.*}} %something)
51 #[no_mangle]
52 #[inline(never)]
53 pub fn use_something<T>(something: T) {
54     hint::black_box(&something);
55 }
56
57 #[no_mangle]
58 pub fn forward_big_cell_container(big_cell_container: BigCellContainer) {
59     use_something(big_cell_container)
60 }