Skip to content

Commit c3778fa

Browse files
author
Jorge Aparicio
committed
libstd: add a dummy field to OsRng to avoid out of module construction
1 parent 556d971 commit c3778fa

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/libstd/rand/os.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,10 @@ mod imp {
187187
/// - iOS: calls SecRandomCopyBytes as /dev/(u)random is sandboxed
188188
/// This does not block.
189189
#[allow(missing_copy_implementations)]
190-
pub struct OsRng;
190+
pub struct OsRng {
191+
// dummy field to ensure that this struct cannot be constructed outside of this module
192+
_dummy: (),
193+
}
191194

192195
#[repr(C)]
193196
struct SecRandom;
@@ -204,7 +207,7 @@ mod imp {
204207
impl OsRng {
205208
/// Create a new `OsRng`.
206209
pub fn new() -> IoResult<OsRng> {
207-
Ok(OsRng)
210+
Ok(OsRng { _dummy: () })
208211
}
209212
}
210213

0 commit comments

Comments
 (0)