File tree Expand file tree Collapse file tree 2 files changed +26
-12
lines changed
compiler/rustc_error_codes/src/error_codes Expand file tree Collapse file tree 2 files changed +26
-12
lines changed Original file line number Diff line number Diff line change 11Per [ RFC 401] [ rfc401 ] , if you have a function declaration ` foo ` :
22
33```
4+ struct S;
5+
46// For the purposes of this explanation, all of these
57// different kinds of `fn` declarations are equivalent:
6- struct S;
8+
79fn foo(x: S) { /* ... */ }
810# #[cfg(for_demonstration_only)]
9- extern "C" { fn foo(x: S); }
11+ extern "C" {
12+ fn foo(x: S);
13+ }
1014# #[cfg(for_demonstration_only)]
11- impl S { fn foo(self) { /* ... */ } }
15+ impl S {
16+ fn foo(self) { /* ... */ }
17+ }
1218```
1319
1420the type of ` foo ` is ** not** ` fn(S) ` , as one might expect.
@@ -40,10 +46,10 @@ extern "C" fn foo(userdata: Box<i32>) {
4046
4147# fn callback(_: extern "C" fn(*mut i32)) {}
4248# 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+ }
4753```
4854
4955Here, transmute is being used to convert the types of the fn arguments.
Original file line number Diff line number Diff line change 11Per [RFC 401][rfc401], if you have a function declaration `foo`:
22
33```
4+ struct S;
5+
46// For the purposes of this explanation, all of these
57// different kinds of `fn` declarations are equivalent:
6- struct S;
8+
79fn 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+ }
1016```
1117
1218the type of `foo` is **not** `fn(S)`, as one might expect.
@@ -34,8 +40,10 @@ extern "C" fn foo(userdata: Box<i32>) {
3440 /* ... */
3541}
3642
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+ }
3947```
4048
4149Here, transmute is being used to convert the types of the fn arguments.
You can’t perform that action at this time.
0 commit comments