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

Open
#1,122 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
rust
Domain
compilers

Research direction

Start with the ndarray::s! macro and the failing call shown at src/tiler.rs:59. Reproduce the compiler diagnostic for ndarray::s!([2..3]), then inspect the macro documentation and determine whether the finished change should provide a clearer diagnostic or explain the nested-bracket mistake in the documentation.

Written by the indexing model from the issue text.

Description

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?

Dominant language
Rust
Stars
4.3k
Forks
391
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from rust-ndarray/ndarray

All issues in rust-ndarray/ndarray

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.