aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir')
-rw-r--r--crates/ra_hir/src/ids.rs38
1 files changed, 19 insertions, 19 deletions
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs
index 24c5f412b..cf0e934a9 100644
--- a/crates/ra_hir/src/ids.rs
+++ b/crates/ra_hir/src/ids.rs
@@ -81,25 +81,6 @@ impl HirFileId {
81 } 81 }
82} 82}
83 83
84fn parse_macro(
85 db: &impl DefDatabase,
86 macro_call_id: MacroCallId,
87) -> Result<TreeArc<SourceFile>, String> {
88 let loc = macro_call_id.loc(db);
89 let macro_arg = db.macro_arg(macro_call_id).ok_or("Fail to args in to tt::TokenTree")?;
90
91 let macro_rules = db.macro_def(loc.def).ok_or("Fail to find macro definition")?;
92 let tt = macro_rules.expand(&macro_arg).map_err(|err| format!("{:?}", err))?;
93
94 // Set a hard limit for the expanded tt
95 let count = tt.count();
96 if count > 65536 {
97 return Err(format!("Total tokens count exceed limit : count = {}", count));
98 }
99
100 Ok(mbe::token_tree_to_ast_item_list(&tt))
101}
102
103#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 84#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
104enum HirFileIdRepr { 85enum HirFileIdRepr {
105 File(FileId), 86 File(FileId),
@@ -143,6 +124,25 @@ pub(crate) fn macro_arg_query(db: &impl DefDatabase, id: MacroCallId) -> Option<
143 Some(Arc::new(tt)) 124 Some(Arc::new(tt))
144} 125}
145 126
127fn parse_macro(
128 db: &impl DefDatabase,
129 macro_call_id: MacroCallId,
130) -> Result<TreeArc<SourceFile>, String> {
131 let loc = macro_call_id.loc(db);
132 let macro_arg = db.macro_arg(macro_call_id).ok_or("Fail to args in to tt::TokenTree")?;
133
134 let macro_rules = db.macro_def(loc.def).ok_or("Fail to find macro definition")?;
135 let tt = macro_rules.expand(&macro_arg).map_err(|err| format!("{:?}", err))?;
136
137 // Set a hard limit for the expanded tt
138 let count = tt.count();
139 if count > 65536 {
140 return Err(format!("Total tokens count exceed limit : count = {}", count));
141 }
142
143 Ok(mbe::token_tree_to_ast_item_list(&tt))
144}
145
146macro_rules! impl_intern_key { 146macro_rules! impl_intern_key {
147 ($name:ident) => { 147 ($name:ident) => {
148 impl salsa::InternKey for $name { 148 impl salsa::InternKey for $name {