]> git.proxmox.com Git - rustc.git/blob - src/test/ui-fulldeps/internal-lints/rustc_pass_by_value.rs
New upstream version 1.67.1+dfsg1
[rustc.git] / src / test / ui-fulldeps / internal-lints / rustc_pass_by_value.rs
1 // compile-flags: -Z unstable-options
2
3 #![feature(rustc_attrs)]
4 #![feature(rustc_private)]
5 #![deny(rustc::pass_by_value)]
6 #![allow(unused)]
7
8 extern crate rustc_middle;
9
10 use rustc_middle::ty::{Ty, TyCtxt};
11
12 fn ty_by_ref(
13 ty_val: Ty<'_>,
14 ty_ref: &Ty<'_>, //~ ERROR passing `Ty<'_>` by reference
15 ty_ctxt_val: TyCtxt<'_>,
16 ty_ctxt_ref: &TyCtxt<'_>, //~ ERROR passing `TyCtxt<'_>` by reference
17 ) {
18 }
19
20 fn ty_multi_ref(ty_multi: &&Ty<'_>, ty_ctxt_multi: &&&&TyCtxt<'_>) {}
21 //~^ ERROR passing `Ty<'_>` by reference
22 //~^^ ERROR passing `TyCtxt<'_>` by reference
23
24 trait T {
25 fn ty_by_ref_in_trait(
26 ty_val: Ty<'_>,
27 ty_ref: &Ty<'_>, //~ ERROR passing `Ty<'_>` by reference
28 ty_ctxt_val: TyCtxt<'_>,
29 ty_ctxt_ref: &TyCtxt<'_>, //~ ERROR passing `TyCtxt<'_>` by reference
30 );
31
32 fn ty_multi_ref_in_trait(ty_multi: &&Ty<'_>, ty_ctxt_multi: &&&&TyCtxt<'_>);
33 //~^ ERROR passing `Ty<'_>` by reference
34 //~^^ ERROR passing `TyCtxt<'_>` by reference
35 }
36
37 struct Foo;
38
39 impl T for Foo {
40 fn ty_by_ref_in_trait(
41 ty_val: Ty<'_>,
42 ty_ref: &Ty<'_>,
43 ty_ctxt_val: TyCtxt<'_>,
44 ty_ctxt_ref: &TyCtxt<'_>,
45 ) {
46 }
47
48 fn ty_multi_ref_in_trait(ty_multi: &&Ty<'_>, ty_ctxt_multi: &&&&TyCtxt<'_>) {}
49 }
50
51 impl Foo {
52 fn ty_by_ref_assoc(
53 ty_val: Ty<'_>,
54 ty_ref: &Ty<'_>, //~ ERROR passing `Ty<'_>` by reference
55 ty_ctxt_val: TyCtxt<'_>,
56 ty_ctxt_ref: &TyCtxt<'_>, //~ ERROR passing `TyCtxt<'_>` by reference
57 ) {
58 }
59
60 fn ty_multi_ref_assoc(ty_multi: &&Ty<'_>, ty_ctxt_multi: &&&&TyCtxt<'_>) {}
61 //~^ ERROR passing `Ty<'_>` by reference
62 //~^^ ERROR passing `TyCtxt<'_>` by reference
63 }
64
65 #[rustc_pass_by_value]
66 enum CustomEnum {
67 A,
68 B,
69 }
70
71 impl CustomEnum {
72 fn test(
73 value: CustomEnum,
74 reference: &CustomEnum, //~ ERROR passing `CustomEnum` by reference
75 ) {
76 }
77 }
78
79 #[rustc_pass_by_value]
80 struct CustomStruct {
81 s: u8,
82 }
83
84 #[rustc_pass_by_value]
85 type CustomAlias<'a> = &'a CustomStruct; //~ ERROR passing `CustomStruct` by reference
86
87 impl CustomStruct {
88 fn test(
89 value: CustomStruct,
90 reference: &CustomStruct, //~ ERROR passing `CustomStruct` by reference
91 ) {
92 }
93
94 fn test_alias(
95 value: CustomAlias,
96 reference: &CustomAlias, //~ ERROR passing `CustomAlias<'_>` by reference
97 ) {
98 }
99 }
100
101 #[rustc_pass_by_value]
102 struct WithParameters<T, const N: usize, M = u32> {
103 slice: [T; N],
104 m: M,
105 }
106
107 impl<T> WithParameters<T, 1> {
108 fn test<'a>(
109 value: WithParameters<T, 1>,
110 reference: &'a WithParameters<T, 1>, //~ ERROR passing `WithParameters<T, 1>` by reference
111 reference_with_m: &WithParameters<T, 1, u32>, //~ ERROR passing `WithParameters<T, 1, u32>` by reference
112 ) -> &'a WithParameters<T, 1> {
113 //~^ ERROR passing `WithParameters<T, 1>` by reference
114 reference as &WithParameters<_, 1> //~ ERROR passing `WithParameters<_, 1>` by reference
115 }
116 }
117
118 fn main() {}