Removing an expression is (not) supported issue


I don'tt know what's the difference between these, i think this is an issue

1 Like

The issue here is parsing priorities when parsing expression attributes.

In the first case the attribute is only applied to current_subject_id, not the whole assignment.
So when cfg applies you get something like /* nothing */ = LessonId(String::from("12522"));, which is an error.

This is something that should be changed in my opinion (that would make behavior more consistent with attributes in other contexts, and less confusing).
This thing is actually the only blocker for stabilizing expression attributes (of which I'm aware at least).


I would suggest always putting whatever you're attributing into a block when possible, to make it clearer for humans too.

(Not taking a position on whether the current behaviour is correct or should be changed.)

The expression attribute should then always apply to the whole statement when involving assignments? I'm asking for situations like #[cfg(false)] * = baz();

It does seem like it might not be a one way door to support the base case shown here and leave the door open for more complex parse cases.

I guess if you wanted to apply attribute to the place expression, you should write

(#[attr] * = baz();

Just like #[attr] f(x) should apply to the whole expression, and if you want to apply attribute to f, you should write (#[attr] f)(x).

Not that is looks like a common case.

1 Like

If expression attributes interacting with parentheses were to be a thing, then I think it would be better written with an inner attribute specifically,

(#![attr] * = baz();

because that way, precedence is “obviously” moot, because existing uses of #![ always apply to the construct with immediately enclosing brackets.

Yes, I think it should apply to the whole statement - we see attributes in a statement position, and we parse the following code as a statement with those attributes.

Similarly to how attributes in function parameter position or in match arm position apply to the whole parameter / arm and not to the closest pattern.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.