ndarray icon indicating copy to clipboard operation
ndarray copied to clipboard

Compiler error message is unhelpful when trying `ndarray::s!([2..3])`

Open vi opened this issue 3 years ago • 0 comments
trafficstars

error[E0277]: the trait bound `[std::ops::Range<{integer}>; 1]: ndarray::SliceNextDim` is not satisfied
   --> src/tiler.rs:59:25
    |
59  |             input.slice(ndarray::s!([2..3]));
    |                         ^^^^^^^^^^^^^^^^^^^ the trait `ndarray::SliceNextDim` is not implemented for `[std::ops::Range<{integer}>; 1]`
    |
note: required by a bound in `ndarray::SliceNextDim::next_in_dim`

I type () after function-like macro call (that is not constructing a data structure sample) almost automatically and I also remember that I need array of ranges for ndarray::s!. That has resulted in s!([...]) twice already, and I spend more than a minute looking at the code, documentation and error message. The error message looks as if arrays or ranges are not OK for ndarray::s. ~~It is not obvious that the mistake is not in usage of ranges or arrays, but in usage of extra outer parentheses.~~. Although one should not use arrays when doing ndarray:s, square brackets in documentation makes it feels as if we were specifying a Rust array as input to the macro, which may result in actual Rust array being fed to it.

Maybe the macro should detect extra brackets and output more more helpful warning or error? Or at least documentation of ndarray::s should mention possible compiler error about []: SliceNextDim and tell user to look at nested brackets?

vi avatar Nov 27 '21 23:11 vi