Skip to content

Commit

Permalink
Give ambient authority arguments names. (#298)
Browse files Browse the repository at this point in the history
Use `let _ = ambient_authority;` to suppress unused argument warnings
rather than naming arguments `_`, because argument names show up in the
documentation, and the fact that these arguments are unused is not part
of the public interface.
  • Loading branch information
sunfishcode committed Mar 15, 2023
1 parent daa7bcb commit 58dd07c
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 11 deletions.
3 changes: 2 additions & 1 deletion cap-directories/src/project_dirs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ impl ProjectDirs {
qualifier: &str,
organization: &str,
application: &str,
_: AmbientAuthority,
ambient_authority: AmbientAuthority,
) -> Option<Self> {
let _ = ambient_authority;
let inner = directories_next::ProjectDirs::from(qualifier, organization, application)?;
Some(Self { inner })
}
Expand Down
17 changes: 15 additions & 2 deletions cap-primitives/src/net/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,14 @@ impl Pool {
/// # Ambient Authority
///
/// This function allows ambient access to any IP address.
pub fn insert_ip_net(&mut self, ip_net: ipnet::IpNet, port: u16, _: AmbientAuthority) {
pub fn insert_ip_net(
&mut self,
ip_net: ipnet::IpNet,
port: u16,
ambient_authority: AmbientAuthority,
) {
let _ = ambient_authority;

self.grants.push(IpGrant {
set: AddrSet::Net(ip_net),
port,
Expand All @@ -63,7 +70,13 @@ impl Pool {
/// # Ambient Authority
///
/// This function allows ambient access to any IP address.
pub fn insert_socket_addr(&mut self, addr: net::SocketAddr, _: AmbientAuthority) {
pub fn insert_socket_addr(
&mut self,
addr: net::SocketAddr,
ambient_authority: AmbientAuthority,
) {
let _ = ambient_authority;

self.grants.push(IpGrant {
set: AddrSet::Net(addr.ip().into()),
port: addr.port(),
Expand Down
7 changes: 6 additions & 1 deletion cap-primitives/src/rustix/fs/dir_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,12 @@ pub(crate) fn canonicalize_options() -> OpenOptions {
///
/// This function is not sandboxed and may trivially access any path that the
/// host process has access to.
pub(crate) fn open_ambient_dir_impl(path: &Path, _: AmbientAuthority) -> io::Result<fs::File> {
pub(crate) fn open_ambient_dir_impl(
path: &Path,
ambient_authority: AmbientAuthority,
) -> io::Result<fs::File> {
let _ = ambient_authority;

let mut options = fs::OpenOptions::new();
options.read(true);

Expand Down
3 changes: 2 additions & 1 deletion cap-primitives/src/time/monotonic_clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ impl MonotonicClock {
///
/// This uses ambient authority to accesses clocks.
#[inline]
pub const fn new(_: AmbientAuthority) -> Self {
pub const fn new(ambient_authority: AmbientAuthority) -> Self {
let _ = ambient_authority;
Self(())
}

Expand Down
3 changes: 2 additions & 1 deletion cap-primitives/src/time/system_clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ impl SystemClock {
///
/// This uses ambient authority to accesses clocks.
#[inline]
pub const fn new(_: AmbientAuthority) -> Self {
pub const fn new(ambient_authority: AmbientAuthority) -> Self {
let _ = ambient_authority;
Self(())
}

Expand Down
7 changes: 6 additions & 1 deletion cap-primitives/src/windows/fs/dir_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,12 @@ pub(crate) fn canonicalize_options() -> OpenOptions {
///
/// This function is not sandboxed and may trivially access any path that the
/// host process has access to.
pub(crate) fn open_ambient_dir_impl(path: &Path, _: AmbientAuthority) -> io::Result<fs::File> {
pub(crate) fn open_ambient_dir_impl(
path: &Path,
ambient_authority: AmbientAuthority,
) -> io::Result<fs::File> {
let _ = ambient_authority;

// Set `FILE_FLAG_BACKUP_SEMANTICS` so that we can open directories. Unset
// `FILE_SHARE_DELETE` so that directories can't be renamed or deleted
// underneath us, since we use paths to implement many directory operations.
Expand Down
12 changes: 8 additions & 4 deletions cap-rand/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ pub mod rngs {
/// This function makes use of ambient authority to access the platform
/// entropy source.
#[inline]
pub const fn default(_: AmbientAuthority) -> Self {
pub const fn default(ambient_authority: AmbientAuthority) -> Self {
let _ = ambient_authority;
Self(())
}
}
Expand Down Expand Up @@ -161,7 +162,8 @@ pub mod rngs {
/// This function makes use of ambient authority to access the platform entropy
/// source.
#[inline]
pub fn thread_rng(_: AmbientAuthority) -> rngs::CapRng {
pub fn thread_rng(ambient_authority: AmbientAuthority) -> rngs::CapRng {
let _ = ambient_authority;
rngs::CapRng {
inner: rand::thread_rng(),
}
Expand All @@ -176,7 +178,8 @@ pub fn thread_rng(_: AmbientAuthority) -> rngs::CapRng {
/// This function makes use of ambient authority to access the platform entropy
/// source.
#[inline]
pub fn std_rng_from_entropy(_: AmbientAuthority) -> rngs::StdRng {
pub fn std_rng_from_entropy(ambient_authority: AmbientAuthority) -> rngs::StdRng {
let _ = ambient_authority;
rand::rngs::StdRng::from_entropy()
}

Expand All @@ -189,9 +192,10 @@ pub fn std_rng_from_entropy(_: AmbientAuthority) -> rngs::StdRng {
/// This function makes use of ambient authority to access the platform entropy
/// source.
#[inline]
pub fn random<T>(_: AmbientAuthority) -> T
pub fn random<T>(ambient_authority: AmbientAuthority) -> T
where
crate::distributions::Standard: crate::distributions::Distribution<T>,
{
let _ = ambient_authority;
rand::random()
}

0 comments on commit 58dd07c

Please sign in to comment.