Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ambiguous error for slice.windows() #107437

Closed
Kuly14 opened this issue Jan 29, 2023 · 1 comment · Fixed by #107442
Closed

Ambiguous error for slice.windows() #107437

Kuly14 opened this issue Jan 29, 2023 · 1 comment · Fixed by #107442
Labels
C-bug Category: This is a bug. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@Kuly14
Copy link

Kuly14 commented Jan 29, 2023

I tried to run this code:

fn main() {
    let vec = vec![1, 2, 3, 4];
    for i in 0..vec.len() {
        for b in vec.windows(i) {
            // Do stuff
        }
    }
}

Of course this shouldn't work since you can't create windows that have 0 elements, but the problem is with the runtime error. It just panicks with this err:

thread 'main' panicked at 'size is zero', /rustc/90743e7298aca107ddaa0c202a4d3604e29bfeb6/library/core/src/slice/mod.rs:786:20
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

And it is very unclear where was the mistake.

@Kuly14 Kuly14 added the C-bug Category: This is a bug. label Jan 29, 2023
@jfrimmel
Copy link
Contributor

Maybe a #[track_caller] attribute on windows() in the standerd library would help?

@Noratrieb Noratrieb added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Jan 29, 2023
@bors bors closed this as completed in 1dbb5ef Feb 1, 2023
thomcc pushed a commit to tcdi/postgrestd that referenced this issue May 31, 2023
improve panic message for slice windows and chunks

before:
```text
thread 'main' panicked at 'size is zero', /rustc/1e225413a21fa69570bd3fefea9eb05e33f8b917/library/core/src/slice/mod.rs:809:44
```
```text
thread 'main' panicked at 'assertion failed: `(left != right)`
  left: `0`,
 right: `0`: chunks cannot have a size of zero', /rustc/1e225413a21fa69570bd3fefea9eb05e33f8b917/library/core/src/slice/mod.rs:843:9
```

after:
```text
thread 'main' panicked at 'chunk size must be non-zero', src/main.rs:4:22
```

fixes rust-lang/rust#107437
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants