struct Matcher<'db, 'sema> {
sema: &'sema Semantics<'db, RootDatabase>,
restrict_range: Option<FileRange>,
rule: &'sema ResolvedRule<'db>,
}Expand description
Checks if our search pattern matches a particular node of the AST.
Fields§
§sema: &'sema Semantics<'db, RootDatabase>§restrict_range: Option<FileRange>If any placeholders come from anywhere outside of this range, then the match will be rejected.
rule: &'sema ResolvedRule<'db>Implementations§
Source§impl<'db, 'sema> Matcher<'db, 'sema>
impl<'db, 'sema> Matcher<'db, 'sema>
fn try_match( rule: &ResolvedRule<'db>, code: &SyntaxNode, restrict_range: &Option<FileRange>, sema: &'sema Semantics<'db, RootDatabase>, ) -> Result<Match, MatchFailed>
Sourcefn validate_range(&self, range: &FileRange) -> Result<(), MatchFailed>
fn validate_range(&self, range: &FileRange) -> Result<(), MatchFailed>
Checks that range is within the permitted range if any. This is applicable when we’re
processing a macro expansion and we want to fail the match if we’re working with a node that
didn’t originate from the token tree of the macro call.
fn attempt_match_node( &self, phase: &mut Phase<'_>, pattern: &SyntaxNode, code: &SyntaxNode, ) -> Result<(), MatchFailed>
fn attempt_match_node_children( &self, phase: &mut Phase<'_>, pattern: &SyntaxNode, code: &SyntaxNode, ) -> Result<(), MatchFailed>
fn attempt_match_sequences( &self, phase: &mut Phase<'_>, pattern_it: PatternIterator, code_it: SyntaxElementChildren, ) -> Result<(), MatchFailed>
fn attempt_match_token( &self, phase: &mut Phase<'_>, pattern: &mut Peekable<PatternIterator>, code: &SyntaxToken, ) -> Result<(), MatchFailed>
fn check_constraint( &self, constraint: &Constraint, code: &SyntaxNode, ) -> Result<(), MatchFailed>
Sourcefn attempt_match_path(
&self,
phase: &mut Phase<'_>,
pattern: &SyntaxNode,
code: &SyntaxNode,
) -> Result<(), MatchFailed>
fn attempt_match_path( &self, phase: &mut Phase<'_>, pattern: &SyntaxNode, code: &SyntaxNode, ) -> Result<(), MatchFailed>
Paths are matched based on whether they refer to the same thing, even if they’re written differently.
fn attempt_match_opt<T: AstNode>( &self, phase: &mut Phase<'_>, pattern: Option<T>, code: Option<T>, ) -> Result<(), MatchFailed>
Sourcefn attempt_match_record_field_list(
&self,
phase: &mut Phase<'_>,
pattern: &SyntaxNode,
code: &SyntaxNode,
) -> Result<(), MatchFailed>
fn attempt_match_record_field_list( &self, phase: &mut Phase<'_>, pattern: &SyntaxNode, code: &SyntaxNode, ) -> Result<(), MatchFailed>
We want to allow the records to match in any order, so we have special matching logic for them.
Sourcefn attempt_match_token_tree(
&self,
phase: &mut Phase<'_>,
pattern: &SyntaxNode,
code: &SyntaxNode,
) -> Result<(), MatchFailed>
fn attempt_match_token_tree( &self, phase: &mut Phase<'_>, pattern: &SyntaxNode, code: &SyntaxNode, ) -> Result<(), MatchFailed>
Outside of token trees, a placeholder can only match a single AST node, whereas in a token tree it can match a sequence of tokens. Note, that this code will only be used when the pattern matches the macro invocation. For matches within the macro call, we’ll already have expanded the macro.
fn attempt_match_ufcs_to_method_call( &self, phase: &mut Phase<'_>, pattern_ufcs: &UfcsCallInfo<'db>, code: &MethodCallExpr, ) -> Result<(), MatchFailed>
fn attempt_match_ufcs_to_ufcs( &self, phase: &mut Phase<'_>, pattern_ufcs: &UfcsCallInfo<'db>, code: &CallExpr, ) -> Result<(), MatchFailed>
Sourcefn check_expr_type(
&self,
pattern_type: &Type<'db>,
expr: &Expr,
) -> Result<usize, MatchFailed>
fn check_expr_type( &self, pattern_type: &Type<'db>, expr: &Expr, ) -> Result<usize, MatchFailed>
Verifies that expr matches pattern_type, possibly after dereferencing some number of
times. Returns the number of times it needed to be dereferenced.
fn get_placeholder_for_node(&self, node: &SyntaxNode) -> Option<&Placeholder>
fn get_placeholder(&self, element: &SyntaxElement) -> Option<&Placeholder>
Auto Trait Implementations§
impl<'db, 'sema> Freeze for Matcher<'db, 'sema>
impl<'db, 'sema> !RefUnwindSafe for Matcher<'db, 'sema>
impl<'db, 'sema> !Send for Matcher<'db, 'sema>
impl<'db, 'sema> !Sync for Matcher<'db, 'sema>
impl<'db, 'sema> Unpin for Matcher<'db, 'sema>
impl<'db, 'sema> UnsafeUnpin for Matcher<'db, 'sema>
impl<'db, 'sema> !UnwindSafe for Matcher<'db, 'sema>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T, R> CollectAndApply<T, R> for T
impl<T, R> CollectAndApply<T, R> for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more