diff options
author | Luca Casonato <hello@lcas.dev> | 2022-06-26 00:13:24 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-26 00:13:24 +0200 |
commit | 8d82ba729937baf83011354242cabc3d50c13dc2 (patch) | |
tree | 3e8c4d87986338639eeef4a76543e4335020262c /core/ops_metrics.rs | |
parent | 38505db39137f33bfdb942658ea892a617ac0980 (diff) |
build: require safety comments on unsafe code (#13870)
Co-authored-by: Bartek IwaĆczuk <biwanczuk@gmail.com>
Co-authored-by: Divy Srivastava <dj.srivastava23@gmail.com>
Diffstat (limited to 'core/ops_metrics.rs')
-rw-r--r-- | core/ops_metrics.rs | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/core/ops_metrics.rs b/core/ops_metrics.rs index b068aa0ee..aa3ff503b 100644 --- a/core/ops_metrics.rs +++ b/core/ops_metrics.rs @@ -56,12 +56,17 @@ impl OpsTracker { #[allow(clippy::mut_from_ref)] #[inline] fn ops_mut(&self) -> &mut Vec<OpMetrics> { + // SAFETY: `OpsTracker` is created after registering ops so it is guaranteed + // that that `ops` will be initialized. unsafe { &mut *self.ops.get() } } #[allow(clippy::mut_from_ref)] #[inline] fn metrics_mut(&self, id: OpId) -> &mut OpMetrics { + // SAFETY: `OpsTracker` is created after registering ops, and ops + // cannot be unregistered during runtime, so it is guaranteed that `id` + // is not causing out-of-bound access. unsafe { self.ops_mut().get_unchecked_mut(id) } } |