Skip to content

Commit 1069a68

Browse files
core: VaArgSafe is an unsafe trait
`T: VaArgSafe` is relied on for soundness. Safe impls promise nothing. Therefore this must be an unsafe trait. Slightly pedantic, as only core can impl this, but we could choose to unseal the trait. That would allow soundly (but unsafely) implementing this for e.g. a `#[repr(C)] struct` that should be passable by varargs.
1 parent e51d8a2 commit 1069a68

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

core/src/ffi/mod.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ mod sealed_trait {
484484
all supported platforms",
485485
issue = "44930"
486486
)]
487-
pub trait VaArgSafe {}
487+
pub unsafe trait VaArgSafe {}
488488
}
489489

490490
macro_rules! impl_va_arg_safe {
@@ -494,7 +494,7 @@ macro_rules! impl_va_arg_safe {
494494
reason = "the `c_variadic` feature has not been properly tested on \
495495
all supported platforms",
496496
issue = "44930")]
497-
impl sealed_trait::VaArgSafe for $t {}
497+
unsafe impl sealed_trait::VaArgSafe for $t {}
498498
)+
499499
}
500500
}
@@ -509,14 +509,15 @@ impl_va_arg_safe! {f64}
509509
all supported platforms",
510510
issue = "44930"
511511
)]
512-
impl<T> sealed_trait::VaArgSafe for *mut T {}
512+
unsafe impl<T> sealed_trait::VaArgSafe for *mut T {}
513+
513514
#[unstable(
514515
feature = "c_variadic",
515516
reason = "the `c_variadic` feature has not been properly tested on \
516517
all supported platforms",
517518
issue = "44930"
518519
)]
519-
impl<T> sealed_trait::VaArgSafe for *const T {}
520+
unsafe impl<T> sealed_trait::VaArgSafe for *const T {}
520521

521522
#[unstable(
522523
feature = "c_variadic",

0 commit comments

Comments
 (0)