Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add error recovery for use_tree_list parsing #16349

Merged
merged 6 commits into from Jan 18, 2024

Conversation

Young-Flash
Copy link
Member

This PR adds error recovery for USE_TREE_LIST parsing, avoid the wrong USE_TREE_LIST making the rest parsing incorrectly.

before

before

after

after

close #16227

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 11, 2024
Copy link
Member

@Veykril Veykril left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#4680 (comment) still applies here fwiw

But I think when parsing a {} delimited UseTree we can just skip unexpected tokens until we find the closing brace or a new item (ITEM_RECOVERY_SET). That should keep the balancing working.

}

pub(super) const USE_TREE_LIST_RECOVERY_SET: TokenSet =
TokenSet::new(&[T![;], T![,], T![.], T![ident]]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably contain pub and other item keywords like struct etc. Also the T![.] makes little sense here I think. ITEM_RECOVERY_SET) is probably what we want to include.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add T![.] here cause it's position on the keyboard is close to the T![,], some user may type it by mistakely when they want to type T![,] (as least I did 😄)

// use b;
// struct T;
// fn test() {}
delimited(p, T!['{'], T!['}'], T![,], USE_TREE_LIST_RECOVERY_SET, |p: &mut Parser<'_>| {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

USE_TREE_LIST_RECOVERY_SET is wrong here, that param in delimited is not for recovery but for the first set. So we want a USE_TREE_LIST_FIRST_SET that contains the tokens that use tree may start with.

Copy link
Member

@Veykril Veykril left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To re-iterate, I don't think matklad's comment on the previous PR applies here. The invariant that was mentioned is still upheld, either the } is eaten as the last child or we recover on an item in which case we stop the parse without consuming any closing one. The reparser checks the invariants for balancedness already so at worst we lose out on the re-parse in this case, but I think that is fine.

BUT, there is one problem I can see here I think. With this setup, the following might change now

struct implThing;

use crate::{impl$0};

This should complete implThing, but with the changes here it might no longer do that, can you add a completion test for this? If it no longer works (as I suspect) we need to adjust the recovery strategy by doing an extra lookahead after the keyword token for , and } and recover accordingly

@Veykril Veykril added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 16, 2024
@Young-Flash
Copy link
Member Author

actually the completion still works

image

@Veykril
Copy link
Member

Veykril commented Jan 18, 2024

Nice, thanks!
@bors r+

@bors
Copy link
Collaborator

bors commented Jan 18, 2024

📌 Commit 1c61326 has been approved by Veykril

It is now in the queue for this repository.

@bors
Copy link
Collaborator

bors commented Jan 18, 2024

⌛ Testing commit 1c61326 with merge 1ab8c7f...

@bors
Copy link
Collaborator

bors commented Jan 18, 2024

☀️ Test successful - checks-actions
Approved by: Veykril
Pushing 1ab8c7f to master...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

better error recovery for USE_TREE_LIST parsing
4 participants