Skip to content

Commit 9fbb882

Browse files
committed
Document why we map type_ to type
1 parent 774aa70 commit 9fbb882

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

libc-test/build.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,14 +1022,9 @@ fn test_dragonflybsd(target: &str) {
10221022
s.replace("e_nsec", ".tv_nsec")
10231023
}
10241024
"u64" if struct_ == "epoll_event" => "data.u64".to_string(),
1025-
"type_"
1026-
if struct_ == "input_event"
1027-
|| struct_ == "input_mask"
1028-
|| struct_ == "ff_effect"
1029-
|| struct_ == "rtprio" =>
1030-
{
1031-
"type".to_string()
1032-
}
1025+
// Field is named `type` in C but that is a Rust keyword,
1026+
// so these fields are translated to `type_` in the bindings.
1027+
"type_" if struct_ == "rtprio" => "type".to_string(),
10331028
s => s.to_string(),
10341029
}
10351030
});
@@ -1555,7 +1550,10 @@ fn test_freebsd(target: &str) {
15551550
s if s.ends_with("_nsec") && struct_.starts_with("stat") => {
15561551
s.replace("e_nsec", ".tv_nsec")
15571552
}
1558-
s => s.to_string(),
1553+
// Field is named `type` in C but that is a Rust keyword,
1554+
// so these fields are translated to `type_` in the bindings.
1555+
"type_" if struct_ == "rtprio" => "type".to_string(),
1556+
s => s.to_string(),
15591557
}
15601558
});
15611559

@@ -2313,12 +2311,13 @@ fn test_linux(target: &str) {
23132311
}
23142312
// FIXME: is this necessary?
23152313
"u64" if struct_ == "epoll_event" => "data.u64".to_string(),
2316-
// FIXME: is this necessary?
2314+
// The following structs have a field called `type` in C,
2315+
// but `type` is a Rust keyword, so these fields are translated
2316+
// to `type_` in Rust.
23172317
"type_"
23182318
if struct_ == "input_event"
23192319
|| struct_ == "input_mask"
2320-
|| struct_ == "ff_effect"
2321-
|| struct_ == "rtprio" =>
2320+
|| struct_ == "ff_effect" =>
23222321
{
23232322
"type".to_string()
23242323
}

0 commit comments

Comments
 (0)