diag: guide parameter mutability and explicit array slice arguments

This commit is contained in:
dev committed 2026-10-09 21:12:26 +03:00
1 parent 6a02659f31
commit 9549a3dec6
22 files changed
+197 -4

No files matched your search

+9 -2
View File
@@ -198,6 +198,8 @@ pub const SourceRepairKind = enum {
borrow_binding,
zero_storage,
numeric_cast_modes,
parameter_mutability,
array_slice_argument,
pub fn hint(kind: SourceRepairKind) []const u8 {
return switch (kind) {
@@ -210,17 +212,22 @@ pub const SourceRepairKind = enum {
.borrow_binding => "Bind a borrow with `ref name = place;` or `mut name = place;`, rather than a let/var initializer.",
.zero_storage => "`zero` is only a whole var initializer: `var name: T = zero;`; T must be zeroable.",
.numeric_cast_modes => "The target-independent `as` rule excludes `usize`/`isize`, even when the value fits. Choose `as!` for a checked conversion (T0006 on overflow) or `as%` for a wrapping conversion.",
.parameter_mutability => "Write `name: T` for a value parameter; use a local `var` for mutable storage, or `name: mut<T>` for an exclusive borrowed parameter. Choose the intended ownership contract.",
.array_slice_argument => "Pass an array as an explicit borrow: `ref array` for `slice<T>` or `mut array` for `slice_mut<T>`. The place and loan must still verify.",
};
}
pub fn code(kind: SourceRepairKind) []const u8 {
return if (kind == .numeric_cast_modes) "E7005" else "E7001";
return switch (kind) {
.numeric_cast_modes, .array_slice_argument => "E7005",
else => "E7001",
};
}
pub fn unit(kind: SourceRepairKind) []const u8 {
return switch (kind) {
.slice_mut_type, .slice_ref_type => "complete type",
.borrow_argument => "prefix",
.borrow_argument, .array_slice_argument => "prefix",
.numeric_cast_modes => "operator",
else => "none",
};