title: What is the best strategy to handle type-related warnings in macros?
body: <p>I have defined a macro to gracefully handle out-of-bounds slicing. The following is the macro's definition:</p>
  
  <pre><code>macro_rules! slice_or_else {
      ($array: expr, $to:expr, $err: block) =&gt; ({
          if $to &lt;= $array.len() {
              &amp;$array[..$to]
          }
          else $err
      })
  }
  </code></pre>
  
  <p>When I compile a function using it, the compiler complains that</p>
  
  <pre><code>warning: comparison is useless due to type limits, #[warn(unused_comparisons)] on by default
  </code></pre>
  
  <p>despite the fact that comparison is used determine whether the requested slice is valid, and that the macro passes testing. Am I missing something?  Can these warnings be turned off for macros?</p>
  
  <hr>
  
  <p><strong>Update:</strong> It appears that passing <code>0</code> as <code>$to</code> causes the problem, as Reem suggested. An example (<a href="http://is.gd/EzNUk6" rel="nofollow" title="Playpen Example">Playpen Example</a>):</p>
  
  <pre><code>fn main() {
      let a: [u8; 4] = [0, 1, 2, 3];
      assert!(slice_or_else!(a, 0, {return;}).len() == 0);
  }
  </code></pre>
  
  <p>I am using macros because I want to be able to affect the flow of the calling function.</p>
  
  <p>Since the warning is justified, what is the best strategy to deal with this use case? Binding <code>$to</code> to temporary variable? casting it explicitly? </p>