Skip to content

Commit bab29e6

Browse files
committed
Default::default the highlighters
1 parent 8c6dc5f commit bab29e6

File tree

3 files changed

+7
-18
lines changed

3 files changed

+7
-18
lines changed

crates/ide/src/syntax_highlighting.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub(crate) fn highlight(
7474

7575
let mut current_macro_call: Option<ast::MacroCall> = None;
7676
let mut format_string_highlighter = FormatStringHighlighter::default();
77-
let mut macro_rules_highlighter = MacroRulesHighlighter::new();
77+
let mut macro_rules_highlighter = MacroRulesHighlighter::default();
7878

7979
// Walk all nodes, keeping track of whether we are inside a macro or not.
8080
// If in macro, expand it first and highlight the expanded code.
@@ -125,8 +125,8 @@ pub(crate) fn highlight(
125125
WalkEvent::Leave(Some(mc)) => {
126126
assert!(current_macro_call == Some(mc));
127127
current_macro_call = None;
128-
format_string_highlighter.reset();
129-
macro_rules_highlighter.reset();
128+
format_string_highlighter = FormatStringHighlighter::default();
129+
macro_rules_highlighter = MacroRulesHighlighter::default();
130130
}
131131
_ => (),
132132
}

crates/ide/src/syntax_highlighting/format.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ pub(super) struct FormatStringHighlighter {
1212
}
1313

1414
impl FormatStringHighlighter {
15-
pub(super) fn reset(&mut self) {
16-
self.format_string = None;
17-
}
18-
1915
pub(super) fn check_for_format_string(&mut self, parent: &SyntaxNode) {
2016
// Check if macro takes a format string and remember it for highlighting later.
2117
// The macros that accept a format string expand to a compiler builtin macros

crates/ide/src/syntax_highlighting/macro_rules.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,14 @@ use syntax::{SyntaxElement, SyntaxKind, SyntaxToken, TextRange, T};
33

44
use crate::{HighlightTag, HighlightedRange};
55

6+
#[derive(Default)]
67
pub(super) struct MacroRulesHighlighter {
78
state: Option<MacroMatcherParseState>,
89
}
910

1011
impl MacroRulesHighlighter {
11-
pub(super) fn new() -> Self {
12-
MacroRulesHighlighter { state: None }
13-
}
14-
1512
pub(super) fn init(&mut self) {
16-
self.state = Some(MacroMatcherParseState::new());
17-
}
18-
19-
pub(super) fn reset(&mut self) {
20-
self.state = None;
13+
self.state = Some(MacroMatcherParseState::default());
2114
}
2215

2316
pub(super) fn advance(&mut self, token: &SyntaxToken) {
@@ -51,8 +44,8 @@ struct MacroMatcherParseState {
5144
in_invoc_body: bool,
5245
}
5346

54-
impl MacroMatcherParseState {
55-
fn new() -> Self {
47+
impl Default for MacroMatcherParseState {
48+
fn default() -> Self {
5649
MacroMatcherParseState {
5750
paren_ty: None,
5851
paren_level: 0,

0 commit comments

Comments
 (0)