Skip to content

Commit 905039a

Browse files
committed
Make version field in context structs unsafe
Changing the version field changes the semantics of the structure.
1 parent 68d308f commit 905039a

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

crates/header-translator/src/rust_type.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2668,11 +2668,14 @@ impl Ty {
26682668
fields
26692669
.iter()
26702670
.fold(TypeSafety::SAFE, |safety, (field_name, field)| {
2671-
safety.merge(
2672-
field
2673-
.safety()
2674-
.context(format!("struct field `{field_name}`")),
2675-
)
2671+
let mut field_safety = field.safety();
2672+
if field_name == "version" {
2673+
// Setting the right version in e.g.
2674+
// `CFRunLoopObserverContext` is important.
2675+
field_safety = field_safety
2676+
.merge(TypeSafety::unsafe_in_argument("must be set correctly"));
2677+
}
2678+
safety.merge(field_safety.context(format!("struct field `{field_name}`")))
26762679
})
26772680
}
26782681
// Conservative.

0 commit comments

Comments
 (0)