stabilize cfg_select! by folkertdev · Pull Request #149783 · rust-lang/rust (original) (raw)

Is there a detailed description of how this macro works? For example:

Not yet, I think.

What is the grammar that it accepts?

In item positions the body should consist of zero or more

('_' | ConfugurationPredicate) => { TokenTree }

In expression position we additionally accept

('_' | ConfugurationPredicate) => Expr,

How does it expand? For example, it seems like if the RHS uses braces, the braces are implicitly removed.

That is correct, one level of braces is removed if braces are used.

Am I correct that whether or not this fails to compile depends on the current cfg's for the current target/environment? That is, there is essentially an implicit _ => {compile_error!()} as the last rule?

Yes if none of the conditions evaluate to true you'll get a compile error (note: earlier iterations did not have this default behavior)

Is it correct that this did not suffer the same fate as assert_matches because the name cfg_select is not in use by any known libraries? (Just curious, cfg_select has already been in the prelude for a while and nobody complained.)

The ecosystem mostly uses cfg_if. But I'll defer to T-libs-api on whether this is exported from all the right places.

Is there a reason the unreachable predicate warning isn't a lint? (The main reason I ask is because this prevents -D warnings from catching it.)

I don't think there is a reason. We could make it a lint (or add it to an existing one?)

Am I correct that the RHS is not parsed unless it is the arm that is selected? That is, the right hand side can contain any token tree?

Yes, the rhs can be any token tree.