Skip to content

Commit

Permalink
attributes: suppress dead code warnings for compile tests (#2322)
Browse files Browse the repository at this point in the history
The `async_fn` test file in `tracing-attributes` contains several
functions that exist just to test whether they _compile_, rather than
make assertions about their behavior. Because these functions are never
called, they (naturally) emit dead code warnings.

This commit adds `#[allow(dead_code)]` to the compilation tests, plus a
comment explaining why we do this.
  • Loading branch information
hawkw committed Sep 24, 2022
1 parent 640cd3f commit b740179
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tracing-attributes/tests/async_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ async fn test_async_fn(polls: usize) -> Result<(), ()> {

// Reproduces a compile error when returning an `impl Trait` from an
// instrumented async fn (see https://github.com/tokio-rs/tracing/issues/1615)
#[allow(dead_code)] // this is just here to test whether it compiles.
#[instrument]
async fn test_ret_impl_trait(n: i32) -> Result<impl Iterator<Item = i32>, ()> {
let n = n;
Expand All @@ -22,6 +23,7 @@ async fn test_ret_impl_trait(n: i32) -> Result<impl Iterator<Item = i32>, ()> {

// Reproduces a compile error when returning an `impl Trait` from an
// instrumented async fn (see https://github.com/tokio-rs/tracing/issues/1615)
#[allow(dead_code)] // this is just here to test whether it compiles.
#[instrument(err)]
async fn test_ret_impl_trait_err(n: i32) -> Result<impl Iterator<Item = i32>, &'static str> {
Ok((0..10).filter(move |x| *x < n))
Expand Down Expand Up @@ -53,6 +55,7 @@ async fn repro_1613_2() {
}

// Reproduces https://github.com/tokio-rs/tracing/issues/1831
#[allow(dead_code)] // this is just here to test whether it compiles.
#[instrument]
#[deny(unused_braces)]
fn repro_1831() -> Pin<Box<dyn Future<Output = ()>>> {
Expand All @@ -61,6 +64,7 @@ fn repro_1831() -> Pin<Box<dyn Future<Output = ()>>> {

// This replicates the pattern used to implement async trait methods on nightly using the
// `type_alias_impl_trait` feature
#[allow(dead_code)] // this is just here to test whether it compiles.
#[instrument(ret, err)]
#[deny(unused_braces)]
#[allow(clippy::manual_async_fn)]
Expand Down

0 comments on commit b740179

Please sign in to comment.