aboutsummaryrefslogtreecommitdiff
path: root/crates/ssr/src/matching.rs
diff options
context:
space:
mode:
authorDavid Lattimore <[email protected]>2020-08-06 02:30:52 +0100
committerDavid Lattimore <[email protected]>2020-08-14 11:12:26 +0100
commitc84f98385a28eeb7595f38b7cfaf861a6e06f4ea (patch)
tree6f8c4a1770aeefde182e365e0d249ed12bc61fdd /crates/ssr/src/matching.rs
parent674af600f105abe1dcb6c7654058e7df5a402429 (diff)
Refactor SSR so that placeholders store a Var
This allows lookup of placeholder bindings given a placeholder without needing to create a Var instance.
Diffstat (limited to 'crates/ssr/src/matching.rs')
-rw-r--r--crates/ssr/src/matching.rs15
1 files changed, 5 insertions, 10 deletions
diff --git a/crates/ssr/src/matching.rs b/crates/ssr/src/matching.rs
index ffc7202ae..7f0b5061e 100644
--- a/crates/ssr/src/matching.rs
+++ b/crates/ssr/src/matching.rs
@@ -2,7 +2,7 @@
2//! process of matching, placeholder values are recorded. 2//! process of matching, placeholder values are recorded.
3 3
4use crate::{ 4use crate::{
5 parsing::{Constraint, NodeKind, Placeholder}, 5 parsing::{Constraint, NodeKind, Placeholder, Var},
6 resolving::{ResolvedPattern, ResolvedRule, UfcsCallInfo}, 6 resolving::{ResolvedPattern, ResolvedRule, UfcsCallInfo},
7 SsrMatches, 7 SsrMatches,
8}; 8};
@@ -56,10 +56,6 @@ pub struct Match {
56 pub(crate) rendered_template_paths: FxHashMap<SyntaxNode, hir::ModPath>, 56 pub(crate) rendered_template_paths: FxHashMap<SyntaxNode, hir::ModPath>,
57} 57}
58 58
59/// Represents a `$var` in an SSR query.
60#[derive(Debug, Clone, PartialEq, Eq, Hash)]
61pub(crate) struct Var(pub String);
62
63/// Information about a placeholder bound in a match. 59/// Information about a placeholder bound in a match.
64#[derive(Debug)] 60#[derive(Debug)]
65pub(crate) struct PlaceholderMatch { 61pub(crate) struct PlaceholderMatch {
@@ -182,10 +178,9 @@ impl<'db, 'sema> Matcher<'db, 'sema> {
182 // We validated the range for the node when we started the match, so the placeholder 178 // We validated the range for the node when we started the match, so the placeholder
183 // probably can't fail range validation, but just to be safe... 179 // probably can't fail range validation, but just to be safe...
184 self.validate_range(&original_range)?; 180 self.validate_range(&original_range)?;
185 matches_out.placeholder_values.insert( 181 matches_out
186 Var(placeholder.ident.to_string()), 182 .placeholder_values
187 PlaceholderMatch::new(code, original_range), 183 .insert(placeholder.ident.clone(), PlaceholderMatch::new(code, original_range));
188 );
189 } 184 }
190 return Ok(()); 185 return Ok(());
191 } 186 }
@@ -487,7 +482,7 @@ impl<'db, 'sema> Matcher<'db, 'sema> {
487 } 482 }
488 if let Phase::Second(match_out) = phase { 483 if let Phase::Second(match_out) = phase {
489 match_out.placeholder_values.insert( 484 match_out.placeholder_values.insert(
490 Var(placeholder.ident.to_string()), 485 placeholder.ident.clone(),
491 PlaceholderMatch::from_range(FileRange { 486 PlaceholderMatch::from_range(FileRange {
492 file_id: self.sema.original_range(code).file_id, 487 file_id: self.sema.original_range(code).file_id,
493 range: first_matched_token 488 range: first_matched_token