ref Vec[T] result pointing into a ref Vec[T] parameter lowers as &Vec<T> vs &[T] (rustc E0308)Open and answer this issue on GitHub.
ready, wip · opened 2026-10-30 · updated 2026-10-31 · 2 comments
Found by the yaml lane (y6, #1013).
enum P { Seq(Vec[P]), Leaf(i64) }
fn inner(a: ref Vec[P]) -> ref Vec[P] {
if a.len() == 1 { match a[0] { P::Seq(parts) => return parts, else => {} } }
return a
}
The parameter lowers as &[P], the result as &Vec<P>; returning the parameter reaches rustc: “Mismatched types, expected &Vec<P>”. Parameter and result of the same view type must lower to the same Rust type (both &[P], with parts as &parts[..]).
To build
ref Vec[T] result as the parameter is (&[T]), converting a field’s &Vec<T> where returned.tests/compiler/tests/.Architect, 2026-10-31: b3-1016 ended partial (patch working, but a function type fn(ref Vec[i64]) -> ref Vec[i64] needs emit_core_types.nika, outside its brief). Decided: brief b4-1016 takes emit_core_types.nika, and the nullable result ref Vec[T]? follows the same rule (Option<&[T]>, probed: it fails in rustc the same way at return a), with the nullable parameter if it still lowers as Option<&Vec<T>>.
Generated by Claude Code
Architect, 2026-10-31: b4-1016 built step 1 (6832794b: a ref Vec[T] result lowers as &[T] in functions, methods, trait methods, function types). Left, as the To build list now reads:
let (brief docs/briefs/bugs/b7-1016-named-lifetime-and-typed-let-slice.md): fn longer(a: ref Vec[i64], b: ref Vec[i64]) -> ref Vec[i64] lowers <'r>(a: &'r Vec<i64>, ..) -> &'r Vec<i64>, so a caller with a slice parameter fails (E0308); let w: ref Vec[i64] = a lowers let w: &Vec<i64> = a.fn some(a: ref Vec[i64]) -> ref Vec[i64]? { .. return a } lowers fn some(a: &[i64]) -> Option<&Vec<i64>> (E0308 at return a). A nullable parameter returned as is (Option<&Vec<T>> on both sides) runs today. Plan: ref Vec[T]? lowers Option<&[T]> on both sides, a caller’s Option<Vec<T>> lent with .as_deref() (emit_core_args.nika:45-46, emit_expr.nika:180), callers in tools hands_on, const_field_type, copied_path.The function type with two view parameters is filed apart (missing lifetime, not Vec-specific).
Generated by Claude Code