0
use tokio::io::AsyncWrite;

pub enum Out<'a, T>
where
    T: AsyncWrite + Unpin,
{
    V(Bar<'a, T>),
}

pub struct Bar<'a, T: AsyncWrite + Unpin> {
    tx: &'a mut T,
}

trait Foo<'m, T: AsyncWrite + Unpin> {
    fn foo(&mut self, m: &u8) -> Result<Out<'m, T>, ()>;
}

struct Inner2<'m, T, S>
where
    T: AsyncWrite + Unpin,
    S: Foo<'m, T>,
{
    response_sender: S,
    _t: std::marker::PhantomData<T>,
}

Here's the playground

error[E0392]: parameter `'m` is never used
  --> src/lib.rs:18:15
   |
18 | struct Inner2<'m, T, S>
   |               ^^ unused parameter
   |
   = help: consider removing `'m`, referring to it in a field, or using a marker such as `std::marker::PhantomData`
Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
user855
  • 19,048
  • 38
  • 98
  • 162
  • [The duplicate applied to your situation](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=d2e4e5fc579bf2edb6d7b2b03d88f47d), or [applied a different way](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=a6510c1dcbbdd251fd9be8a1d9837138) or don't place the trait bound on the struct but only the *function* that needs it. – Shepmaster Nov 15 '20 at 17:17
  • Both solutions achieve different effect right? What does <&'m ()> mean in 2nd solution? What is it doing? @Shepmaster – user855 Nov 15 '20 at 21:15
  • *achieve different effect* — Yes, all three solutions have different effects. [How does for<> syntax differ from a regular lifetime bound?](https://stackoverflow.com/q/35592750/155423). *What does <&'m ()> mean* — It means the same conceptual thing as the `PhantomData` you are already using: "tell the compiler to treat this type as if it contained a reference to a value with lifetime `'m`". – Shepmaster Nov 16 '20 at 01:37

0 Answers0