1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//! Compile-proven borrow-guard constraint.
//!
//! The Hopper Safety Audit's Finding 2 asks for *compile-time* proof
//! that no raw `&T` / `&mut T` can escape an account access path.
//! Every runtime surface already returns a [`Ref`], [`RefMut`],
//! [`SegRef`], or [`SegRefMut`], but that guarantee is embedded in the
//! function return types alone. [`HopperRefOnly`] is the nominal
//! version of that promise: a sealed marker trait implemented only by
//! Hopper's four borrow guards.
//!
//! API authors can now write `fn f<G: HopperRefOnly>(g: G)` and rely
//! on the compiler to reject a naked `&mut U` at the call site. The
//! sealed trait pattern means no downstream crate can stamp the marker
//! onto arbitrary types, which closes the audit's "prove no raw refs"
//! gate at compile time instead of by convention.
//!
//! # Grep receipt
//!
//! An auditor running `grep -r "HopperRefOnly"` sees exactly five
//! lines: the trait declaration plus the four guard impls. There is
//! no macro-generated expansion, no procedural indirection. Every
//! impl is visible at the byte level.
//!
//! [`Ref`]: crate::borrow::Ref
//! [`RefMut`]: crate::borrow::RefMut
//! [`SegRef`]: crate::segment_lease::SegRef
//! [`SegRefMut`]: crate::segment_lease::SegRefMut
use crate;
use crate;
/// Marker trait implemented exclusively by Hopper's four account-data
/// borrow guards: [`Ref`], [`RefMut`], [`SegRef`], [`SegRefMut`].
///
/// Use this as a bound on APIs that must accept only drop-guarded
/// borrows. A naked `&T` or `&mut T` will fail the bound at compile
/// time, which is the closure proof for Finding 2 of the audit
/// ("borrow safety compile-proven, not just runtime-enforced").
///
/// [`Ref`]: crate::borrow::Ref
/// [`RefMut`]: crate::borrow::RefMut
/// [`SegRef`]: crate::segment_lease::SegRef
/// [`SegRefMut`]: crate::segment_lease::SegRefMut