Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Appendix B: Diagnostics you will meet

Every diagnostic has a stable name. Static means the program is rejected before it runs; dynamic means a check failed while it ran and the program stopped; both means the same rule is applied statically where the text shows the problem and dynamically where only the values can. coby --explain prog.cb prints the full registry entry for any of them, and the specification’s registry under spec/registry/ lists them all. These are the ones a newcomer sees most.

DiagnosticWhenWhat it means, and the usual fix
diag.syntax-errorstaticThe text is not a program. The message names what was expected.
diag.unbound-namestaticNothing has this name. Check the spelling, declare it, or import std;.
diag.ambiguous-namestaticTwo imports supply the name. Qualify it, m::name.
diag.name-not-visiblestaticThe item or field is private to its module. Export it, or go through the module’s functions.
diag.type-mismatchstaticThe types differ and nothing converts. Convert with widen, narrow or to_float, or fix the type. Also a printf specifier that does not match its argument.
diag.cannot-infer-type-parameterstaticauto v = Vec::new(); and the like. Write the type on the left.
diag.use-of-uninitializedstaticA variable is read on some path before it is written. Assign on every path.
diag.duplicate-localstaticA name declared twice in one block. Assign to it, or use another name.
diag.literal-out-of-rangestaticA literal does not fit its type, 256: u8.
diag.arith-overflowboth+, - or * left the type’s range. Widen, or use wrapping_, saturating_ or checked_.
diag.div-by-zerobothDivision or remainder by zero. Test first, or checked_div.
diag.narrowing-overflowbothnarrow to a type the value does not fit.
diag.index-out-of-boundsbothAn index at or past the length.
diag.stale-bindingbothA name used after its value moved or was dropped, or a reference used after its target ended. Use the new owner, or give the name a new value.
diag.aliasing-conflictbothAn access while a conflicting reference is live: a write under a reader, a second reference beside an exclusive one, a push while an element reference lives, a spawner using what it lent a thread. End the earlier borrow first.
diag.write-through-sharedstaticA write through ref<T, shared>. Take ref<T, exclusive>, or put the value in a mutex.
diag.move-while-aliased, diag.destroy-while-aliasedbothA resource moved or dropped while a reference to it lives.
diag.reference-escapes-scopestaticA reference to a local returned or stored outside its block. Return the value.
diag.lifetime-elision-ambiguousstaticA function with two reference parameters returns a reference. Return an owned value.
diag.read-of-resourcestaticA resource where a copy would be made, such as == on two vectors. Borrow it, or use slice_eq.
diag.move-out-of-fieldstaticA resource field moved out of a struct that lives on. Move the whole struct, or destructure it.
diag.overwrite-of-live-resourcebothAn assignment over a resource whose destruction matters. overwrite, replace, or drop first.
diag.non-exhaustive-matchstaticA variant has no arm. Add it, or _.
diag.unreachable-armstaticAn arm no value can reach, such as a repeated literal.
diag.result-discardedstaticA Result computed and not used. Handle it, or _ = e;.
diag.propagate-outside-fallible-contextstatic? in a function that does not return a matching Result or Option.
diag.unwrap-faileddynamicunwrap or expect on None or Err.
diag.assert-faileddynamicAn assert whose condition was false.
diag.static-assert-failedstaticA static_assert whose condition was false.
diag.capture-list-mismatchstaticA closure’s brackets do not list exactly the outer names its body uses.
diag.unbounded-type-parameterstaticAn operator on a T with no bound that gives it. Add : ordered, : number, or pass the operation in.
diag.spawn-borrow-closurestaticA closure that borrows locals passed to spawn. Use move.
diag.mutex-reentrant-lockdynamicA thread locked a mutex it already holds.
diag.mutex-poisoneddynamicA thread faulted while holding this mutex.
diag.deadlock, diag.channel-deadlockdynamicA wait that nothing can end.
diag.thread-cancelleddynamicThe thread was asked to stop; its waiter sees it through try_join.
diag.trusted-outside-unsafestaticA raw-pointer or extern operation outside an unsafe block.
diag.extern-non-ffi-typestaticAn extern fn with a type C cannot take. Use scalars, raw pointers and plain structs.
diag.recursive-typestaticA struct that contains itself directly. Put a Box between.
diag.no-mainstaticNo fn main() at the root, or one with parameters or the wrong return type.

A message beginning internal error in coby: or cobc: is a bug in the tool, not in your program. It exits with status 4; please report it with the program that caused it.