std: `SliceIndex<str>` missing for `std::ops` ranges, so generic `R: SliceIndex<str>` bounds fail
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
Research direction
Read the existing SliceIndex<str> impls in libs/relax/compiler/std/core/str/traits_impls.rs (lines 63, 88, 113, 138) next to the StrIndex trait and its impls in libs/relax/compiler/std/core/str/mod.rs from line 219, and compare with how real std covers ops ranges. Then add SliceIndex<str> impls for the std::ops range types, delegating to the same boundary checks the std::range impls and StrIndex use. Done looks like the reproducer in the issue compiling and printing el, plus the existing str indexing tests still passing.
Written by the indexing model from the issue text.
Description
On Relax 953d174a (macOS arm64), a generic bound on SliceIndex<str> fails for std::ops range types, although direct indexing works.
Reproduce
Cargo.toml
[package]
name = "repro-sliceindex"
version = "0.1.0"
edition = "2024"
[workspace]
src/main.rs
use std::slice::SliceIndex;
fn text_slice<R: SliceIndex<str, Output = str>>(s: &str, r: R) -> &str {
s.get(r).unwrap_or("")
}
fn main() {
let r: std::ops::Range<usize> = 1..3;
println!("{}", text_slice("hello", r));
}
Expected: prints el under rustc 1.100 (and edition 2021 behaves the same).
Actual:
src/main.rs:10:20: E0277: the trait bound `Range<usize>: SliceIndex<str>` is not satisfied
&"hello"[1..3] works, so indexing itself is fine; the trait bound is not.
Where it points
Relax std implements SliceIndex<str> only for the new std::range types:
libs/relax/compiler/std/core/str/traits_impls.rs:63(crate::range::Range<usize>),:88(RangeInclusive),:113(RangeFrom),:138(RangeToInclusive).
The std::ops range types take the separate StrIndex trait instead (libs/relax/compiler/std/core/str/mod.rs:219 and following), which is what the indexing operator uses. Real std has impl SliceIndex<str> for ops::Range<usize> and the other ops ranges.
This breaks any generic API bounded on SliceIndex<str>; it shows up in a vendored text-area widget whose fn text_slice<R: SliceIndex<str, Output = str>>(...) is called with 1..3.
Fix: add the SliceIndex<str> impls for the ops range types, delegating to the same boundary checks / StrIndex methods.
- Dominant language
- Rust
- Stars
- 601
- Forks
- 34
- Avg merge
- 1h 58m
- Merged PRs (30d)
- 45
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from makepad/relax
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 42/100
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 18/100
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 18/100
Maintainers usually reply within 1 day
-
Relax live tests rerun the whole suite after a one-line body editMay be free again A pull request for this issue was closed without being merged. Open
Difficulty 4/5 3-5 days Newbie friendliness 32/100
Maintainers usually reply within 1 day
Similar issues
-
CI/CD ignore-for-release
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
eclipse-ankaios/ankaios#844 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
symposium-dev/symposium#530 ·
Maintainers usually reply within 5 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
topgrade-rs/topgrade#2540 ·
Maintainers usually reply within 1 day