diag: guide parameter mutability and explicit array slice arguments
This commit is contained in:
1 parent
6a02659f31
commit
9549a3dec6
22 files changed
+197
-4
No files matched your search
@@ -127,6 +127,8 @@ These stable kinds use spec 10 §3. `hint` MUST equal the registered text. Alter
|
||||
| `borrow_binding` | E7001 | Bind a borrow with `ref name = place;` or `mut name = place;`, rather than a let/var initializer. | none |
|
||||
| `zero_storage` | E7001 | `zero` is only a whole var initializer: `var name: T = zero;`; T must be zeroable. | none |
|
||||
| `numeric_cast_modes` | E7005 | 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. | operator |
|
||||
| `parameter_mutability` | E7001 | 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. | none |
|
||||
| `array_slice_argument` | E7005 | 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. | prefix |
|
||||
|
||||
Closed applicability:
|
||||
|
||||
@@ -137,6 +139,8 @@ Closed applicability:
|
||||
- Borrow kinds: `&` rejected as the first token of a call argument, excluding enum variant payloads (`borrow_argument`) or let/typed-var initializer (`borrow_binding`). Other expression contexts, including the second `&` in `a && b`, have no borrow advice. For an argument whose following token is an ordinary identifier, emit `["ref"]`; for `&mut` followed by an ordinary identifier, emit `["mut"]`. Other operands have hint only, including `&&x`. These prefixes do not imply that the referent/mode verifies; binding advice has no prefix alternative.
|
||||
- `zero_storage`: keyword `zero` rejected at primary-expression start. Accepted typed-var zero initialization has no advice.
|
||||
- `numeric_cast_modes`: integer `as` rejected by the lossless-widening rule, with unchanged `from`/`to`. Alternatives MUST be `["as!", "as%"]`. Non-integer casts and other E7005 rules have no such candidate.
|
||||
- `parameter_mutability`: `mut` rejected where a function parameter name is required, immediately followed by an ordinary identifier and `:`. Hint only: value storage and an exclusive borrow have different ownership contracts. Other malformed parameter prefixes and incomplete `mut` spellings have no such advice.
|
||||
- `array_slice_argument`: ordinary function-call argument type mismatch for a bare named, non-linear array whose element type equals the expected `slice<T>` or `slice_mut<T>` element type. Alternatives MUST be `["ref"]` for a shared slice and `["mut"]` for an exclusive slice. This is an explicit borrow prefix, not an implicit conversion or a guarantee that the place/loan verifies. Excludes other element types, array expressions/projections, existing borrow arguments, bindings/returns, intrinsics and task spawning (which requires a retained named loan). Earlier name/move/operand errors retain priority. The same rule applies to explicitly specialized generic/static functions and imported ordinary calls.
|
||||
|
||||
## E7006 reasons
|
||||
|
||||
|
||||
Reference in new issue
Block a user