Merge branch 'disallowed_lint' into 'main'

Remove allow(clippy::disallowed_methods) lint flag.

See merge request tpo/core/arti!437
This commit is contained in:
eta 2022-03-30 14:02:13 +00:00
commit 5d27710ef1
22 changed files with 2 additions and 46 deletions

View File

@ -1,3 +1,3 @@
disallowed-methods = [
{ path = "std::time::SystemTime::now", reason = "prefere using SleepProvider::wallclock instead when possible" },
# { path = "std::time::SystemTime::now", reason = "prefere using SleepProvider::wallclock instead when possible" },
]

View File

@ -34,7 +34,6 @@
// This file uses `unwrap()` a fair deal, but this is fine in test/bench code
// because it's OK if tests and benchmarks simply crash if things go wrong.
#![allow(clippy::unwrap_used)]
#![allow(clippy::disallowed_methods)]
use anyhow::{anyhow, Result};
use arti::cfg::ArtiConfig;

View File

@ -38,10 +38,7 @@ impl BootstrapStatus {
/// 0 is defined as "just started"; 1 is defined as "ready to use."
pub fn as_frac(&self) -> f32 {
// Coefficients chosen arbitrarily.
#[allow(clippy::disallowed_methods)]
let res =
self.conn_status.frac() * 0.15 + self.dir_status.frac_at(SystemTime::now()) * 0.85;
res
self.conn_status.frac() * 0.15 + self.dir_status.frac_at(SystemTime::now()) * 0.85
}
/// Return true if the status indicates that the client is ready for
@ -50,7 +47,6 @@ impl BootstrapStatus {
/// For the purposes of this function, the client is "ready for traffic" if,
/// as far as we know, we can start acting on a new client request immediately.
pub fn ready_for_traffic(&self) -> bool {
#[allow(clippy::disallowed_methods)]
let now = SystemTime::now();
self.conn_status.usable() && self.dir_status.usable_at(now)
}

View File

@ -119,7 +119,6 @@ pub trait Timebound<T>: Sized {
/// Unwrap this Timebound object if it is valid now.
fn check_valid_now(self) -> Result<T, Self::Error> {
#[allow(clippy::disallowed_methods)]
self.check_valid_at(&time::SystemTime::now())
}

View File

@ -265,7 +265,6 @@ mod test {
let dirinfo = (&netdir).into();
let config = PathConfig::default();
let guards: OptDummyGuardMgr<'_> = None;
#[allow(clippy::disallowed_methods)]
let now = SystemTime::now();
for _ in 0..1000 {
@ -311,7 +310,6 @@ mod test {
.unwrap();
let dirinfo = (&netdir).into();
let guards: OptDummyGuardMgr<'_> = None;
#[allow(clippy::disallowed_methods)]
let now = SystemTime::now();
let config = PathConfig::default();
@ -359,7 +357,6 @@ mod test {
let dirinfo = (&netdir).into();
let guards: OptDummyGuardMgr<'_> = None;
let config = PathConfig::default();
#[allow(clippy::disallowed_methods)]
let now = SystemTime::now();
// With target ports

View File

@ -667,7 +667,6 @@ pub(crate) mod test {
let di = (&netdir).into();
let config = crate::PathConfig::default();
let guards: OptDummyGuardMgr<'_> = None;
#[allow(clippy::disallowed_methods)]
let now = SystemTime::now();
// Only doing basic tests for now. We'll test the path
@ -745,7 +744,6 @@ pub(crate) mod test {
let di = (&netdir).into();
let config = crate::PathConfig::default();
let guards: OptDummyGuardMgr<'_> = None;
#[allow(clippy::disallowed_methods)]
let now = SystemTime::now();
let (path, usage, _, _) = TargetCircUsage::TimeoutTesting

View File

@ -502,7 +502,6 @@ mod test {
) -> (RequestResult<()>, Vec<u8>) {
// We don't need to do anything fancy here, since we aren't simulating
// a timeout.
#[allow(clippy::disallowed_methods)]
let mock_time = MockSleepProvider::new(std::time::SystemTime::now());
let mut output = Vec::new();

View File

@ -469,7 +469,6 @@ mod test {
.unwrap();
let d2 = b"blah blah blah 12 blah blah blah";
#[allow(clippy::disallowed_methods)]
let d3 = SystemTime::now();
let mut req = ConsensusRequest::default();

View File

@ -380,7 +380,6 @@ mod test {
#[test]
fn week() {
#[allow(clippy::disallowed_methods)]
let now = SystemTime::now();
let one_day = Duration::new(86400, 0);

View File

@ -633,7 +633,6 @@ mod test {
#[test]
fn dir_status_basics() {
#[allow(clippy::disallowed_methods)]
let now = SystemTime::now();
let hour = Duration::new(3600, 0);

View File

@ -693,7 +693,6 @@ mod test {
fn basic_guard() -> Guard {
let id = basic_id();
let ports = vec!["127.0.0.7:7777".parse().unwrap()];
#[allow(clippy::disallowed_methods)]
let added = SystemTime::now();
Guard::new(id, ports, added)
}
@ -814,7 +813,6 @@ mod test {
fn record_success() {
let t1 = Instant::now() - Duration::from_secs(10);
// has to be in the future, since the guard's "added_at" time is based on now.
#[allow(clippy::disallowed_methods)]
let now = SystemTime::now();
let t2 = now + Duration::from_secs(300 * 86400);
let t3 = Instant::now() + Duration::from_secs(310 * 86400);
@ -871,7 +869,6 @@ mod test {
fn expiration() {
const DAY: Duration = Duration::from_secs(24 * 60 * 60);
let params = GuardParams::default();
#[allow(clippy::disallowed_methods)]
let now = SystemTime::now();
let g = basic_guard();
@ -903,7 +900,6 @@ mod test {
.unwrap_if_sufficient()
.unwrap();
let params = GuardParams::default();
#[allow(clippy::disallowed_methods)]
let now = SystemTime::now();
// Construct a guard from a relay from the netdir.
@ -960,7 +956,6 @@ mod test {
.unwrap();
//let params = GuardParams::default();
#[allow(clippy::disallowed_methods)]
let now = SystemTime::now();
// Try a guard that isn't in the netdir at all.
@ -1043,7 +1038,6 @@ mod test {
let mut g = basic_guard();
let params = GuardParams::default();
#[allow(clippy::disallowed_methods)]
let now = SystemTime::now();
let _ignore = g.record_success(now, &params);

View File

@ -869,7 +869,6 @@ mod test {
let mut samples: Vec<HashSet<GuardId>> = Vec::new();
for _ in 0..3 {
let mut guards = GuardSet::default();
#[allow(clippy::disallowed_methods)]
guards.extend_sample_as_needed(SystemTime::now(), &params, &netdir);
assert_eq!(guards.guards.len(), params.min_filtered_sample_size);
assert_eq!(guards.confirmed.len(), 0);
@ -882,14 +881,12 @@ mod test {
assert!(relay.is_flagged_guard());
assert!(relay.is_dir_cache());
assert!(guards.contains_relay(&relay));
#[allow(clippy::disallowed_methods)]
{
assert!(!guard.is_expired(&params, SystemTime::now()));
}
}
// Make sure that the sample doesn't expand any further.
#[allow(clippy::disallowed_methods)]
guards.extend_sample_as_needed(SystemTime::now(), &params, &netdir);
assert_eq!(guards.guards.len(), params.min_filtered_sample_size);
guards.assert_consistency();
@ -910,7 +907,6 @@ mod test {
..GuardParams::default()
};
#[allow(clippy::disallowed_methods)]
let t1 = SystemTime::now();
let t2 = t1 + Duration::from_secs(20);
@ -947,7 +943,6 @@ mod test {
n_primary: 4,
..GuardParams::default()
};
#[allow(clippy::disallowed_methods)]
let t1 = SystemTime::now();
let t2 = t1 + Duration::from_secs(20);
let t3 = t2 + Duration::from_secs(30);
@ -994,7 +989,6 @@ mod test {
fn expiration() {
let netdir = netdir();
let params = GuardParams::default();
#[allow(clippy::disallowed_methods)]
let t1 = SystemTime::now();
let mut guards = GuardSet::default();
@ -1029,7 +1023,6 @@ mod test {
n_primary: 2,
..GuardParams::default()
};
#[allow(clippy::disallowed_methods)]
let st1 = SystemTime::now();
let i1 = Instant::now();
let sec = Duration::from_secs(1);
@ -1153,7 +1146,6 @@ mod test {
max_sample_bw_fraction: 1.0,
..GuardParams::default()
};
#[allow(clippy::disallowed_methods)]
let mut st = SystemTime::now();
let mut inst = Instant::now();
let sec = Duration::from_secs(1);
@ -1196,7 +1188,6 @@ mod test {
let mut guards = GuardSet::default();
#[allow(clippy::disallowed_methods)]
guards.extend_sample_as_needed(SystemTime::now(), &params, &netdir);
guards.select_primary_guards(&params);
@ -1234,13 +1225,11 @@ mod test {
};
let usage = crate::GuardUsageBuilder::default().build().unwrap();
let mut guards = GuardSet::default();
#[allow(clippy::disallowed_methods)]
guards.extend_sample_as_needed(SystemTime::now(), &params, &netdir);
guards.select_primary_guards(&params);
assert_eq!(guards.primary.len(), 2);
let (_kind, p_id1) = guards.pick_guard(&usage, &params).unwrap();
#[allow(clippy::disallowed_methods)]
guards.record_success(&p_id1, &params, SystemTime::now());
assert_eq!(guards.missing_primary_microdescriptors(&netdir), 0);

View File

@ -66,7 +66,6 @@ mod test {
#[test]
fn test_randomize_time() {
#[allow(clippy::disallowed_methods)]
let now = SystemTime::now();
let one_hour = Duration::from_secs(3600);
let ten_sec = Duration::from_secs(10);

View File

@ -138,7 +138,6 @@ where
f | RelayFlags::EXIT | RelayFlags::GUARD,
];
#[allow(clippy::disallowed_methods)]
let now = SystemTime::now();
let one_day = Duration::new(86400, 0);
let mut bld = MdConsensus::builder();

View File

@ -619,7 +619,6 @@ mod test {
#[test]
fn weightset_from_consensus() {
use rand::Rng;
#[allow(clippy::disallowed_methods)]
let now = SystemTime::now();
let one_hour = Duration::new(3600, 0);
let mut rng = rand::thread_rng();

View File

@ -146,7 +146,6 @@ mod test {
#[test]
fn simple_cert() {
#[allow(clippy::disallowed_methods)]
let now = SystemTime::now();
let one_hour = Duration::new(3600, 0);
let later = now + one_hour * 2;
@ -167,7 +166,6 @@ mod test {
#[test]
fn failing_cert() {
#[allow(clippy::disallowed_methods)]
let now = SystemTime::now();
let one_hour = Duration::new(3600, 0);
let later = now + one_hour * 2;

View File

@ -377,7 +377,6 @@ mod test {
#[test]
fn consensus() {
#[allow(clippy::disallowed_methods)]
let now = SystemTime::now();
let one_hour = Duration::new(3600, 0);

View File

@ -203,7 +203,6 @@ mod test {
}
let minute = Duration::from_secs(60);
let second = Duration::from_secs(1);
#[allow(clippy::disallowed_methods)]
let start = SystemTime::now();
let target = start + 30 * minute;

View File

@ -95,7 +95,6 @@ pub trait SleepProvider {
///
/// (This is the same as `SystemTime::now`, if not running in test mode.)
fn wallclock(&self) -> SystemTime {
#[allow(clippy::disallowed_methods)]
SystemTime::now()
}

View File

@ -26,7 +26,6 @@ impl<R: Runtime> MockSleepRuntime<R> {
/// Create a new runtime that wraps `runtime`, but overrides
/// its view of time with a [`MockSleepProvider`].
pub fn new(runtime: R) -> Self {
#[allow(clippy::disallowed_methods)]
let sleep = MockSleepProvider::new(SystemTime::now());
MockSleepRuntime { runtime, sleep }
}

View File

@ -439,7 +439,6 @@ mod test {
#[test]
fn basics_of_time_travel() {
#[allow(clippy::disallowed_methods)]
let w1 = SystemTime::now();
let sp = MockSleepProvider::new(w1);
let i1 = sp.now();
@ -462,7 +461,6 @@ mod test {
use std::sync::atomic::AtomicBool;
use std::sync::atomic::Ordering;
#[allow(clippy::disallowed_methods)]
let sp = MockSleepProvider::new(SystemTime::now());
let one_hour = Duration::new(3600, 0);

View File

@ -17,7 +17,6 @@ fn timeouts() {
oneshot::Sender<()>,
Timeout<oneshot::Receiver<()>, tor_rtmock::time::Sleeping>,
) {
#[allow(clippy::disallowed_methods)]
let start = SystemTime::now();
let (send, recv) = oneshot::channel::<()>();
let mock_sp = MockSleepProvider::new(start);