fix: cfg_select supports non token-tree tokens#21705
fix: cfg_select supports non token-tree tokens#21705A4-Tacks wants to merge 2 commits intorust-lang:masterfrom
Conversation
900fe40 to
441213c
Compare
| ); | ||
| } | ||
| Some(_) => { | ||
| let savepoint = iter.savepoint(); |
There was a problem hiding this comment.
That's not how rustc does this and this is not the right way. This will break on e.g. paths with commas like foo::<T, U>. You need to parse an expression with the parser.
There was a problem hiding this comment.
But it still needs to support pat, so I roughly delimited it with commas
There was a problem hiding this comment.
What do you mean by "it still need to support pat"? You need to use the parser to parse an expr like with macro_rules matcher.
There was a problem hiding this comment.
Like let cfg_select! { _ => () } = ();,
but now I realize that it's actually parsing according to the expression, it just happens to be a valid pat
- Fix single non-curly groups is ignored `true => ((),)`, old: `(),`, new: `((),)`
Example
---
```rust
const _: i32 = cfg_select! { true => 2 + 3, _ => 3 + 4 };
```
**Before this PR**
```rust
const _: i32 = cfg_select! { true => 2 /* expected a token tree after `=>` */+ 3, _ => 3 + 4 };
```
**After this PR**
```rust
const _: i32 = 2 + 3;
```
441213c to
56b5dc1
Compare
56b5dc1 to
d50fae3
Compare
00ca67e to
b12c79e
Compare
| }; | ||
|
|
||
| /// Parse one expression, skip comma in turbofish | ||
| fn parse_expr<'a>(iter: &mut TtIter<'a>) -> tt::TokenTreesView<'a> { |
There was a problem hiding this comment.
That is definitely not enough. The only way to parse an expression reliably is to invoke the parser.
There was a problem hiding this comment.
That is definitely not enough.
Is there anything else besides the closure returning the location?
The only way to parse an expression reliably is to invoke the parser.
Do we have an expression parser for TtIter?
There was a problem hiding this comment.
Is there anything else besides the closure returning the location?
What do you mean?
Do we have an expression parser for TtIter?
No, but you can look at the macro_rules matcher. Look at the function named expect_fragment().
Fixes #21702
true => ((),), old:(),, new:((),)Example
Before this PR
After this PR