mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 16:54:01 +00:00
Merge #3009
3009: Make sure that newly created nodes are the root of the tree r=matklad a=matklad Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
1f7a54cfa7
@ -2,7 +2,7 @@
|
||||
//! of smaller pieces.
|
||||
use itertools::Itertools;
|
||||
|
||||
use crate::{ast, AstNode, SourceFile, SyntaxKind, SyntaxToken};
|
||||
use crate::{ast, AstNode, SourceFile, SyntaxKind, SyntaxNode, SyntaxToken};
|
||||
|
||||
pub fn name(text: &str) -> ast::Name {
|
||||
ast_from_text(&format!("mod {};", text))
|
||||
@ -179,7 +179,16 @@ pub fn token(kind: SyntaxKind) -> SyntaxToken {
|
||||
|
||||
fn ast_from_text<N: AstNode>(text: &str) -> N {
|
||||
let parse = SourceFile::parse(text);
|
||||
parse.tree().syntax().descendants().find_map(N::cast).unwrap()
|
||||
let node = parse.tree().syntax().descendants().find_map(N::cast).unwrap();
|
||||
let node = node.syntax().clone();
|
||||
let node = unroot(node);
|
||||
let node = N::cast(node).unwrap();
|
||||
assert_eq!(node.syntax().text_range().start(), 0.into());
|
||||
node
|
||||
}
|
||||
|
||||
fn unroot(n: SyntaxNode) -> SyntaxNode {
|
||||
SyntaxNode::new_root(n.green().clone())
|
||||
}
|
||||
|
||||
pub mod tokens {
|
||||
|
Loading…
Reference in New Issue
Block a user