E0495: Buffer not first class str
| Code | Category | Stability |
|---|---|---|
E0495 | Struct and enum | Permanent |
Explanation
StrBuf and Str(N) own mutable string storage, while first-class str values are static-backed and may freely escape. Treating a buffer as first-class str could leave a copied view pointing at storage after its owner is dropped, so buffers coerce only to second-class borrow str or inout str views.
Likely cause
A string buffer is passed to a bare str parameter, returned as str, or stored in a str binding or field. Use borrow str for read-only access, inout str for exclusive local-buffer access, or keep the owning buffer type across the boundary.
Examples
Pass a buffer as first-class str
fn length(value: str) -> u64 { value.len() }
fn main() -> i32 {
let value: Str(8) = "hello";
@intCast(length(value))
}
Borrow the buffer for string access
fn length(borrow value: str) -> u64 { value.len() }
fn main() -> i32 {
let value: Str(8) = "hello";
@intCast(length(borrow value))
}