rust-lang / rust-lang/rust

Suggest removing `[]` for array of 1 `RangeBounds` arguments.

Open
#147,944 1 comment 2 reactions 1 assignee View on GitHub

@IoaNNUwU is already working on this.

Since Oct 21, 2025.

A-diagnostics D-newcomer-roadblock T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code
fn main() {
    let mut vec = vec![1, 2, 3];
    vec.drain([..3]);
}
Current output
error[E0277]: the trait bound `[RangeTo<{integer}>; 1]: RangeBounds<usize>` is not satisfied
    --> src\main.rs:5:15
     |
5    |     vec.drain([..3]);
     |         ----- ^^^^^ the trait `RangeBounds<usize>` is not implemented for `[RangeTo<{integer}>; 1]`
     |         |
     |         required by a bound introduced by this call
     |
note: required by a bound in `Vec::<T, A>::drain`
    --> C:\Users\ioann\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib/rustlib/src/rust\library\alloc\src\vec\mod.rs:2665:12
     |
2663 |     pub fn drain<R>(&mut self, range: R) -> Drain<'_, T, A>
     |            ----- required by a bound in this associated function
2664 |     where
2665 |         R: RangeBounds<usize>,
     |            ^^^^^^^^^^^^^^^^^^ required by this bound in `Vec::<T, A>::drain`
Desired output
`[..3]` is an array of 1 range. Consider removing `[]`.
Rationale and extra context

It's not obvious from the error message why trait bound wasn't satisfied. Rust compiler should probably highlight the fact that [..3] is an array of 1 range, not a range.

Second option may be to impl RangeBounds<T> for [ impl RangeBounds<T> ; 1 ].

Other cases

Rust Version
rustc 1.92.0-nightly (a9d0a6f15 2025-09-16)
binary: rustc
commit-hash: a9d0a6f15533a364816c4d81e2192009ef601d33
commit-date: 2025-09-16
host: x86_64-pc-windows-msvc
release: 1.92.0-nightly
LLVM version: 21.1.1
Anything else?

No response

Contributor guide

Open the contributing guide

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.