diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-05-04 20:42:30 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-05-04 20:42:30 +0100 |
commit | 5b663f1b07233442a3b0b58db453504dcc51ddc9 (patch) | |
tree | 83e7822f41dd04db2f5e79d75f88a9c838beceee /crates/hir_expand/src/hygiene.rs | |
parent | 010e4c8fe018d703aac38c54307ddbee35edc380 (diff) | |
parent | 1ea4dae59699a103209a7ecfc1a03c8df0d211af (diff) |
Merge #8732
8732: internal: refactor expansion queries r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/hir_expand/src/hygiene.rs')
-rw-r--r-- | crates/hir_expand/src/hygiene.rs | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/crates/hir_expand/src/hygiene.rs b/crates/hir_expand/src/hygiene.rs index 779725629..ed61ebca3 100644 --- a/crates/hir_expand/src/hygiene.rs +++ b/crates/hir_expand/src/hygiene.rs | |||
@@ -5,6 +5,7 @@ | |||
5 | use std::sync::Arc; | 5 | use std::sync::Arc; |
6 | 6 | ||
7 | use base_db::CrateId; | 7 | use base_db::CrateId; |
8 | use db::TokenExpander; | ||
8 | use either::Either; | 9 | use either::Either; |
9 | use mbe::Origin; | 10 | use mbe::Origin; |
10 | use parser::SyntaxKind; | 11 | use parser::SyntaxKind; |
@@ -115,7 +116,7 @@ struct HygieneInfo { | |||
115 | /// The `macro_rules!` arguments. | 116 | /// The `macro_rules!` arguments. |
116 | def_start: Option<InFile<TextSize>>, | 117 | def_start: Option<InFile<TextSize>>, |
117 | 118 | ||
118 | macro_def: Arc<(db::TokenExpander, mbe::TokenMap)>, | 119 | macro_def: Arc<TokenExpander>, |
119 | macro_arg: Arc<(tt::Subtree, mbe::TokenMap)>, | 120 | macro_arg: Arc<(tt::Subtree, mbe::TokenMap)>, |
120 | exp_map: Arc<mbe::TokenMap>, | 121 | exp_map: Arc<mbe::TokenMap>, |
121 | } | 122 | } |
@@ -124,13 +125,16 @@ impl HygieneInfo { | |||
124 | fn map_ident_up(&self, token: TextRange) -> Option<(InFile<TextRange>, Origin)> { | 125 | fn map_ident_up(&self, token: TextRange) -> Option<(InFile<TextRange>, Origin)> { |
125 | let token_id = self.exp_map.token_by_range(token)?; | 126 | let token_id = self.exp_map.token_by_range(token)?; |
126 | 127 | ||
127 | let (token_id, origin) = self.macro_def.0.map_id_up(token_id); | 128 | let (token_id, origin) = self.macro_def.map_id_up(token_id); |
128 | let (token_map, tt) = match origin { | 129 | let (token_map, tt) = match origin { |
129 | mbe::Origin::Call => (&self.macro_arg.1, self.arg_start), | 130 | mbe::Origin::Call => (&self.macro_arg.1, self.arg_start), |
130 | mbe::Origin::Def => ( | 131 | mbe::Origin::Def => match (&*self.macro_def, self.def_start) { |
131 | &self.macro_def.1, | 132 | (TokenExpander::MacroDef { def_site_token_map, .. }, Some(tt)) |
132 | *self.def_start.as_ref().expect("`Origin::Def` used with non-`macro_rules!` macro"), | 133 | | (TokenExpander::MacroRules { def_site_token_map, .. }, Some(tt)) => { |
133 | ), | 134 | (def_site_token_map, tt) |
135 | } | ||
136 | _ => panic!("`Origin::Def` used with non-`macro_rules!` macro"), | ||
137 | }, | ||
134 | }; | 138 | }; |
135 | 139 | ||
136 | let range = token_map.range_by_token(token_id)?.by_kind(SyntaxKind::IDENT)?; | 140 | let range = token_map.range_by_token(token_id)?.by_kind(SyntaxKind::IDENT)?; |