Docs/Toolchain/Compiler Errors
Compiler Errors
What each Fid compiler error means and how to fix it: borrow, capability, effect, type, thread safety, safety annotation and security errors.
~5 min read
On this page
Each entry shows a message exactly as fid prints it, what it means, how to fix it, and the page that explains the rule. Line numbers and names in a message come from the program being compiled.
Good to know:
fid explain file.fdlists which run-time checks the compiler kept or removed, andfid check file.fdruns every check on this page without building.
Borrow and reference errors
The borrow checker found a value changed or kept while something else still refers to it.
error: borrow error in main (line 4): cannot mutate v: shared borrow(s) are active on it or its fieldsA value was changed while a shared reference to it is still used later. Fix: Move the change after the last use of the reference. See the rule.
error: borrow error in main (line 7): cannot change v while a `for` loop iterates over it: the loop would read past a resize or skip elements.A Vec was changed inside a for loop over it. Fix: Collect the changes in another Vec and apply them after the loop. See the rule.
error: borrow error in main (line 12): cannot assign to s.x: s is borrowedA field of a struct was assigned while the struct is borrowed. Fix: Assign after the last use of the reference. See the rule.
error: Reference error (line 3): in 'bad', 'bad' returns a reference to local 'x', which is freed when it returnsA function returns a reference to one of its own locals. Fix: Return the value itself, or take the storage as a parameter. See the rule.
error: Borrow error (line 7): returns a borrowed string (&str) as an owned str; the string belongs to its owner and may be freed after this returns.A borrowed string (&str) is returned where an owned str is expected. Fix: Return str_clone(s), or declare the result &str. See the rule.
Capability, effect and sandbox errors
A module or function did something it was not granted or did not declare.
Capability error: 'println()' requires 'IO' capability (not granted to module 'logger')An imported module calls a function that needs a capability the use line did not grant. Fix: Add the capability to use module with { ... }, or remove the call. See the rule.
Effect error: function 'pure_sum' has inferred effect '!IO' but only declared effects not including itA function declares fewer effects than its body (or the functions it calls) has. Fix: Add the effect to the signature, or remove the side effect. See the rule.
Sandbox error: 'print()' requires 'IO' capability -- all capabilities are revoked inside sandboxCode inside sandbox { } used a capability; all are revoked there. Fix: Move the call out of the sandbox block. See the rule.
Type errors
The type checker rejected the program.
Type error: non-exhaustive match at line 5 in main — missing variant(s): Color::BlueA match does not cover every variant of the enum. Fix: Add the missing arms, or a _ arm. See the rule.
error: Type error (line 10, in 'main'): i64 does not implement Show (required by T: Show in 'twice').A type argument does not implement the cap a generic function requires. Fix: Implement the cap for the type, or pass a type that has it. See the rule.
Thread safety errors
A value that is not @send would cross to another thread.
error: Thread safety error (line 6): argument 1 of the spawned call has type &i64, which is not @send.A reference or raw pointer is passed to a spawned call. Fix: Pass the value itself, or share it through a mutex, atomic or channel. See the rule.
Safety annotation errors
A function carries a safety annotation and its body breaks that rule.
error: Safety error (crashfree) (line 3): function 'next_reading' uses integer `+`/`-`/`*`, which panics on overflow (mark the function @wrapping for two's-complement arithmetic).A @crashfree function uses arithmetic that can overflow and panic. Fix: Use checked arithmetic, or mark the function @wrapping if wrap-around is intended. See the rule.
error: Safety error (safety-annotated): function 'collect' is @no-alloc but calls 'Vec_new'.A @no-alloc function calls something that allocates. Fix: Take the buffer as a parameter instead of creating it. See the rule.
error: Safety error (safety-annotated): function 'collect' is @no-alloc but uses .push(), which allocates.A @no-alloc function uses a method that allocates, such as .push(). Fix: Use a fixed-size array or a buffer passed in. See the rule.
error: Safety error (safety-critical): function 'run' is @no-indirect but calls its parameter 'f', a function value.A @no-indirect function calls through a function value. Fix: Call the function by name. See the rule.
error: Linear type error (line 9): variable 't' was already consumed (moved).A @linear value was used a second time. Fix: Use the value exactly once; pass the result on instead of the original. See the rule.
error: Safety error (line 6): calling the C function c_sqrt() needs an `unsafe` block.A C function was called outside an unsafe block. Fix: Wrap the call in unsafe { }; fid audit will list it. See the rule.
Security errors
Secret or personal data would reach a place it must not.
error: Security error (@secret) (line 2): in 'check', a secret value reaches output 'println'A @secret value reaches output. Fix: Do not print it; hash or compare it in a @secret function. See the rule.
error: Security error (@secret) (line 3): in 'check', returns a secret value; mark the function @secret (callers keep its result secret) or @declassify (an audited release)A function returns a secret without being marked. Fix: Mark the function @secret, or @declassify if the release is audited. See the rule.
error: Security error (@sensitive) (line 2): in 'send_analytics', a sensitive value reaches output 'println'; release it through privacy::release (a consent check) or mark the function @declassifyA @sensitive value reaches output without a consent check. Fix: Release it through privacy::release. See the rule.
error: Security error (constant_time) (line 3): function 'same' has an early return.A @constant_time function returns early. Fix: Compute the whole result, then return once. See the rule.
error: Security error (constant_time) (line 3): function 'same' branches on secret data (`if`).A @constant_time function branches on secret data. Fix: Replace the if with arithmetic on the secret. See the rule.