std: `SliceIndex<str>` missing for `std::ops` ranges, so generic `R: SliceIndex<str>` bounds fail

Aperta Adatta ai principianti
#269 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust
Ambito
compilers

Direzione di ricerca

Leggi le impl esistenti di SliceIndex<str> in libs/relax/compiler/std/core/str/traits_impls.rs (righe 63, 88, 113, 138) accanto al trait StrIndex e alle sue impl in libs/relax/compiler/std/core/str/mod.rs dalla riga 219, e confronta con come il vero std copre i range ops. Poi aggiungi impl di SliceIndex<str> per i tipi di range di std::ops, delegando agli stessi controlli sui limiti che usano le impl di std::range e StrIndex. È completo quando il reproducer nell'issue compila e stampa el, e i test esistenti di indicizzazione di str continuano a passare.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Rust
Stelle
601
Fork
34
Merge medio
1h 58m
PR unite (30g)
45

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di makepad/relax

Tutte le issue di makepad/relax

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.