From bab29e65eb87f4765fb22d58bff723780980eeb6 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Wed, 14 Oct 2020 22:21:58 +0200 Subject: Default::default the highlighters --- crates/ide/src/syntax_highlighting.rs | 6 +++--- crates/ide/src/syntax_highlighting/format.rs | 4 ---- crates/ide/src/syntax_highlighting/macro_rules.rs | 15 ++++----------- 3 files changed, 7 insertions(+), 18 deletions(-) diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs index 8ecaff204..527888306 100644 --- a/crates/ide/src/syntax_highlighting.rs +++ b/crates/ide/src/syntax_highlighting.rs @@ -74,7 +74,7 @@ pub(crate) fn highlight( let mut current_macro_call: Option = None; let mut format_string_highlighter = FormatStringHighlighter::default(); - let mut macro_rules_highlighter = MacroRulesHighlighter::new(); + let mut macro_rules_highlighter = MacroRulesHighlighter::default(); // Walk all nodes, keeping track of whether we are inside a macro or not. // If in macro, expand it first and highlight the expanded code. @@ -125,8 +125,8 @@ pub(crate) fn highlight( WalkEvent::Leave(Some(mc)) => { assert!(current_macro_call == Some(mc)); current_macro_call = None; - format_string_highlighter.reset(); - macro_rules_highlighter.reset(); + format_string_highlighter = FormatStringHighlighter::default(); + macro_rules_highlighter = MacroRulesHighlighter::default(); } _ => (), } diff --git a/crates/ide/src/syntax_highlighting/format.rs b/crates/ide/src/syntax_highlighting/format.rs index 3ab01295a..71bde24f0 100644 --- a/crates/ide/src/syntax_highlighting/format.rs +++ b/crates/ide/src/syntax_highlighting/format.rs @@ -12,10 +12,6 @@ pub(super) struct FormatStringHighlighter { } impl FormatStringHighlighter { - pub(super) fn reset(&mut self) { - self.format_string = None; - } - pub(super) fn check_for_format_string(&mut self, parent: &SyntaxNode) { // Check if macro takes a format string and remember it for highlighting later. // The macros that accept a format string expand to a compiler builtin macros diff --git a/crates/ide/src/syntax_highlighting/macro_rules.rs b/crates/ide/src/syntax_highlighting/macro_rules.rs index 0676e0972..4462af47e 100644 --- a/crates/ide/src/syntax_highlighting/macro_rules.rs +++ b/crates/ide/src/syntax_highlighting/macro_rules.rs @@ -3,21 +3,14 @@ use syntax::{SyntaxElement, SyntaxKind, SyntaxToken, TextRange, T}; use crate::{HighlightTag, HighlightedRange}; +#[derive(Default)] pub(super) struct MacroRulesHighlighter { state: Option, } impl MacroRulesHighlighter { - pub(super) fn new() -> Self { - MacroRulesHighlighter { state: None } - } - pub(super) fn init(&mut self) { - self.state = Some(MacroMatcherParseState::new()); - } - - pub(super) fn reset(&mut self) { - self.state = None; + self.state = Some(MacroMatcherParseState::default()); } pub(super) fn advance(&mut self, token: &SyntaxToken) { @@ -51,8 +44,8 @@ struct MacroMatcherParseState { in_invoc_body: bool, } -impl MacroMatcherParseState { - fn new() -> Self { +impl Default for MacroMatcherParseState { + fn default() -> Self { MacroMatcherParseState { paren_ty: None, paren_level: 0, -- cgit v1.2.3