]> git.lizzy.rs Git - rust.git/blob - tests/ui/generics/generic-no-mangle.fixed
Rollup merge of #107598 - chenyukang:yukang/fix-core-bench, r=thomcc
[rust.git] / tests / ui / generics / generic-no-mangle.fixed
1 // run-rustfix
2
3 #![deny(no_mangle_generic_items)]
4
5
6 pub fn foo<T>() {} //~ ERROR functions generic over types or consts must be mangled
7
8
9 pub extern "C" fn bar<T>() {} //~ ERROR functions generic over types or consts must be mangled
10
11 #[no_mangle]
12 pub fn baz(x: &i32) -> &i32 { x }
13
14 #[no_mangle]
15 pub fn qux<'a>(x: &'a i32) -> &i32 { x }
16
17 pub struct Foo;
18
19 impl Foo {
20     
21     pub fn foo<T>() {} //~ ERROR functions generic over types or consts must be mangled
22
23     
24     pub extern "C" fn bar<T>() {} //~ ERROR functions generic over types or consts must be mangled
25
26     #[no_mangle]
27     pub fn baz(x: &i32) -> &i32 { x }
28
29     #[no_mangle]
30     pub fn qux<'a>(x: &'a i32) -> &i32 { x }
31 }
32
33 trait Trait1 {
34     fn foo<T>();
35     extern "C" fn bar<T>();
36     fn baz(x: &i32) -> &i32;
37     fn qux<'a>(x: &'a i32) -> &i32;
38 }
39
40 impl Trait1 for Foo {
41     
42     fn foo<T>() {} //~ ERROR functions generic over types or consts must be mangled
43
44     
45     extern "C" fn bar<T>() {} //~ ERROR functions generic over types or consts must be mangled
46
47     #[no_mangle]
48     fn baz(x: &i32) -> &i32 { x }
49
50     #[no_mangle]
51     fn qux<'a>(x: &'a i32) -> &i32 { x }
52 }
53
54 trait Trait2<T> {
55     fn foo();
56     fn foo2<U>();
57     extern "C" fn bar();
58     fn baz(x: &i32) -> &i32;
59     fn qux<'a>(x: &'a i32) -> &i32;
60 }
61
62 impl<T> Trait2<T> for Foo {
63     
64     fn foo() {} //~ ERROR functions generic over types or consts must be mangled
65
66     
67     fn foo2<U>() {} //~ ERROR functions generic over types or consts must be mangled
68
69     
70     extern "C" fn bar() {} //~ ERROR functions generic over types or consts must be mangled
71
72     
73     fn baz(x: &i32) -> &i32 { x } //~ ERROR functions generic over types or consts must be mangled
74
75     
76     fn qux<'a>(x: &'a i32) -> &i32 { x } //~ ERROR functions generic over types or consts must be mangled
77 }
78
79 pub struct Bar<T>(#[allow(unused_tuple_struct_fields)] T);
80
81 impl<T> Bar<T> {
82     
83     pub fn foo() {} //~ ERROR functions generic over types or consts must be mangled
84
85     
86     pub extern "C" fn bar() {} //~ ERROR functions generic over types or consts must be mangled
87
88     
89     pub fn baz<U>() {} //~ ERROR functions generic over types or consts must be mangled
90 }
91
92 impl Bar<i32> {
93     #[no_mangle]
94     pub fn qux() {}
95 }
96
97 trait Trait3 {
98     fn foo();
99     extern "C" fn bar();
100     fn baz<U>();
101 }
102
103 impl<T> Trait3 for Bar<T> {
104     
105     fn foo() {} //~ ERROR functions generic over types or consts must be mangled
106
107     
108     extern "C" fn bar() {} //~ ERROR functions generic over types or consts must be mangled
109
110     
111     fn baz<U>() {} //~ ERROR functions generic over types or consts must be mangled
112 }
113
114 pub struct Baz<'a>(#[allow(unused_tuple_struct_fields)] &'a i32);
115
116 impl<'a> Baz<'a> {
117     #[no_mangle]
118     pub fn foo() {}
119
120     #[no_mangle]
121     pub fn bar<'b>(x: &'b i32) -> &i32 { x }
122 }
123
124 trait Trait4 {
125     fn foo();
126     fn bar<'a>(x: &'a i32) -> &i32;
127 }
128
129 impl Trait4 for Bar<i32> {
130     #[no_mangle]
131     fn foo() {}
132
133     #[no_mangle]
134     fn bar<'b>(x: &'b i32) -> &i32 { x }
135 }
136
137 impl<'a> Trait4 for Baz<'a> {
138     #[no_mangle]
139     fn foo() {}
140
141     #[no_mangle]
142     fn bar<'b>(x: &'b i32) -> &i32 { x }
143 }
144
145 trait Trait5<T> {
146     fn foo();
147 }
148
149 impl Trait5<i32> for Foo {
150     #[no_mangle]
151     fn foo() {}
152 }
153
154 impl Trait5<i32> for Bar<i32> {
155     #[no_mangle]
156     fn foo() {}
157 }
158
159 fn main() {}