Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix clippy::missing-panics-doc #1377

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ build --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect

# TODO(aaronmondal): Extend these flags until we can run with clippy::pedantic.
# TODO(aaronmondal): Fix dependency_on_unit_never_type_fallback.
build --@rules_rust//:clippy_flags=-Dwarnings,-Adependency_on_unit_never_type_fallback,-Dclippy::uninlined_format_args,-Dclippy::manual_string_new
build --@rules_rust//:clippy_flags=-Dwarnings,-Adependency_on_unit_never_type_fallback,-Dclippy::uninlined_format_args,-Dclippy::manual_string_new,-Dclippy::missing-panics-doc
build --@rules_rust//:clippy.toml=//:clippy.toml

test --@rules_rust//:rustfmt.toml=//:.rustfmt.toml
Expand Down
3 changes: 3 additions & 0 deletions nativelink-metric/nativelink-metric-macro-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ impl<'a> ToTokens for MetricStruct<'a> {
}
}

/// # Panics
///
/// This function will panic if the `MetricsComponent` macro is applied to anything other than a struct.
#[proc_macro_derive(MetricsComponent, attributes(metric))]
pub fn metrics_component_derive(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as DeriveInput);
Expand Down
7 changes: 7 additions & 0 deletions nativelink-scheduler/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ fn reduce_platform_properties(
}

impl Worker {
/// Creates a new `Worker` with the specified ID, platform properties, sender, and timestamp.
///
/// # Panics
///
/// This function will panic if the system time is earlier than the Unix epoch.
/// The panic occurs due to the call to `SystemTime::now().duration_since(UNIX_EPOCH).unwrap()`,
/// which will fail if the system clock is misconfigured or set to a time before the Unix epoch.
pub fn new(
id: WorkerId,
platform_properties: PlatformProperties,
Expand Down
12 changes: 12 additions & 0 deletions nativelink-service/src/worker_api_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ pub struct WorkerApiServer {
}

impl WorkerApiServer {
/// Creates a new `WorkerApiServer` with the given configuration and schedulers.
///
/// # Panics
///
/// This function panics if the system time is earlier than the Unix epoch.
/// The panic occurs in two situations:
/// - When retrieving the system time for scheduler timeouts (`SystemTime::now().duration_since(UNIX_EPOCH)`).
/// - During server creation, if the system time is invalid, it will trigger an internal error.
///
/// # Errors
///
/// Returns an error if the server could not be created with the given configuration and schedulers.
pub fn new(
config: &WorkerApiConfig,
schedulers: &HashMap<String, Arc<dyn WorkerScheduler>>,
Expand Down
10 changes: 10 additions & 0 deletions nativelink-store/src/s3_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,16 @@ where
I: InstantWrapper,
NowFn: Fn() -> I + Send + Sync + Unpin + 'static,
{
/// Creates a new S3 store with the specified configuration and time function.
///
/// # Panics
///
/// This function will panic if the application name provided to the AWS SDK is invalid.
/// The panic occurs with the message `"valid app name"` in the call to `AppName::new()`.
///
/// # Errors
///
/// Returns an error if there is an issue with creating the S3 client or other components.
pub async fn new(
config: &nativelink_config::stores::S3Store,
now_fn: NowFn,
Expand Down
10 changes: 10 additions & 0 deletions nativelink-store/src/shard_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ pub struct ShardStore {
}

impl ShardStore {
/// Creates a new `ShardStore` with the given configuration and stores.
///
/// # Panics
///
/// This function will panic if the `weights` vector is empty when attempting to modify the last element
/// using `unwrap()`. This panic should not occur as long as the `config.stores` is not empty, as validated earlier.
///
/// # Errors
///
/// Returns an error if the number of `config.stores` does not match the number of `stores`, or if `config.stores` is empty.
pub fn new(
config: &nativelink_config::stores::ShardStore,
stores: Vec<Store>,
Expand Down
13 changes: 13 additions & 0 deletions nativelink-util/src/buf_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,14 @@ impl DropCloserReadHalf {
///
/// On error the state of the stream is undefined and the caller should not
/// attempt to use the stream again.
/// # Panics
///
/// This function will panic if the `recent_data` is not empty after draining it.
/// Specifically, it panics with the message `"Recent_data should be empty"`.
///
/// # Errors
///
/// Returns an error if `bytes_received` exceeds `max_recent_data_size`.
pub fn try_reset_stream(&mut self) -> Result<(), Error> {
if self.bytes_received > self.max_recent_data_size {
return Err(make_err!(
Expand Down Expand Up @@ -313,6 +321,11 @@ impl DropCloserReadHalf {
}

/// Peek the next set of bytes in the stream without consuming them.
///
/// # Panics
///
/// This function will panic if `queued_data` is empty after attempting to receive data.
/// The panic occurs with the message `"Should have data in the queue"`.
pub async fn peek(&mut self) -> &Result<Bytes, Error> {
if self.queued_data.is_empty() {
let chunk = self.recv().await;
Expand Down
5 changes: 5 additions & 0 deletions nativelink-util/src/evicting_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ where
/// and return the number of items that were processed.
/// The `handler` function should return `true` to continue processing the next item
/// or `false` to stop processing.
///
/// # Panics
///
/// This function will panic if the `btree` index is not properly initialized and is `None` after attempting to rebuild it.
/// The panic occurs due to calling `unwrap()` on a `None` value.
pub async fn range<F, Q>(&self, prefix_range: impl RangeBounds<Q>, mut handler: F) -> u64
where
F: FnMut(&K, &T) -> bool,
Expand Down
7 changes: 7 additions & 0 deletions nativelink-util/src/fastcdc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ pub struct FastCDC {
}

impl FastCDC {
/// Creates a new instance with the specified minimum, average, and maximum sizes.
///
/// # Panics
///
/// This function will panic if:
/// - `min_size` is not less than `avg_size`, in which case it panics with the message `"Expected {min_size} < {avg_size}"`.
/// - `avg_size` is not less than `max_size`, in which case it panics with the message `"Expected {avg_size} < {max_size}"`.
pub fn new(min_size: usize, avg_size: usize, max_size: usize) -> Self {
assert!(min_size < avg_size, "Expected {min_size} < {avg_size}");
assert!(avg_size < max_size, "Expected {avg_size} < {max_size}");
Expand Down
7 changes: 7 additions & 0 deletions nativelink-util/src/metrics_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,13 @@ pub struct CounterWithTime {

impl CounterWithTime {
#[inline]
/// Increments the counter and updates the last time to the current system time.
///
/// # Panics
///
/// This function will panic if the system time is earlier than the Unix epoch.
/// This happens because `SystemTime::now().duration_since(UNIX_EPOCH).unwrap()` is called,
/// which panics if the system clock is incorrect or misconfigured.
pub fn inc(&self) {
if !metrics_enabled() {
return;
Expand Down
6 changes: 6 additions & 0 deletions nativelink-util/src/origin_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,12 @@ impl<T> ContextAwareFuture<T> {
/// active context.
#[must_use = "futures do nothing unless you `.await` or poll them"]
#[inline]
/// Creates a new `ContextAwareFuture` from the active origin context.
///
/// # Panics
///
/// This function will panic if the `ActiveOriginContext` is not set (i.e., it returns `None`).
/// The panic occurs with the message `"OriginContext must be set"`.
pub fn new_from_active(inner: Instrumented<T>) -> ContextAwareFuture<T> {
match ActiveOriginContext::get() {
Some(ctx) => ContextAwareFuture::new(Some(ctx), inner),
Expand Down
13 changes: 13 additions & 0 deletions nativelink-worker/src/worker_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ use nativelink_proto::com::github::trace_machina::nativelink::remote_execution::
use tokio::process;
use tracing::{event, Level};

/// Creates a `SupportedProperties` object based on the provided worker properties.
///
/// # Panics
///
/// This function will panic if the process fails and the exit status code cannot be retrieved
/// (i.e., `process_output.status.code().unwrap()` returns `None`). This might happen if the process was terminated by a signal and no exit code was available.
///
/// # Errors
///
/// Returns an error if:
/// - A worker property query command cannot be parsed.
/// - A worker property query command fails to execute.
/// - The process output cannot be converted to UTF-8.
pub async fn make_supported_properties<S: BuildHasher>(
worker_properties: &HashMap<String, WorkerProperty, S>,
) -> Result<SupportedProperties, Error> {
Expand Down