E0496: Inout str requires local buffer
| Code | Category | Stability |
|---|---|---|
E0496 | Struct and enum | Permanent |
Explanation
An inout str parameter is an exclusive view into caller-owned mutable string storage, so its operand must have local-buffer provenance from StrBuf or Str(N). A first-class str is static-backed, immutable, and copyable; granting exclusive access could write read-only memory and cannot establish unique ownership.
Likely cause
A first-class str, usually a string literal or str binding, is passed with inout. Use borrow str when only reading static text, or copy the content into a local StrBuf or Str(N) before requesting an exclusive view.
Examples
Request an exclusive view of static str
fn length(inout value: str) -> u64 { value.len() }
fn main() -> i32 {
let mut value: str = "hello";
@intCast(length(inout value))
}
Use a local buffer for an exclusive view
fn length(inout value: str) -> u64 { value.len() }
fn main() -> i32 {
let mut value: Str(8) = "hello";
@intCast(length(inout value))
}