Skip to content

Commit b404b91

Browse files
committed
minor: dead code
1 parent ff52167 commit b404b91

File tree

2 files changed

+34
-50
lines changed

2 files changed

+34
-50
lines changed

crates/ide/src/diagnostics.rs

Lines changed: 21 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -86,36 +86,14 @@ impl Diagnostic {
8686
self
8787
}
8888

89-
fn error(range: TextRange, message: String) -> Self {
90-
Self {
91-
message,
92-
range,
93-
severity: Severity::Error,
94-
fixes: None,
95-
unused: false,
96-
code: None,
97-
experimental: false,
98-
}
99-
}
100-
101-
fn hint(range: TextRange, message: String) -> Self {
102-
Self {
103-
message,
104-
range,
105-
severity: Severity::WeakWarning,
106-
fixes: None,
107-
unused: false,
108-
code: None,
109-
experimental: false,
110-
}
111-
}
112-
113-
fn with_fixes(self, fixes: Option<Vec<Assist>>) -> Self {
114-
Self { fixes, ..self }
89+
fn with_fixes(mut self, fixes: Option<Vec<Assist>>) -> Diagnostic {
90+
self.fixes = fixes;
91+
self
11592
}
11693

117-
fn with_unused(self, unused: bool) -> Self {
118-
Self { unused, ..self }
94+
fn with_unused(mut self, unused: bool) -> Diagnostic {
95+
self.unused = unused;
96+
self
11997
}
12098
}
12199

@@ -150,11 +128,9 @@ pub(crate) fn diagnostics(
150128

151129
// [#34344] Only take first 128 errors to prevent slowing down editor/ide, the number 128 is chosen arbitrarily.
152130
res.extend(
153-
parse
154-
.errors()
155-
.iter()
156-
.take(128)
157-
.map(|err| Diagnostic::error(err.range(), format!("Syntax Error: {}", err))),
131+
parse.errors().iter().take(128).map(|err| {
132+
Diagnostic::new("syntax-error", format!("Syntax Error: {}", err), err.range())
133+
}),
158134
);
159135

160136
for node in parse.tree().syntax().descendants() {
@@ -244,13 +220,18 @@ fn check_unnecessary_braces_in_use_statement(
244220
});
245221

246222
acc.push(
247-
Diagnostic::hint(use_range, "Unnecessary braces in use statement".to_string())
248-
.with_fixes(Some(vec![fix(
249-
"remove_braces",
250-
"Remove unnecessary braces",
251-
SourceChange::from_text_edit(file_id, edit),
252-
use_range,
253-
)])),
223+
Diagnostic::new(
224+
"unnecessary-braces",
225+
"Unnecessary braces in use statement".to_string(),
226+
use_range,
227+
)
228+
.severity(Severity::WeakWarning)
229+
.with_fixes(Some(vec![fix(
230+
"remove_braces",
231+
"Remove unnecessary braces",
232+
SourceChange::from_text_edit(file_id, edit),
233+
use_range,
234+
)])),
254235
);
255236
}
256237

crates/ide/src/diagnostics/field_shorthand.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use ide_db::{base_db::FileId, source_change::SourceChange};
55
use syntax::{ast, match_ast, AstNode, SyntaxNode};
66
use text_edit::TextEdit;
77

8-
use crate::{diagnostics::fix, Diagnostic};
8+
use crate::{diagnostics::fix, Diagnostic, Severity};
99

1010
pub(super) fn check(acc: &mut Vec<Diagnostic>, file_id: FileId, node: &SyntaxNode) {
1111
match_ast! {
@@ -46,7 +46,8 @@ fn check_expr_field_shorthand(
4646

4747
let field_range = record_field.syntax().text_range();
4848
acc.push(
49-
Diagnostic::hint(field_range, "Shorthand struct initialization".to_string())
49+
Diagnostic::new("use-field-shorthand", "Shorthand struct initialization", field_range)
50+
.severity(Severity::WeakWarning)
5051
.with_fixes(Some(vec![fix(
5152
"use_expr_field_shorthand",
5253
"Use struct shorthand initialization",
@@ -85,14 +86,16 @@ fn check_pat_field_shorthand(
8586
let edit = edit_builder.finish();
8687

8788
let field_range = record_pat_field.syntax().text_range();
88-
acc.push(Diagnostic::hint(field_range, "Shorthand struct pattern".to_string()).with_fixes(
89-
Some(vec![fix(
90-
"use_pat_field_shorthand",
91-
"Use struct field shorthand",
92-
SourceChange::from_text_edit(file_id, edit),
93-
field_range,
94-
)]),
95-
));
89+
acc.push(
90+
Diagnostic::new("use-field-shorthand", "Shorthand struct pattern", field_range)
91+
.severity(Severity::WeakWarning)
92+
.with_fixes(Some(vec![fix(
93+
"use_pat_field_shorthand",
94+
"Use struct field shorthand",
95+
SourceChange::from_text_edit(file_id, edit),
96+
field_range,
97+
)])),
98+
);
9699
}
97100
}
98101

0 commit comments

Comments
 (0)