-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.Diagnostics: Confusing error or lint; hard to understand for new users.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
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.1Anything else?
No response
Scripter17 and IoaNNUwU
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.Diagnostics: Confusing error or lint; hard to understand for new users.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.