Skip to content
Closed
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
14 changes: 11 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -395,13 +395,21 @@ jobs:
enable-sccache: true
rust-toolchain: RUST_NIGHTLY
rust-components: llvm-tools-preview
cargo-tools: CARGO_LLVM_COV_VERSION
cargo-tools: CARGO_LLVM_COV_VERSION, CARGO_NEXTEST_VERSION

# execute
# Coverage is generated with `llvm-cov nextest` (one process per test) instead
# of the default `cargo test` harness (all tests in one process). Process
# isolation prevents cross-test contamination of tracing's process-global
# callsite-interest cache: with the single-process harness, a no-subscriber test
# can register a `tracing::event!` callsite as "never interested" before a
# subscriber-installing test runs, leaving the macro's enabled branch (its
# field-value expressions) recorded as uncovered nondeterministically across
# platforms. This matches the `just coverage-measure` recipe (justfiles/coverage.just).
- name: Generate Coverage (all-features)
run: cargo +${{ env.RUST_NIGHTLY }} llvm-cov --all-features --workspace --lcov --output-path lcov-all.info
run: cargo +${{ env.RUST_NIGHTLY }} llvm-cov nextest --all-features --workspace --lcov --output-path lcov-all.info
- name: Generate Coverage (no-default-features)
run: cargo +${{ env.RUST_NIGHTLY }} llvm-cov --no-default-features --workspace --lcov --output-path lcov-no-def.info
run: cargo +${{ env.RUST_NIGHTLY }} llvm-cov nextest --no-default-features --workspace --lcov --output-path lcov-no-def.info
- name: Upload Coverage to Codecov
uses: codecov/codecov-action@v7.0.0
with:
Expand Down
9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,15 @@ unreachable_pub = "warn"
unsafe_op_in_unsafe_fn = "warn"
unused_lifetimes = "warn"

# Coverage builds (`cargo llvm-cov nextest`) compile the non-test library of
# leaf crates whose `coverage(off)` attributes are all gated behind cargo
# features or `cfg(test)`. In feature/target combinations where none of those
# attributes are compiled, the crate-level `#![feature(coverage_attribute)]`
# gate (enabled by the `coverage_nightly` cfg) is technically unused. That is a
# benign artifact of instrumentation, not a real problem, so allow it rather
# than encoding brittle per-crate feature conditions on every coverage gate.
unused_features = "allow"
Comment on lines +218 to +221

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is smelly but I suppose there is no clean solution that avoids a cfg-conditional mess. We should file an issue in rust-lang/clippy to request possiblity for an allowlist in clippy.toml, though, so we can specifically say we are fine with "coverage_nightly" looking unused.


# Allow our special-purpose nonstandard cfg attributes.
# - coverage / coverage_nightly: set by cargo-llvm-cov to enable nightly coverage attributes.
# - loom: set via RUSTFLAGS to swap in the loom model-checker for atomics in select crates.
Expand Down
2 changes: 1 addition & 1 deletion crates/automation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//! An unpublished crate for shared code used for writing Rust scripts

#![allow(clippy::missing_errors_doc, reason = "this is an internal crate for scripts")]
#![cfg_attr(all(coverage_nightly, test), feature(coverage_attribute))]
#![cfg_attr(coverage_nightly, feature(coverage_attribute))]
#![cfg_attr(coverage_nightly, coverage(off))]

mod cargo;
Expand Down
24 changes: 12 additions & 12 deletions crates/cachet/src/telemetry/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ impl CacheTelemetry {
not(feature = "logs"),
expect(clippy::unused_self, reason = "self.logging_enabled is used when logs is enabled")
)]
#[cfg_attr(
not(any(feature = "logs", test)),
allow(unused_variables, reason = "consumed only by the logging path, which is compiled out here")
)]
fn record_debug_with_duration(&self, cache_name: CacheName, event: &'static str, duration: Duration) {
#[cfg(any(feature = "logs", test))]
if self.logging_enabled {
Expand All @@ -151,16 +155,16 @@ impl CacheTelemetry {
cache.duration_ns = duration.as_nanos()
);
}
#[cfg(not(any(feature = "logs", test)))]
{
let _ = (cache_name, event, duration);
}
}

#[cfg_attr(
not(feature = "logs"),
expect(clippy::unused_self, reason = "self.logging_enabled is used when logs is enabled")
)]
#[cfg_attr(
not(any(feature = "logs", test)),
allow(unused_variables, reason = "consumed only by the logging path, which is compiled out here")
)]
fn record_info_with_duration(&self, cache_name: CacheName, event: &'static str, duration: Duration) {
#[cfg(any(feature = "logs", test))]
if self.logging_enabled {
Expand All @@ -170,16 +174,16 @@ impl CacheTelemetry {
cache.duration_ns = duration.as_nanos()
);
}
#[cfg(not(any(feature = "logs", test)))]
{
let _ = (cache_name, event, duration);
}
}

#[cfg_attr(
not(feature = "logs"),
expect(clippy::unused_self, reason = "self.logging_enabled is used when logs is enabled")
)]
#[cfg_attr(
not(any(feature = "logs", test)),
allow(unused_variables, reason = "consumed only by the logging path, which is compiled out here")
)]
fn record_error_with_duration(&self, cache_name: CacheName, event: &'static str, duration: Duration) {
#[cfg(any(feature = "logs", test))]
if self.logging_enabled {
Expand All @@ -189,10 +193,6 @@ impl CacheTelemetry {
cache.duration_ns = duration.as_nanos()
);
}
#[cfg(not(any(feature = "logs", test)))]
{
let _ = (cache_name, event, duration);
}
}

pub(crate) fn record_hit(&self, tier_name: CacheName, duration: Duration, fallback: bool) {
Expand Down
2 changes: 0 additions & 2 deletions crates/fetch_hyper/src/connection/hyper_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,7 @@ mod tests {
use bytes::Bytes;
use fetch_options::{ConnectionLifetime, PoolIndex, RequestFilter};
use http::Version;
use http_body_util::BodyExt as _;
use http_extensions::{HttpBodyBuilder, HttpRequestBuilder};
use layered::Service as _;

use super::*;
use crate::HyperTransport;
Expand Down
2 changes: 1 addition & 1 deletion crates/fetch_hyper/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

#![cfg_attr(all(coverage_nightly, test), feature(coverage_attribute))]
#![cfg_attr(coverage_nightly, feature(coverage_attribute))]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![doc(html_logo_url = "https://media.githubusercontent.com/media/microsoft/oxidizer/refs/heads/main/crates/fetch_hyper/logo.png")]
#![doc(html_favicon_url = "https://media.githubusercontent.com/media/microsoft/oxidizer/refs/heads/main/crates/fetch_hyper/favicon.ico")]
Expand Down
Loading