MIR ICE on reference-to-reference deref coercion `as` casts (`&String as &str`, `&Arc::from("hi") as &str`)
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
- #254 di @Piping — chiusa senza merge
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
Start with the cast handling in libs/relax/types/src/typeck.rs, then trace record_cast_borrow, cast_expr in libs/relax/compiler/src/mir/build/thir/cx/expr.rs, and Coerce::DerefRef in libs/relax/compiler/src/lower.rs. Run the listed relax check and relax test reproducers first. Done means the valid shared and mutable deref casts compile and run, while the invalid casts retain the reported errors; pull request #254 is already open for this issue.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Minimal reproducer
Pure std only (edition = "2021"):
fn main() {
let s = String::from("hi");
let r: &str = &s as &str;
println!("{r}");
}
Also reproduces with open inference variables in the source or target referent, and mutable deref coercions:
use std::sync::Arc;
fn main() {
let a: &str = &Arc::from("hi") as &str;
let mut s = String::from("hi");
let ms: &mut str = &mut s as &mut str;
let v = vec![1u8, 2];
let sl: &[u8] = &v as &[_];
println!("{a} {ms} {sl:?}");
}
Actual behavior (relax check / relax test)
internal: internal compiler error while checking the borrows of repro::main: repro::main: MIR bug: ArrayToPointer cast from unexpected type &String -- Relax bug, report it
internal: internal compiler error while checking the borrows of repro::main: repro::main: MIR bug: bad assignment (&String = &str): NoSolution -- Relax bug, report it
(Same two MIR bugs for &Arc<str>, &mut String, and &Vec<u8, Global>.)
Expected behavior
Matches rustc: deref coercion as casts between references compile and execute without errors, selecting Deref::deref for shared target references and DerefMut::deref_mut for mutable target references, while invalid casts (&s as &mut str, &s as &usize) keep reporting E0605 and missing DerefMut (&mut arc as &mut str) keeps reporting E0596.
Root cause
libs/relax/types/src/typeck.rs(ExprKind::Cast): the(TyKind::Ref, TyKind::Ref)deref coercion branch calledself.set_deref_ref(x.0, derefs, None)without recording the trailingAdjust::Borrowat the target type.record_cast_borrowthen sawself.b.coerce(e.0)(Some(Coerce::DerefRef(_))) and appendedAdjust::Borrow(tm, borrow_target(source, tm))using the source reference type (e.g.&String/&Arc<str>), leavingety_adjusted(source) != expr_ty.libs/relax/types/src/mir/build/thir/cx/expr.rs(cast_expr) then fell through toelse if matches!(source_ty, TyKind::Ref(..))and emittedPointerCoercion::ArrayToPointer, causing borrowck to report both MIR ICEs.- Additionally,
(TyKind::Ref, TyKind::Ref)only deferred casts when the immediate referent wasTyKind::Infer(_), missing referents containing open inference variables (&Arc::from("hi") as &str,&v as &[_], deferred multi-step deref), andlibs/relax/compiler/src/lower.rs(Coerce::DerefRef) used the source reference's mutability rather than the target reference's mutability when choosingDerefvsDerefMut.
- 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
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di makepad/relax
-
std: `SliceIndex<str>` missing for `std::ops` ranges, so generic `R: SliceIndex<str>` bounds failAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 42/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 18/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 18/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di makepad/relax
Issue simili
-
CI/CD ignore-for-release
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
eclipse-ankaios/ankaios#844 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
symposium-dev/symposium#530 ·
I maintainer di solito rispondono entro 5 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
topgrade-rs/topgrade#2540 ·
I maintainer di solito rispondono entro 1 giorno