How to allow arbitrary expressions in format strings

I believe that the maximum complexity of Python f-string expressions is the same as allowed in lambda expressions (basically "one liners"). Rust expressions can be way more complicated:

// A single expression
{
    #[derive(Serialize)]
    struct JsonWrapper { field1: bool, field2: u32 };
    let wrap = JsonWrapper { field1: some_local_bool, field2: some_local_int };
    serde_json::to_string(wrap)
}

Is this going to be allowed in a string literal? If not, what rule do we have to hang such restrictions on? Do macros need to do anything different here?

Sure, maybe "no one" will do this, but what kinds of rules can syntax highlighting tools rely upon to not have to consider cases such as the above? How about the compiler?

8 Likes