Skip to content

Commit

Permalink
Avoid dead_code warnings in test
Browse files Browse the repository at this point in the history
    warning: trait `UnsafeTraitPubCrate` is never used
       --> tests/test.rs:160:25
        |
    160 | pub(crate) unsafe trait UnsafeTraitPubCrate {}
        |                         ^^^^^^^^^^^^^^^^^^^
        |
        = note: `#[warn(dead_code)]` on by default

    warning: trait `UnsafeTraitPrivate` is never used
       --> tests/test.rs:163:14
        |
    163 | unsafe trait UnsafeTraitPrivate {}
        |              ^^^^^^^^^^^^^^^^^^

    warning: trait `CanDestruct` is never used
       --> tests/test.rs:167:11
        |
    167 |     trait CanDestruct {
        |           ^^^^^^^^^^^

    warning: trait `Trait` is never used
       --> tests/test.rs:184:11
        |
    184 |     trait Trait {
        |           ^^^^^

    warning: trait `Trait` is never used
       --> tests/test.rs:206:15
        |
    206 |     pub trait Trait {
        |               ^^^^^

    warning: trait `Trait` is never used
       --> tests/test.rs:231:15
        |
    231 |     pub trait Trait {
        |               ^^^^^

    warning: trait `Issue1` is never used
       --> tests/test.rs:243:11
        |
    243 |     trait Issue1 {
        |           ^^^^^^

    warning: trait `Issue11` is never used
       --> tests/test.rs:287:11
        |
    287 |     trait Issue11 {
        |           ^^^^^^^

    warning: struct `Struct` is never constructed
       --> tests/test.rs:291:12
        |
    291 |     struct Struct;
        |            ^^^^^^

    warning: trait `Trait` is never used
       --> tests/test.rs:304:11
        |
    304 |     trait Trait {}
        |           ^^^^^

    warning: trait `Issue15` is never used
       --> tests/test.rs:307:11
        |
    307 |     trait Issue15 {
        |           ^^^^^^^

    warning: trait `Issue17` is never used
       --> tests/test.rs:317:11
        |
    317 |     trait Issue17 {
        |           ^^^^^^^

    warning: struct `Struct` is never constructed
       --> tests/test.rs:321:12
        |
    321 |     struct Struct {
        |            ^^^^^^

    warning: struct `Str` is never constructed
       --> tests/test.rs:412:12
        |
    412 |     struct Str<'a>(&'a str);
        |            ^^^

    warning: trait `Trait1` is never used
       --> tests/test.rs:415:11
        |
    415 |     trait Trait1<'a> {
        |           ^^^^^^

    warning: trait `Trait2` is never used
       --> tests/test.rs:430:11
        |
    430 |     trait Trait2 {
        |           ^^^^^^

    warning: trait `Trait3` is never used
       --> tests/test.rs:440:11
        |
    440 |     trait Trait3<'a, 'b> {
        |           ^^^^^^

    warning: trait `Trait` is never used
       --> tests/test.rs:870:11
        |
    870 |     trait Trait {
        |           ^^^^^

    warning: trait `T1` is never used
        --> tests/test.rs:1006:11
         |
    1006 |     trait T1 {
         |           ^^

    warning: struct `Foo` is never constructed
        --> tests/test.rs:1021:12
         |
    1021 |     struct Foo;
         |            ^^^

    warning: trait `Trait` is never used
        --> tests/test.rs:1085:11
         |
    1085 |     trait Trait {
         |           ^^^^^

    warning: trait `Trait` is never used
        --> tests/test.rs:1100:11
         |
    1100 |     trait Trait<T = ()> {
         |           ^^^^^

    warning: trait `TestTrait` is never used
        --> tests/test.rs:1140:11
         |
    1140 |     trait TestTrait {
         |           ^^^^^^^^^

    warning: trait `Trait` is never used
        --> tests/test.rs:1287:11
         |
    1287 |     trait Trait {
         |           ^^^^^

    warning: struct `Struct` is never constructed
        --> tests/test.rs:1293:12
         |
    1293 |     struct Struct;
         |            ^^^^^^

    warning: trait `Foo` is never used
        --> tests/test.rs:1402:11
         |
    1402 |     trait Foo {
         |           ^^^
  • Loading branch information
dtolnay committed Feb 8, 2024
1 parent db5bfa5 commit 52836cf
Showing 1 changed file with 36 additions and 20 deletions.
56 changes: 36 additions & 20 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,11 @@ pub unsafe trait UnsafeTrait {}
unsafe impl UnsafeTrait for () {}

#[async_trait]
#[allow(dead_code)]
pub(crate) unsafe trait UnsafeTraitPubCrate {}

#[async_trait]
#[allow(dead_code)]
unsafe trait UnsafeTraitPrivate {}

pub async fn test_can_destruct() {
Expand All @@ -177,6 +179,8 @@ pub async fn test_can_destruct() {
let _d: u8 = d;
}
}

let _ = <Struct as CanDestruct>::f;
}

pub async fn test_self_in_macro() {
Expand All @@ -199,6 +203,10 @@ pub async fn test_self_in_macro() {
println!("{}", self);
}
}

let _ = <String as Trait>::a;
let _ = <String as Trait>::b;
let _ = <String as Trait>::c;
}

pub async fn test_inference() {
Expand All @@ -208,6 +216,10 @@ pub async fn test_inference() {
Box::new(std::iter::empty())
}
}

impl Trait for () {}

let _ = <() as Trait>::f;
}

pub async fn test_internal_items() {
Expand All @@ -233,14 +245,18 @@ pub async fn test_unimplemented() {
unimplemented!()
}
}

impl Trait for () {}

let _ = <() as Trait>::f;
}

// https://github.com/dtolnay/async-trait/issues/1
pub mod issue1 {
use async_trait::async_trait;

#[async_trait]
trait Issue1 {
pub trait Issue1 {
async fn f<U>(&self);
}

Expand Down Expand Up @@ -284,11 +300,11 @@ pub mod issue11 {
use std::sync::Arc;

#[async_trait]
trait Issue11 {
pub trait Issue11 {
async fn example(self: Arc<Self>);
}

struct Struct;
pub struct Struct;

#[async_trait]
impl Issue11 for Struct {
Expand All @@ -301,10 +317,10 @@ pub mod issue15 {
use async_trait::async_trait;
use std::marker::PhantomData;

trait Trait {}
pub trait Trait {}

#[async_trait]
trait Issue15 {
pub trait Issue15 {
async fn myfn(&self, _: PhantomData<dyn Trait + Send>) {}
}
}
Expand All @@ -314,11 +330,11 @@ pub mod issue17 {
use async_trait::async_trait;

#[async_trait]
trait Issue17 {
pub trait Issue17 {
async fn f(&self);
}

struct Struct {
pub struct Struct {
string: String,
}

Expand Down Expand Up @@ -409,10 +425,10 @@ pub mod issue25 {
pub mod issue28 {
use async_trait::async_trait;

struct Str<'a>(&'a str);
pub struct Str<'a>(&'a str);

#[async_trait]
trait Trait1<'a> {
pub trait Trait1<'a> {
async fn f(x: Str<'a>) -> &'a str;
async fn g(x: Str<'a>) -> &'a str {
x.0
Expand All @@ -427,7 +443,7 @@ pub mod issue28 {
}

#[async_trait]
trait Trait2 {
pub trait Trait2 {
async fn f();
}

Expand All @@ -437,7 +453,7 @@ pub mod issue28 {
}

#[async_trait]
trait Trait3<'a, 'b> {
pub trait Trait3<'a, 'b> {
async fn f(_: &'a &'b ()); // chain 'a and 'b
async fn g(_: &'b ()); // chain 'b only
async fn h(); // do not chain
Expand Down Expand Up @@ -867,7 +883,7 @@ pub mod issue89 {
use async_trait::async_trait;

#[async_trait]
trait Trait {
pub trait Trait {
async fn f(&self);
}

Expand Down Expand Up @@ -1003,7 +1019,7 @@ pub mod issue104 {
use async_trait::async_trait;

#[async_trait]
trait T1 {
pub trait T1 {
async fn id(&self) -> i32;
}

Expand All @@ -1018,7 +1034,7 @@ pub mod issue104 {
};
}

struct Foo;
pub struct Foo;

impl_t1!(Foo, 1);
}
Expand Down Expand Up @@ -1082,7 +1098,7 @@ pub mod issue120 {
use async_trait::async_trait;

#[async_trait]
trait Trait {
pub trait Trait {
async fn f(&self);
}

Expand All @@ -1097,7 +1113,7 @@ pub mod issue123 {
use async_trait::async_trait;

#[async_trait]
trait Trait<T = ()> {
pub trait Trait<T = ()> {
async fn f(&self) -> &str
where
T: 'async_trait,
Expand Down Expand Up @@ -1137,7 +1153,7 @@ pub mod issue134 {
use async_trait::async_trait;

#[async_trait]
trait TestTrait {
pub trait TestTrait {
async fn run<const DUMMY: bool>(self)
where
Self: Sized,
Expand Down Expand Up @@ -1284,13 +1300,13 @@ pub mod issue152 {
use async_trait::async_trait;

#[async_trait]
trait Trait {
pub trait Trait {
type Assoc;

async fn f(&self) -> Self::Assoc;
}

struct Struct;
pub struct Struct;

#[async_trait]
impl Trait for Struct {
Expand Down Expand Up @@ -1399,7 +1415,7 @@ pub mod issue183 {
use async_trait::async_trait;

#[async_trait]
trait Foo {
pub trait Foo {
async fn foo(_n: i32) {}
}
}
Expand Down

0 comments on commit 52836cf

Please sign in to comment.