aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdwin Cheng <[email protected]>2019-11-04 13:43:36 +0000
committerEdwin Cheng <[email protected]>2019-11-04 17:38:20 +0000
commit7e28924012409352bbacbfebf9fac4e4409f09b8 (patch)
tree0d095814496c0ff04d1f1ecc8c6bafa8358a3a65
parente6709f64af1836460aee41aca34eb19ed3a337dd (diff)
Use ? and destructing to simplifed long code
-rw-r--r--crates/ra_hir_expand/src/db.rs36
1 files changed, 17 insertions, 19 deletions
diff --git a/crates/ra_hir_expand/src/db.rs b/crates/ra_hir_expand/src/db.rs
index b3746924d..8369c2b40 100644
--- a/crates/ra_hir_expand/src/db.rs
+++ b/crates/ra_hir_expand/src/db.rs
@@ -132,35 +132,33 @@ pub(crate) fn parse_macro_with_info(
132 log::warn!("fail on macro_parse: (reason: {})", err,); 132 log::warn!("fail on macro_parse: (reason: {})", err,);
133 }) 133 })
134 .ok()?; 134 .ok()?;
135 let res = match macro_file.macro_file_kind { 135
136 let (parsed, exp_map) = match macro_file.macro_file_kind {
136 MacroFileKind::Items => { 137 MacroFileKind::Items => {
137 mbe::token_tree_to_items(&tt.0).ok().map(|(p, map)| (Parse::to_syntax(p), map)) 138 mbe::token_tree_to_items(&tt.0).map(|(p, map)| (p.to_syntax(), map)).ok()?
138 } 139 }
139 MacroFileKind::Expr => { 140 MacroFileKind::Expr => {
140 mbe::token_tree_to_expr(&tt.0).ok().map(|(p, map)| (Parse::to_syntax(p), map)) 141 mbe::token_tree_to_expr(&tt.0).map(|(p, map)| (p.to_syntax(), map)).ok()?
141 } 142 }
142 }; 143 };
143 144
144 res.map(|(parsed, exp_map)| { 145 let expand_info = tt.1;
145 let expand_info = tt.1; 146 let loc: MacroCallLoc = db.lookup_intern_macro(macro_call_id);
146 let loc: MacroCallLoc = db.lookup_intern_macro(macro_call_id); 147
148 let arg_tt = loc.ast_id.to_node(db).token_tree();
149 let def_tt = loc.def.ast_id.to_node(db).token_tree();
147 150
148 let def_start = 151 let arg_start = arg_tt.map(|t| t.syntax().text_range().start());
149 loc.def.ast_id.to_node(db).token_tree().map(|t| t.syntax().text_range().start()); 152 let def_start = def_tt.map(|t| t.syntax().text_range().start());
150 let arg_start =
151 loc.ast_id.to_node(db).token_tree().map(|t| t.syntax().text_range().start());
152 153
153 let arg_map = arg_start 154 let arg_map =
154 .map(|start| exp_map.ranges(&expand_info.arg_map, start)) 155 arg_start.map(|start| exp_map.ranges(&expand_info.arg_map, start)).unwrap_or_default();
155 .unwrap_or_else(|| Vec::new()); 156 let def_map =
156 let def_map = def_start 157 def_start.map(|start| exp_map.ranges(&expand_info.def_map, start)).unwrap_or_default();
157 .map(|start| exp_map.ranges(&expand_info.def_map, start))
158 .unwrap_or_else(|| Vec::new());
159 158
160 let info = ExpansionInfo { arg_map, def_map }; 159 let info = ExpansionInfo { arg_map, def_map };
161 160
162 ParseMacroWithInfo { parsed, expansion_info: Arc::new(info) } 161 Some(ParseMacroWithInfo { parsed, expansion_info: Arc::new(info) })
163 })
164} 162}
165 163
166pub(crate) fn macro_expansion_info( 164pub(crate) fn macro_expansion_info(