title: Is it possible to have conditional trait inheritance (such as Send + Sync) using feature flags?
body: <p>In a library one may want to restrict implementations of a trait to be thread safe based on a feature flag. This sometimes involves changing trait inheritance. However, attributes are not allowed on the trait inheritance bounds. A common workaround is to copy the trait:</p>
  
  <pre class="lang-rust prettyprint-override"><code>#[cfg(not(feature = "thread_safe"))]
  pub trait MyTrait {
      fn foo();
  }
  
  #[cfg(feature = "thread_safe")]
  pub trait MyTrait: Send + Sync {
      fn foo();
  }
  </code></pre>
  
  <p>The duplicated code can be mitigated by using a macro (see below), but this can make the IDE experience suffer. Is there a better way to achieve conditional trait inheritance?</p>
  
  <pre class="lang-rust prettyprint-override"><code>macro_rules! my_trait {
      ($($bounds:ident),*) =&gt; {
          pub trait MyTrait where $(Self: $bounds),* {
              fn foo();
          }
      };
  }
  
  #[cfg(not(feature = "thread_safe"))]
  my_trait!();
  #[cfg(feature = "thread_safe")]
  my_trait!(Send, Sync);
  </code></pre>