Fix parsing logic in proc_macro::quote - #148209
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
114e740 to
02f04b0
Compare
This comment has been minimized.
This comment has been minimized.
02f04b0 to
0e341e2
Compare
proc_macro::quoteproc_macro::quote
|
rustbot has assigned @petrochenkov. Use |
|
r? @tgross35 |
|
|
proc_macro::quoteproc_macro::quote
8dc03cd to
36c13e9
Compare
This comment has been minimized.
This comment has been minimized.
|
David knows this much better than I do r? @dtolnay |
|
@bors r+ |
|
@moatom: 🔑 Insufficient privileges: Not in reviewers |
|
@tgross35 thx. I wanted to restart CI just in case because this PR compiles locally. |
|
@dtolnay |
|
|
||
| fn main() { | ||
| let arr = [1, 2, 3]; | ||
| let _ = quote! { ${$arr}* }; //~ ERROR the trait bound `[{integer}; 3]: ToTokens` is not satisfied [E0277] |
There was a problem hiding this comment.
| let _ = quote! { ${$arr}* }; //~ ERROR the trait bound `[{integer}; 3]: ToTokens` is not satisfied [E0277] | |
| let _ = quote! { $[$arr]* }; //~ ERROR the trait bound `[{integer}; 3]: ToTokens` is not satisfied [E0277] |
| match &tree { | ||
| TokenTree::Punct(tt) if tt.as_char() == '$' => { | ||
| if let Some(TokenTree::Ident(id)) = iter.peek() { | ||
| while let Some(ref tree) = iter.next() { |
There was a problem hiding this comment.
This is going to miss adjacent metavariables. For example this works:
let a = ['a'];
let b = ['b'];
eprintln!("{}", proc_macro::quote!($($a . $b)*));but this does not:
eprintln!("{}", proc_macro::quote!($($a $b)*));There was a problem hiding this comment.
[note] This was caused by an extra iter.next();: b2ae84c#diff-6ebaa6be050b7cea1d542579c11cde3cba0942a3417c53298001f9db02a8d06dL407
| } | ||
|
|
||
| /// Consume a `$( CONTENTS ) SEP *` accordingly. It handles repetition by expanding `$( CONTENTS ) SEP *` to `{ REP_EXPANDED }`. | ||
| fn consume_dollar_group_sep_star( |
There was a problem hiding this comment.
This is accepting too many tokens in the "separator" in some cases.
let arr = ['a', 'b'];
eprintln!("{}", proc_macro::quote!($($arr) $$ x .. false [] *));'a' $x .. false [] 'b'There was a problem hiding this comment.
I introduced is_valid_sep_prefix to resolve this, but there might be a more elegant solution.
abc4763 to
ae0617b
Compare
|
r? @dtolnay |
|
Requested reviewer is already assigned to this pull request. Please choose another assignee. |
This comment has been minimized.
This comment has been minimized.
ae0617b to
93fd70a
Compare
This comment has been minimized.
This comment has been minimized.
88f4fbe to
3613f22
Compare
3613f22 to
62534aa
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
I've now rebased and squashed the commits for smoother communication. |
| consume_dollar_group_sep_star(tt.stream(), &mut iter).to_tokens(&mut tokens); | ||
| continue; | ||
| } | ||
| TokenTree::Group(_) => { |
There was a problem hiding this comment.
output_dollar_group_sep seems available here too.
|
Been a little while, r? libs |
View all comments
Fix #140238