Skip to content

Commit 0e3e3e2

Browse files
bors[bot]matklad
andauthored
Merge #10357
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 <[email protected]>
2 parents 0618100 + defe805 commit 0e3e3e2

File tree

3 files changed

+5
-8
lines changed

3 files changed

+5
-8
lines changed

crates/syntax/src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,6 @@ impl SourceFile {
162162
let (green, mut errors) = parsing::parse_text(text);
163163
let root = SyntaxNode::new_root(green.clone());
164164

165-
if cfg!(debug_assertions) {
166-
validation::validate_block_structure(&root);
167-
}
168-
169165
errors.extend(validation::validate(&root));
170166

171167
assert_eq!(root.kind(), SyntaxKind::SOURCE_FILE);

crates/syntax/src/syntax_node.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl SyntaxTreeBuilder {
4747

4848
pub fn finish(self) -> Parse<SyntaxNode> {
4949
let (green, errors) = self.finish_raw();
50-
if cfg!(debug_assertions) {
50+
if cfg!(debug_assertions) && false {
5151
let node = SyntaxNode::new_root(green.clone());
5252
crate::validation::validate_block_structure(&node);
5353
}

crates/syntax/src/validation.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ fn validate_literal(literal: ast::Literal, acc: &mut Vec<SyntaxError>) {
170170

171171
pub(crate) fn validate_block_structure(root: &SyntaxNode) {
172172
let mut stack = Vec::new();
173-
for node in root.descendants() {
173+
for node in root.descendants_with_tokens() {
174174
match node.kind() {
175175
T!['{'] => stack.push(node),
176176
T!['}'] => {
@@ -183,11 +183,12 @@ pub(crate) fn validate_block_structure(root: &SyntaxNode) {
183183
root,
184184
);
185185
assert!(
186-
node.next_sibling().is_none() && pair.prev_sibling().is_none(),
186+
node.next_sibling_or_token().is_none()
187+
&& pair.prev_sibling_or_token().is_none(),
187188
"\nfloating curlys at {:?}\nfile:\n{}\nerror:\n{}\n",
188189
node,
189190
root.text(),
190-
node.text(),
191+
node,
191192
);
192193
}
193194
}

0 commit comments

Comments
 (0)