File tree 2 files changed +26
-12
lines changed
compiler/rustc_error_codes/src/error_codes
2 files changed +26
-12
lines changed Original file line number Diff line number Diff line change 1
1
Per [ RFC 401] [ rfc401 ] , if you have a function declaration ` foo ` :
2
2
3
3
```
4
+ struct S;
5
+
4
6
// For the purposes of this explanation, all of these
5
7
// different kinds of `fn` declarations are equivalent:
6
- struct S;
8
+
7
9
fn foo(x: S) { /* ... */ }
8
10
# #[cfg(for_demonstration_only)]
9
- extern "C" { fn foo(x: S); }
11
+ extern "C" {
12
+ fn foo(x: S);
13
+ }
10
14
# #[cfg(for_demonstration_only)]
11
- impl S { fn foo(self) { /* ... */ } }
15
+ impl S {
16
+ fn foo(self) { /* ... */ }
17
+ }
12
18
```
13
19
14
20
the type of ` foo ` is ** not** ` fn(S) ` , as one might expect.
@@ -40,10 +46,10 @@ extern "C" fn foo(userdata: Box<i32>) {
40
46
41
47
# fn callback(_: extern "C" fn(*mut i32)) {}
42
48
# use std::mem::transmute;
43
- # unsafe {
44
- let f: extern "C" fn(*mut i32) = transmute(foo);
45
- callback(f);
46
- # }
49
+ unsafe {
50
+ let f: extern "C" fn(*mut i32) = transmute(foo);
51
+ callback(f);
52
+ }
47
53
```
48
54
49
55
Here, transmute is being used to convert the types of the fn arguments.
Original file line number Diff line number Diff line change 1
1
Per [RFC 401][rfc401], if you have a function declaration `foo`:
2
2
3
3
```
4
+ struct S;
5
+
4
6
// For the purposes of this explanation, all of these
5
7
// different kinds of `fn` declarations are equivalent:
6
- struct S;
8
+
7
9
fn foo(x: S) { /* ... */ }
8
- extern "C" { fn foo(x: S); }
9
- impl S { fn foo(self) { /* ... */ } }
10
+ extern "C" {
11
+ fn foo(x: S);
12
+ }
13
+ impl S {
14
+ fn foo(self) { /* ... */ }
15
+ }
10
16
```
11
17
12
18
the type of `foo` is **not** `fn(S)`, as one might expect.
@@ -34,8 +40,10 @@ extern "C" fn foo(userdata: Box<i32>) {
34
40
/* ... */
35
41
}
36
42
37
- let f: extern "C" fn(*mut i32) = transmute(foo);
38
- callback(f);
43
+ unsafe {
44
+ let f: extern "C" fn(*mut i32) = transmute(foo);
45
+ callback(f);
46
+ }
39
47
```
40
48
41
49
Here, transmute is being used to convert the types of the fn arguments.
You can’t perform that action at this time.
0 commit comments