E0020 — Effect/purity violation
A function annotated pure (or called from one) invokes a
side-effecting operation.
What triggers it
A pure function’s body (transitively) calls something with
observable side effects — I/O, mutable global state, or a builtin
tagged as effectful. The effect checker walks the call graph from
each pure function and flags the first offending call.
Minimal example
pure fn log_and_add(int a, int b) -> int {
println("adding");
return a + b;
}
Output:
scratch.rz:2:5: error[E0020]: effect violation: `println` is not pure
println("adding");
^^^^^^^^^^^^^^^^^^
Fix
Remove the side-effecting call from the pure function, or drop
the pure annotation if the effect is intentional.
fn log_and_add(int a, int b) -> int {
println("adding");
return a + b;
}
Source
Emitted from the effect-polymorphism checker in
resilient/src/effects.rs.