Fix ICE on for await loops with separated keyword tokens - #7063
Fix ICE on for await loops with separated keyword tokens#7063AsthaMishra wants to merge 2 commits into
for await loops with separated keyword tokens#7063Conversation
| // rustfmt-edition: 2024 | ||
|
|
There was a problem hiding this comment.
Is for await only available in the 2024 edition?
There was a problem hiding this comment.
@AsthaMishra Might be best to set the lowest edition where for await is available.
There was a problem hiding this comment.
will remove this
| let offset = self.keyword.len() + label_string.len() + 1; | ||
| let offset = keyword.len() + label_string.len() + 1; |
There was a problem hiding this comment.
This doesn't seem correct to me in if there's a multi line comment. For example:
`for /* some
* multi-line
* comment
*/ await`
There was a problem hiding this comment.
multi line comment working fine
async fn for_await_comment_after_for(iter: Iter) {
for /* some
* multi-line
* comment
*/ await
i in iter {}
}
this formatted to
async fn for_await_comment_after_for(iter: Iter) {
for /* some
* multi-line
* comment
*/
await i in iter {}
}
and no other errors
There was a problem hiding this comment.
@AsthaMishra what I'm saying is that it doesn't make sense to calculate the offset based on the entire length of the comment + the keywords. Especially if the comment is on multiple lines.
There was a problem hiding this comment.
okay. Understood.
| async fn for_await_comment_between_keywords(iter: Iter) { | ||
| for /* between for and await */ await i in iter {} | ||
| } | ||
|
|
||
| async fn for_await_comment_after_keyword(iter: Iter) { | ||
| for await /* between await and pat */ i in iter {} | ||
| } | ||
|
|
||
| async fn for_await_comment_both_gaps(iter: Iter) { | ||
| for /* first gap */ await /* second gap */ i in iter {} | ||
| } |
There was a problem hiding this comment.
Let's add test cases where the user uses a // line comment instead of an /* inline comment */. Let's also expand on what we've got here and add some multi-line comment test cases too.
|
@rustbot author |
|
Reminder, once the PR becomes ready for a review, use |
… last new line. Test cases added for multi-line and line comment
|
@rustbot ready |
Issue : we are searching source for single string literal
for await, but source have more than one space between these tokens. Any source that separated tokens with more than one space, new line, or a comment failed the search becausespan_afterpanickedFix: locate
forandawaitas independent token then combine them withcombine_strs_with_missing_commentsby preserving any comment between them, like howmutandrefhandled in patterns.rs. the lookup usesopt_span_afterso a miss results in unformatted output instead of an ICEFixes #7054