mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-05 06:27:38 +00:00
15 lines
463 B
Rust
15 lines
463 B
Rust
![]() |
//! Things which exist to solve practial issues, but which shouldn't exist.
|
||
|
//!
|
||
|
//! Please avoid adding new usages of the functions in this module
|
||
|
|
||
|
use crate::{ast, AstNode};
|
||
|
|
||
|
pub fn parse_expr_from_str(s: &str) -> Option<ast::Expr> {
|
||
|
let file = ast::SourceFile::parse(&format!("const _: () = {};", s));
|
||
|
let expr = file.syntax_node().descendants().find_map(ast::Expr::cast)?;
|
||
|
if expr.syntax().text() != s {
|
||
|
return None;
|
||
|
}
|
||
|
Some(expr)
|
||
|
}
|