Allow mutate expressions and statements
Since https://github.com/rust-lang/rust/pull/49124, expressions and statements can be mutated if the flag stmt_expr_attributes is used.
Currently, mutagen assumes that mutations happen only on func/methods contexts. For example, there are some mutations that depends on methods_info.
We are also assuming this for the coverage information. We are prepending the static var on the beginning of the scope of a method, but we will need to think about how we will report the coverage when we will mutate single expressions or statements.
Related: 15b2e37cb1363467aa0900eda1fedaeb39ec6a1e
First, what code would we mutate here? The only things that may contain exprs outside of fns are consts, statics and [_, N] types, and the latter take only constexprs which we cannot mutate. Am I missing something?
Second, we could introduce a global method info for all extra-function mutations, if there were any. As for statements, we can add our own global static within fold_item, as it returns a SmallVector<P<Item>>.
Ah, I've now revisited the change. It means we could encounter #[mutate] attributes on statements or expressions within methods (or, unfortunately, elsewhere). For now I don't see the need to allow this. First, we'd have to explain why static FOO: u32 = #[mutate] 42; will crash. And usually people will want to mutation test a complete method or function. It rarely makes sense to choose a smaller view, unless you want to limit mutations, but in that case, I'd rather have a #[nomutate] attribute.
Sorry for not making this enough clear.
I'm ok with not allowing this, but maybe we should give some feedback to the user. As now Rust allows to annotate expressions and statements, maybe we should, somehow, raise a warning that the annotated expr/stmt won't be mutated.
What do you think?
Good idea. Our self.cx has a span_warn function that should make this a breeze. Would make for a good first issue I think.