10357: internal: fix and force-disable block validation ;-( r=matklad a=matklad

Originally we tried to maintain the invariant that `{}` always match.
That is, that in the parse tree the pair of corresponding `{}` is always
first and last tokens of some nodes.

We had the code to validate that, but apparently it's been broken for
**years** since we introduced tokens/nodes split. Fixing it now makes
some tests fail.

It's unclear if we want to keep this invariant: there's a strong
motivation for breaking it in the following case:

```
use std::{ // unclosed paren

fn main() {

}

} // don't actually want to pair up this with the one from `use`
```

So let's fix the code, but disable it for the time being

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2021-09-26 12:54:12 +00:00 committed by GitHub
commit 0e3e3e2a51
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 8 deletions

View file

@ -162,10 +162,6 @@ impl SourceFile {
let (green, mut errors) = parsing::parse_text(text); let (green, mut errors) = parsing::parse_text(text);
let root = SyntaxNode::new_root(green.clone()); let root = SyntaxNode::new_root(green.clone());
if cfg!(debug_assertions) {
validation::validate_block_structure(&root);
}
errors.extend(validation::validate(&root)); errors.extend(validation::validate(&root));
assert_eq!(root.kind(), SyntaxKind::SOURCE_FILE); assert_eq!(root.kind(), SyntaxKind::SOURCE_FILE);

View file

@ -47,7 +47,7 @@ impl SyntaxTreeBuilder {
pub fn finish(self) -> Parse<SyntaxNode> { pub fn finish(self) -> Parse<SyntaxNode> {
let (green, errors) = self.finish_raw(); let (green, errors) = self.finish_raw();
if cfg!(debug_assertions) { if cfg!(debug_assertions) && false {
let node = SyntaxNode::new_root(green.clone()); let node = SyntaxNode::new_root(green.clone());
crate::validation::validate_block_structure(&node); crate::validation::validate_block_structure(&node);
} }

View file

@ -170,7 +170,7 @@ fn validate_literal(literal: ast::Literal, acc: &mut Vec<SyntaxError>) {
pub(crate) fn validate_block_structure(root: &SyntaxNode) { pub(crate) fn validate_block_structure(root: &SyntaxNode) {
let mut stack = Vec::new(); let mut stack = Vec::new();
for node in root.descendants() { for node in root.descendants_with_tokens() {
match node.kind() { match node.kind() {
T!['{'] => stack.push(node), T!['{'] => stack.push(node),
T!['}'] => { T!['}'] => {
@ -183,11 +183,12 @@ pub(crate) fn validate_block_structure(root: &SyntaxNode) {
root, root,
); );
assert!( assert!(
node.next_sibling().is_none() && pair.prev_sibling().is_none(), node.next_sibling_or_token().is_none()
&& pair.prev_sibling_or_token().is_none(),
"\nfloating curlys at {:?}\nfile:\n{}\nerror:\n{}\n", "\nfloating curlys at {:?}\nfile:\n{}\nerror:\n{}\n",
node, node,
root.text(), root.text(),
node.text(), node,
); );
} }
} }