diff options
author | Nick Mathewson <nickm@torproject.org> | 2024-05-07 19:18:07 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2024-05-07 19:18:07 +0000 |
commit | 1f0a5d3a917d2a8c1b600ce902326cf7e3bcd104 (patch) | |
tree | eeab08a35c66864228e979c104320c1cd85c251d | |
parent | 6dae6f12a94e5b76cb31966a7c9c5433ee8d4c7e (diff) | |
parent | 0ef90866793c1529a3cfb697fd834181e684b451 (diff) | |
download | arti-1f0a5d3a917d2a8c1b600ce902326cf7e3bcd104.tar.gz arti-1f0a5d3a917d2a8c1b600ce902326cf7e3bcd104.zip |
Merge branch 'bug1395_remaining' into 'main'
Fix remaining instances of unexpected_cfgs lint
Closes #1395
See merge request tpo/core/arti!2134
-rw-r--r-- | crates/equix/Cargo.toml | 4 | ||||
-rw-r--r-- | crates/equix/fuzz/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/equix/src/bucket_array/mem.rs | 42 | ||||
-rw-r--r-- | crates/equix/src/lib.rs | 5 | ||||
-rw-r--r-- | crates/tor-cell/src/restrict.rs | 71 | ||||
-rw-r--r-- | crates/tor-consdiff/fuzz/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/tor-consdiff/src/lib.rs | 8 | ||||
-rw-r--r-- | crates/tor-netdoc/src/doc/routerdesc.rs | 3 | ||||
-rwxr-xr-x | maint/check_doc_features | 2 |
9 files changed, 82 insertions, 55 deletions
diff --git a/crates/equix/Cargo.toml b/crates/equix/Cargo.toml index 6ef498760..769852065 100644 --- a/crates/equix/Cargo.toml +++ b/crates/equix/Cargo.toml @@ -24,6 +24,10 @@ license = "LGPL-3.0-only" default = ["compiler"] full = ["compiler", "hashx/full"] compiler = ["hashx/compiler"] +experimental = ["bucket-array"] +# For fuzzing only: expose the unstable 'bucket-array' API. +bucket-array = ["__is_experimental"] +__is_experimental = [] [dependencies] arrayvec = "0.7.4" diff --git a/crates/equix/fuzz/Cargo.toml b/crates/equix/fuzz/Cargo.toml index a648d7a54..33431dd56 100644 --- a/crates/equix/fuzz/Cargo.toml +++ b/crates/equix/fuzz/Cargo.toml @@ -14,6 +14,7 @@ libfuzzer-sys = "0.4" [dependencies.equix] path = ".." +features = ["bucket-array"] # Prevent this from interfering with workspaces [workspace] diff --git a/crates/equix/src/bucket_array/mem.rs b/crates/equix/src/bucket_array/mem.rs index f52eb63bc..77d869a6a 100644 --- a/crates/equix/src/bucket_array/mem.rs +++ b/crates/equix/src/bucket_array/mem.rs @@ -39,6 +39,10 @@ //! certain to never increment the counter without actually writing to the //! [`MaybeUninit`]. See [`BucketState::insert`]. +// We need to allow this warning because we conditionally make some private +// functions public, but their documentation links to private types. +#![allow(rustdoc::private_intra_doc_links)] + use num_traits::{One, Zero}; use std::alloc; use std::mem::MaybeUninit; @@ -56,7 +60,7 @@ use std::ops::{Add, Range}; /// This memory is always assumed to be uninitialized unless we hold a mutable /// reference that's associated with information about specific fields that /// were initialized during the reference's lifetime. -#[cfg_attr(fuzzing, visibility::make(pub))] +#[cfg_attr(feature = "bucket-array", visibility::make(pub))] pub(crate) unsafe trait Uninit: Copy { /// Allocate new uninitialized memory, returning a new Box. fn alloc() -> Box<Self> { @@ -77,7 +81,7 @@ pub(crate) unsafe trait Uninit: Copy { /// /// Implements [`Uninit`]. Structs and unions made from `BucketArrayMemory` /// can be soundly marked as [`Uninit`]. -#[cfg_attr(fuzzing, visibility::make(pub))] +#[cfg_attr(feature = "bucket-array", visibility::make(pub))] #[derive(Copy, Clone)] pub(crate) struct BucketArrayMemory< // Number of buckets @@ -97,7 +101,7 @@ pub(crate) struct BucketArrayMemory< unsafe impl<const N: usize, const M: usize, T: Copy> Uninit for BucketArrayMemory<N, M, T> {} /// Types that can be used as a count of items in a bucket -#[cfg_attr(fuzzing, visibility::make(pub))] +#[cfg_attr(feature = "bucket-array", visibility::make(pub))] pub(crate) trait Count: Copy + Zero + One + Into<usize> + Add<Self, Output = Self> {} impl<T: Copy + Zero + One + Into<usize> + Add<Self, Output = Self>> Count for T {} @@ -163,7 +167,7 @@ impl<const N: usize, const CAP: usize, C: Count> BucketState<N, CAP, C> { } /// Concrete binding between one [`BucketState`] and one [`BucketArrayMemory`] -#[cfg_attr(fuzzing, visibility::make(pub))] +#[cfg_attr(feature = "bucket-array", visibility::make(pub))] pub(crate) struct BucketArray< // Lifetime for mutable reference to the backing memory 'a, @@ -184,7 +188,7 @@ pub(crate) struct BucketArray< impl<'a, const N: usize, const CAP: usize, C: Count, A: Copy> BucketArray<'a, N, CAP, C, A> { /// A new [`BucketArray`] wraps a new [`BucketState`] and some possibly-recycled [`BucketArrayMemory`] - #[cfg_attr(fuzzing, visibility::make(pub))] + #[cfg_attr(feature = "bucket-array", visibility::make(pub))] pub(crate) fn new(mem: &'a mut BucketArrayMemory<N, CAP, A>) -> Self { Self { mem, @@ -195,7 +199,7 @@ impl<'a, const N: usize, const CAP: usize, C: Count, A: Copy> BucketArray<'a, N, /// Look up the valid item range for a particular bucket. /// /// Panics if the bucket index is out of range. - #[cfg_attr(fuzzing, visibility::make(pub))] + #[cfg_attr(feature = "bucket-array", visibility::make(pub))] #[inline(always)] pub(crate) fn item_range(&self, bucket: usize) -> Range<usize> { self.state.item_range(bucket) @@ -204,7 +208,7 @@ impl<'a, const N: usize, const CAP: usize, C: Count, A: Copy> BucketArray<'a, N, /// Look up the value of one item in one bucket. /// /// Panics if the indices are out of range. - #[cfg_attr(fuzzing, visibility::make(pub))] + #[cfg_attr(feature = "bucket-array", visibility::make(pub))] #[inline(always)] pub(crate) fn item_value(&self, bucket: usize, item: usize) -> A { assert!(self.state.item_range(bucket).contains(&item)); @@ -216,7 +220,11 @@ impl<'a, const N: usize, const CAP: usize, C: Count, A: Copy> BucketArray<'a, N, /// Append a new item to a bucket. /// /// If the bucket is full, returns `Err(())` and makes no changes. - #[cfg_attr(fuzzing, visibility::make(pub))] + #[cfg_attr( + feature = "bucket-array", + visibility::make(pub), + allow(clippy::result_unit_err) + )] #[inline(always)] pub(crate) fn insert(&mut self, bucket: usize, value: A) -> Result<(), ()> { self.state.insert(bucket, |item| { @@ -226,7 +234,7 @@ impl<'a, const N: usize, const CAP: usize, C: Count, A: Copy> BucketArray<'a, N, } /// Concrete binding between one [`BucketState`] and a pair of [`BucketArrayMemory`] -#[cfg_attr(fuzzing, visibility::make(pub))] +#[cfg_attr(feature = "bucket-array", visibility::make(pub))] pub(crate) struct BucketArrayPair< // Lifetime for mutable reference to the first backing memory 'a, @@ -255,7 +263,7 @@ impl<'a, 'b, const N: usize, const CAP: usize, C: Count, A: Copy, B: Copy> BucketArrayPair<'a, 'b, N, CAP, C, A, B> { /// A new [`BucketArray`] wraps a new [`BucketState`] and two [`BucketArrayMemory`] - #[cfg_attr(fuzzing, visibility::make(pub))] + #[cfg_attr(feature = "bucket-array", visibility::make(pub))] pub(crate) fn new( mem_a: &'a mut BucketArrayMemory<N, CAP, A>, mem_b: &'b mut BucketArrayMemory<N, CAP, B>, @@ -270,7 +278,7 @@ impl<'a, 'b, const N: usize, const CAP: usize, C: Count, A: Copy, B: Copy> /// Look up the valid item range for a particular bucket. /// /// Panics if the bucket index is out of range. - #[cfg_attr(fuzzing, visibility::make(pub))] + #[cfg_attr(feature = "bucket-array", visibility::make(pub))] #[inline(always)] pub(crate) fn item_range(&self, bucket: usize) -> Range<usize> { self.state.item_range(bucket) @@ -279,7 +287,7 @@ impl<'a, 'b, const N: usize, const CAP: usize, C: Count, A: Copy, B: Copy> /// Look up the first value for one item in one bucket. /// /// Panics if the indices are out of range. - #[cfg_attr(fuzzing, visibility::make(pub))] + #[cfg_attr(feature = "bucket-array", visibility::make(pub))] #[inline(always)] pub(crate) fn item_value_first(&self, bucket: usize, item: usize) -> A { assert!(self.state.item_range(bucket).contains(&item)); @@ -291,7 +299,7 @@ impl<'a, 'b, const N: usize, const CAP: usize, C: Count, A: Copy, B: Copy> /// Look up the second value for one item in one bucket. /// /// Panics if the indices are out of range. - #[cfg_attr(fuzzing, visibility::make(pub))] + #[cfg_attr(feature = "bucket-array", visibility::make(pub))] #[inline(always)] pub(crate) fn item_value_second(&self, bucket: usize, item: usize) -> B { assert!(self.state.item_range(bucket).contains(&item)); @@ -303,7 +311,11 @@ impl<'a, 'b, const N: usize, const CAP: usize, C: Count, A: Copy, B: Copy> /// Append a new item pair to a bucket. /// /// If the bucket is full, returns Err(()) and makes no changes. - #[cfg_attr(fuzzing, visibility::make(pub))] + #[cfg_attr( + feature = "bucket-array", + visibility::make(pub), + allow(clippy::result_unit_err) + )] #[inline(always)] pub(crate) fn insert(&mut self, bucket: usize, first: A, second: B) -> Result<(), ()> { self.state.insert(bucket, |item| { @@ -314,7 +326,7 @@ impl<'a, 'b, const N: usize, const CAP: usize, C: Count, A: Copy, B: Copy> /// Transfer the [`BucketState`] to a new single [`BucketArray`], /// keeping the second half and dropping the first. - #[cfg_attr(fuzzing, visibility::make(pub))] + #[cfg_attr(feature = "bucket-array", visibility::make(pub))] pub(crate) fn drop_first(self) -> BucketArray<'b, N, CAP, C, B> { BucketArray { mem: self.mem_b, diff --git a/crates/equix/src/lib.rs b/crates/equix/src/lib.rs index bdaed927c..9789632cc 100644 --- a/crates/equix/src/lib.rs +++ b/crates/equix/src/lib.rs @@ -47,8 +47,9 @@ mod err; mod solution; mod solver; -// Export bucket_array::mem API only to the fuzzer -#[cfg(fuzzing)] +// Export bucket_array::mem API only to the fuzzer. +// (This is not stable; you should not use it except for testing.) +#[cfg(feature = "bucket-array")] pub use bucket_array::mem::{BucketArray, BucketArrayMemory, BucketArrayPair, Count, Uninit}; use hashx::{HashX, HashXBuilder}; diff --git a/crates/tor-cell/src/restrict.rs b/crates/tor-cell/src/restrict.rs index 5de6e0aff..97d09a9eb 100644 --- a/crates/tor-cell/src/restrict.rs +++ b/crates/tor-cell/src/restrict.rs @@ -162,42 +162,49 @@ macro_rules! restricted_msg { } } - $( - #[cfg(feature = $omit_from)] - )? - impl From<$name> for $any_msg { - fn from(msg: $name) -> $any_msg { - match msg { - $( - $( #[cfg(feature=$feat)] )? - $name::$case(b) => Self::$case(b), - )* - $( - $name::$unrecognized(u) => $any_msg::Unrecognized(u), - )? + #[allow(unexpected_cfgs)] + const _: () = { + $( + #[cfg(feature = $omit_from)] + )? + impl From<$name> for $any_msg { + fn from(msg: $name) -> $any_msg { + match msg { + $( + $( #[cfg(feature=$feat)] )? + $name::$case(b) => Self::$case(b), + )* + $( + $name::$unrecognized(u) => $any_msg::Unrecognized(u), + )? + } } } - } + }; - $( - #[cfg(feature = $omit_from)] - )? - impl TryFrom<$any_msg> for $name { - type Error = $any_msg; - fn try_from(msg: $any_msg) -> std::result::Result<$name, $any_msg> { - Ok(match msg { - $( - $( #[cfg(feature=$feat)] )? - $any_msg::$case(b) => $name::$case(b), - )* - $( - $any_msg::Unrecognized(u) => Self::$unrecognized(u), - )? - #[allow(unreachable_patterns)] - other => return Err(other), - }) + #[allow(unexpected_cfgs)] + const _: () = { + $( + #[cfg(feature = $omit_from)] + )? + impl TryFrom<$any_msg> for $name { + type Error = $any_msg; + fn try_from(msg: $any_msg) -> std::result::Result<$name, $any_msg> { + Ok(match msg { + $( + $( #[cfg(feature=$feat)] )? + $any_msg::$case(b) => $name::$case(b), + )* + $( + $any_msg::Unrecognized(u) => Self::$unrecognized(u), + )? + #[allow(unreachable_patterns)] + other => return Err(other), + }) + } } - } + }; + $( $( #[cfg(feature=$feat)] )? impl From<$msg_mod :: $case> for $name { diff --git a/crates/tor-consdiff/fuzz/Cargo.toml b/crates/tor-consdiff/fuzz/Cargo.toml index fba6494c3..1fe1bf305 100644 --- a/crates/tor-consdiff/fuzz/Cargo.toml +++ b/crates/tor-consdiff/fuzz/Cargo.toml @@ -14,6 +14,7 @@ libfuzzer-sys = "0.4" [dependencies.tor-consdiff] path = ".." +features = ["slow-diff-apply"] # Prevent this from interfering with workspaces [workspace] diff --git a/crates/tor-consdiff/src/lib.rs b/crates/tor-consdiff/src/lib.rs index 1bc3c9c08..d9db4fd91 100644 --- a/crates/tor-consdiff/src/lib.rs +++ b/crates/tor-consdiff/src/lib.rs @@ -62,7 +62,7 @@ pub fn looks_like_diff(s: &str) -> bool { /// /// This is a slow version, for testing and correctness checking. It uses /// an O(n) operation to apply diffs, and therefore runs in O(n^2) time. -#[cfg(any(test, fuzzing, feature = "slow-diff-apply"))] +#[cfg(any(test, feature = "slow-diff-apply"))] pub fn apply_diff_trivial<'a>(input: &'a str, diff: &'a str) -> Result<DiffResult<'a>> { let mut diff_lines = diff.lines(); let (_, d2) = parse_diff_header(&mut diff_lines)?; @@ -214,7 +214,7 @@ impl<'a> DiffCommand<'a> { /// /// Because DiffResult internally uses a vector of line, this /// implementation is potentially O(n) in the size of the input. - #[cfg(any(test, fuzzing, feature = "slow-diff-apply"))] + #[cfg(any(test, feature = "slow-diff-apply"))] fn apply_to(&self, target: &mut DiffResult<'a>) -> Result<()> { match self { Self::Delete { low, high } => { @@ -496,7 +496,7 @@ impl<'a> DiffResult<'a> { /// /// This has to move elements around within the vector, and so it /// is potentially O(n) in its length. - #[cfg(any(test, fuzzing, feature = "slow-diff-apply"))] + #[cfg(any(test, feature = "slow-diff-apply"))] fn remove_lines(&mut self, first: usize, last: usize) -> Result<()> { if first > self.lines.len() || last > self.lines.len() || first == 0 || last == 0 { Err(Error::CantApply("line out of range")) @@ -515,7 +515,7 @@ impl<'a> DiffResult<'a> { /// /// This has to move elements around within the vector, and so it /// is potentially O(n) in its length. - #[cfg(any(test, fuzzing, feature = "slow-diff-apply"))] + #[cfg(any(test, feature = "slow-diff-apply"))] fn insert_at(&mut self, pos: usize, lines: &[&'a str]) -> Result<()> { if pos > self.lines.len() + 1 || pos == 0 { Err(Error::CantApply("position out of range")) diff --git a/crates/tor-netdoc/src/doc/routerdesc.rs b/crates/tor-netdoc/src/doc/routerdesc.rs index 232f7e5fe..b1507956c 100644 --- a/crates/tor-netdoc/src/doc/routerdesc.rs +++ b/crates/tor-netdoc/src/doc/routerdesc.rs @@ -498,12 +498,13 @@ impl RouterDesc { }; // master-key-ed25519: required, and should match certificate. + #[allow(unexpected_cfgs)] { let master_key_tok = body.required(MASTER_KEY_ED25519)?; let ed_id: Ed25519Public = master_key_tok.parse_arg(0)?; let ed_id: ll::pk::ed25519::Ed25519Identity = ed_id.into(); if ed_id != *identity_cert.peek_signing_key() { - #[cfg(not(fuzzing))] + #[cfg(not(fuzzing))] // No feature here; never omit in production. return Err(EK::BadObjectVal .at_pos(master_key_tok.pos()) .with_msg("master-key-ed25519 does not match key in identity-ed25519")); diff --git a/maint/check_doc_features b/maint/check_doc_features index 9da8df44d..7f3fb3b14 100755 --- a/maint/check_doc_features +++ b/maint/check_doc_features @@ -13,7 +13,7 @@ additional_required = {} # Not interested in the low-level interfaces we provide only for fuzzing additional_provided['equix'] = [ - ('{BucketArray, BucketArrayMemory, BucketArrayPair, Count, Uninit}', 'fuzzing'), + ('{BucketArray, BucketArrayMemory, BucketArrayPair, Count, Uninit}', 'feature = "bucket-array"'), ] # PreferredRuntime has a somewhat more complexe rule for existing |