Skip to content

Commit ff52167

Browse files
committed
internal: kill diagnostic sink
1 parent 935c53b commit ff52167

File tree

4 files changed

+19
-170
lines changed

4 files changed

+19
-170
lines changed

crates/hir/src/diagnostics.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ use hir_def::path::ModPath;
99
use hir_expand::{name::Name, HirFileId, InFile};
1010
use syntax::{ast, AstPtr, SyntaxNodePtr, TextRange};
1111

12-
pub use crate::diagnostics_sink::{
13-
Diagnostic, DiagnosticCode, DiagnosticSink, DiagnosticSinkBuilder,
14-
};
15-
1612
macro_rules! diagnostics {
1713
($($diag:ident,)*) => {
1814
pub enum AnyDiagnostic {$(

crates/hir/src/diagnostics_sink.rs

Lines changed: 0 additions & 109 deletions
This file was deleted.

crates/hir/src/lib.rs

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ mod attrs;
2727
mod has_source;
2828

2929
pub mod diagnostics;
30-
pub mod diagnostics_sink;
3130
pub mod db;
3231

3332
mod display;
@@ -78,10 +77,7 @@ use syntax::{
7877
};
7978
use tt::{Ident, Leaf, Literal, TokenTree};
8079

81-
use crate::{
82-
db::{DefDatabase, HirDatabase},
83-
diagnostics_sink::DiagnosticSink,
84-
};
80+
use crate::db::{DefDatabase, HirDatabase};
8581

8682
pub use crate::{
8783
attrs::{HasAttrs, Namespace},
@@ -457,15 +453,10 @@ impl Module {
457453
self.id.def_map(db.upcast())[self.id.local_id].scope.visibility_of((*def).into())
458454
}
459455

460-
pub fn diagnostics(
461-
self,
462-
db: &dyn HirDatabase,
463-
sink: &mut DiagnosticSink,
464-
) -> Vec<AnyDiagnostic> {
456+
pub fn diagnostics(self, db: &dyn HirDatabase, acc: &mut Vec<AnyDiagnostic>) {
465457
let _p = profile::span("Module::diagnostics").detail(|| {
466458
format!("{:?}", self.name(db).map_or("<unknown>".into(), |name| name.to_string()))
467459
});
468-
let mut acc: Vec<AnyDiagnostic> = Vec::new();
469460
let def_map = self.id.def_map(db.upcast());
470461
for diag in def_map.diagnostics() {
471462
if diag.in_module != self.id.local_id {
@@ -618,11 +609,11 @@ impl Module {
618609
}
619610
for decl in self.declarations(db) {
620611
match decl {
621-
ModuleDef::Function(f) => acc.extend(f.diagnostics(db, sink)),
612+
ModuleDef::Function(f) => f.diagnostics(db, acc),
622613
ModuleDef::Module(m) => {
623614
// Only add diagnostics from inline modules
624615
if def_map[m.id.local_id].origin.is_inline() {
625-
acc.extend(m.diagnostics(db, sink))
616+
m.diagnostics(db, acc)
626617
}
627618
}
628619
_ => acc.extend(decl.diagnostics(db)),
@@ -632,11 +623,10 @@ impl Module {
632623
for impl_def in self.impl_defs(db) {
633624
for item in impl_def.items(db) {
634625
if let AssocItem::Function(f) = item {
635-
acc.extend(f.diagnostics(db, sink));
626+
f.diagnostics(db, acc);
636627
}
637628
}
638629
}
639-
acc
640630
}
641631

642632
pub fn declarations(self, db: &dyn HirDatabase) -> Vec<ModuleDef> {
@@ -1035,12 +1025,7 @@ impl Function {
10351025
db.function_data(self.id).is_async()
10361026
}
10371027

1038-
pub fn diagnostics(
1039-
self,
1040-
db: &dyn HirDatabase,
1041-
sink: &mut DiagnosticSink,
1042-
) -> Vec<AnyDiagnostic> {
1043-
let mut acc: Vec<AnyDiagnostic> = Vec::new();
1028+
pub fn diagnostics(self, db: &dyn HirDatabase, acc: &mut Vec<AnyDiagnostic>) {
10441029
let krate = self.module(db).id.krate();
10451030

10461031
let source_map = db.body_with_source_map(self.id.into()).1;
@@ -1225,7 +1210,6 @@ impl Function {
12251210
for diag in hir_ty::diagnostics::validate_module_item(db, krate, self.id.into()) {
12261211
acc.push(diag.into())
12271212
}
1228-
acc
12291213
}
12301214

12311215
/// Whether this function declaration has a definition.

crates/ide/src/diagnostics.rs

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,7 @@ mod unresolved_proc_macro;
2626

2727
mod field_shorthand;
2828

29-
use std::cell::RefCell;
30-
31-
use hir::{
32-
diagnostics::{AnyDiagnostic, DiagnosticCode, DiagnosticSinkBuilder},
33-
Semantics,
34-
};
29+
use hir::{diagnostics::AnyDiagnostic, Semantics};
3530
use ide_assists::AssistResolveStrategy;
3631
use ide_db::{base_db::SourceDatabase, RootDatabase};
3732
use itertools::Itertools;
@@ -45,6 +40,15 @@ use unlinked_file::UnlinkedFile;
4540

4641
use crate::{Assist, AssistId, AssistKind, FileId, Label, SourceChange};
4742

43+
#[derive(Copy, Clone, Debug, PartialEq)]
44+
pub struct DiagnosticCode(pub &'static str);
45+
46+
impl DiagnosticCode {
47+
pub fn as_str(&self) -> &str {
48+
self.0
49+
}
50+
}
51+
4852
#[derive(Debug)]
4953
pub struct Diagnostic {
5054
// pub name: Option<String>,
@@ -113,10 +117,6 @@ impl Diagnostic {
113117
fn with_unused(self, unused: bool) -> Self {
114118
Self { unused, ..self }
115119
}
116-
117-
fn with_code(self, code: Option<DiagnosticCode>) -> Self {
118-
Self { code, ..self }
119-
}
120120
}
121121

122122
#[derive(Debug, Copy, Clone)]
@@ -161,35 +161,13 @@ pub(crate) fn diagnostics(
161161
check_unnecessary_braces_in_use_statement(&mut res, file_id, &node);
162162
field_shorthand::check(&mut res, file_id, &node);
163163
}
164-
let res = RefCell::new(res);
165-
let sink_builder = DiagnosticSinkBuilder::new()
166-
// Only collect experimental diagnostics when they're enabled.
167-
.filter(|diag| !(diag.is_experimental() && config.disable_experimental))
168-
.filter(|diag| !config.disabled.contains(diag.code().as_str()));
169-
170-
// Finalize the `DiagnosticSink` building process.
171-
let mut sink = sink_builder
172-
// Diagnostics not handled above get no fix and default treatment.
173-
.build(|d| {
174-
res.borrow_mut().push(
175-
Diagnostic::error(
176-
sema.diagnostics_display_range(d.display_source()).range,
177-
d.message(),
178-
)
179-
.with_code(Some(d.code())),
180-
);
181-
});
182164

183165
let mut diags = Vec::new();
184166
let module = sema.to_module_def(file_id);
185167
if let Some(m) = module {
186-
diags = m.diagnostics(db, &mut sink)
168+
m.diagnostics(db, &mut diags)
187169
}
188170

189-
drop(sink);
190-
191-
let mut res = res.into_inner();
192-
193171
let ctx = DiagnosticsContext { config, sema, resolve };
194172
if module.is_none() {
195173
let d = UnlinkedFile { file: file_id };
@@ -350,8 +328,8 @@ mod tests {
350328
)
351329
.unwrap()
352330
.pop()
353-
.unwrap();
354-
let fix = &diagnostic.fixes.unwrap()[nth];
331+
.expect("no diagnostics");
332+
let fix = &diagnostic.fixes.expect("diagnostic misses fixes")[nth];
355333
let actual = {
356334
let source_change = fix.source_change.as_ref().unwrap();
357335
let file_id = *source_change.source_file_edits.keys().next().unwrap();

0 commit comments

Comments
 (0)