fork/rust

git clone https://git.julia.blue/fork/rust

borsAuto merge of #103046 - JanBeh:PR_clarify_cmp_terminology, r=workingjubilee3bcad65fbf6

master
3.2 KiB159 linesraw
1// run-rustfix
2
3#![deny(no_mangle_generic_items)]
4
5
6pub fn foo<T>() {} //~ ERROR functions generic over types or consts must be mangled
7
8
9pub extern "C" fn bar<T>() {} //~ ERROR functions generic over types or consts must be mangled
10
11#[no_mangle]
12pub fn baz(x: &i32) -> &i32 { x }
13
14#[no_mangle]
15pub fn qux<'a>(x: &'a i32) -> &i32 { x }
16
17pub struct Foo;
18
19impl 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
33trait 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
40impl 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
54trait 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
62impl<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
79pub struct Bar<T>(#[allow(unused_tuple_struct_fields)] T);
80
81impl<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
92impl Bar<i32> {
93    #[no_mangle]
94    pub fn qux() {}
95}
96
97trait Trait3 {
98    fn foo();
99    extern "C" fn bar();
100    fn baz<U>();
101}
102
103impl<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
114pub struct Baz<'a>(#[allow(unused_tuple_struct_fields)] &'a i32);
115
116impl<'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
124trait Trait4 {
125    fn foo();
126    fn bar<'a>(x: &'a i32) -> &i32;
127}
128
129impl 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
137impl<'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
145trait Trait5<T> {
146    fn foo();
147}
148
149impl Trait5<i32> for Foo {
150    #[no_mangle]
151    fn foo() {}
152}
153
154impl Trait5<i32> for Bar<i32> {
155    #[no_mangle]
156    fn foo() {}
157}
158
159fn main() {}