mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 04:19:13 +00:00
introduce hacks module
This commit is contained in:
parent
aa1788dc71
commit
bfc263f1f9
6 changed files with 34 additions and 51 deletions
14
crates/syntax/src/hacks.rs
Normal file
14
crates/syntax/src/hacks.rs
Normal file
|
@ -0,0 +1,14 @@
|
|||
//! 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)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue