wowlab_tidy/languages/rust/rules/hygiene/support.rs
1use ra_ap_syntax::{AstNode, Edition, SourceFile, ast};
2
3pub(super) fn parse_expr(source: &str) -> Option<ast::Expr> {
4 let fixture = format!("fn fixture() {{ let value = {source}; }}");
5 let parse = SourceFile::parse(&fixture, Edition::Edition2024);
6
7 if !parse.errors().is_empty() {
8 return None;
9 }
10
11 parse
12 .tree()
13 .syntax()
14 .descendants()
15 .find_map(ast::LetStmt::cast)?
16 .initializer()
17}