mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-28 12:55:11 +00:00
ddbb28daa0
This will be needed as we parse unknown identifiers and want to insert them into source code.
17 lines
533 B
Rust
17 lines
533 B
Rust
//! Things which exist to solve practical issues, but which shouldn't exist.
|
|
//!
|
|
//! Please avoid adding new usages of the functions in this module
|
|
|
|
use parser::Edition;
|
|
|
|
use crate::{ast, AstNode};
|
|
|
|
pub fn parse_expr_from_str(s: &str, edition: Edition) -> Option<ast::Expr> {
|
|
let s = s.trim();
|
|
let file = ast::SourceFile::parse(&format!("const _: () = {s};"), edition);
|
|
let expr = file.syntax_node().descendants().find_map(ast::Expr::cast)?;
|
|
if expr.syntax().text() != s {
|
|
return None;
|
|
}
|
|
Some(expr)
|
|
}
|