safe_goto!() { /* proc-macro */ }
Expand description
Executes the contained Rust code with possibly irreducible control flow
§Example
use safe_goto::safe_goto;
safe_goto!{
begin() {
goto s1(3)
},
s1(n: i32) {
n + 1
}
};
The invocation above generates the following code:
'outer_goto: {
enum States {
S1(i32)
}
let mut goto: States = 'goto: {
let break_val = {break 'goto States::S1(3)};
break 'outer_goto break_val;
};
'goto: loop {
let ret = match goto {
States::S1(n) => {
n + 1
}
};
break ret;
}
};
There must be a begin block with no arguments. The begin block cannot be a target of a goto, but can be used for one-time moves. Nested safe_goto’s are not allowed, though function calls can be used to get around this limitation. Execution that exits any of the goto blocks will return from the macro with the value at the end of the final block executed.
§Safety
The macro does not generate unsafe code unless given unsafe code as input. There are no guarantees for how the macro will interact with unsafe code.