Skip to content

Commit 935c53b

Browse files
committed
internal: use cov-mark rather than bailing out diagnostic
1 parent b292e1b commit 935c53b

File tree

5 files changed

+62
-108
lines changed

5 files changed

+62
-108
lines changed

crates/hir/src/diagnostics.rs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
//!
44
//! This probably isn't the best way to do this -- ideally, diagnistics should
55
//! be expressed in terms of hir types themselves.
6-
use std::any::Any;
7-
86
use cfg::{CfgExpr, CfgOptions};
97
use either::Either;
108
use hir_def::path::ModPath;
@@ -157,25 +155,4 @@ pub struct MissingMatchArms {
157155
pub arms: AstPtr<ast::MatchArmList>,
158156
}
159157

160-
#[derive(Debug)]
161-
pub struct InternalBailedOut {
162-
pub file: HirFileId,
163-
pub pat_syntax_ptr: SyntaxNodePtr,
164-
}
165-
166-
impl Diagnostic for InternalBailedOut {
167-
fn code(&self) -> DiagnosticCode {
168-
DiagnosticCode("internal:match-check-bailed-out")
169-
}
170-
fn message(&self) -> String {
171-
format!("Internal: match check bailed out")
172-
}
173-
fn display_source(&self) -> InFile<SyntaxNodePtr> {
174-
InFile { file_id: self.file, value: self.pat_syntax_ptr.clone() }
175-
}
176-
fn as_any(&self) -> &(dyn Any + Send + 'static) {
177-
self
178-
}
179-
}
180-
181158
pub use hir_ty::diagnostics::IncorrectCase;

crates/hir/src/lib.rs

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ use crate::{
8686
pub use crate::{
8787
attrs::{HasAttrs, Namespace},
8888
diagnostics::{
89-
AnyDiagnostic, BreakOutsideOfLoop, InactiveCode, IncorrectCase, InternalBailedOut,
90-
MacroError, MismatchedArgCount, MissingFields, MissingMatchArms, MissingOkOrSomeInTailExpr,
89+
AnyDiagnostic, BreakOutsideOfLoop, InactiveCode, IncorrectCase, MacroError,
90+
MismatchedArgCount, MissingFields, MissingMatchArms, MissingOkOrSomeInTailExpr,
9191
MissingUnsafe, NoSuchField, RemoveThisSemicolon, ReplaceFilterMapNextWithFindMap,
9292
UnimplementedBuiltinMacro, UnresolvedExternCrate, UnresolvedImport, UnresolvedMacroCall,
9393
UnresolvedModule, UnresolvedProcMacro,
@@ -461,7 +461,6 @@ impl Module {
461461
self,
462462
db: &dyn HirDatabase,
463463
sink: &mut DiagnosticSink,
464-
internal_diagnostics: bool,
465464
) -> Vec<AnyDiagnostic> {
466465
let _p = profile::span("Module::diagnostics").detail(|| {
467466
format!("{:?}", self.name(db).map_or("<unknown>".into(), |name| name.to_string()))
@@ -619,11 +618,11 @@ impl Module {
619618
}
620619
for decl in self.declarations(db) {
621620
match decl {
622-
ModuleDef::Function(f) => acc.extend(f.diagnostics(db, sink, internal_diagnostics)),
621+
ModuleDef::Function(f) => acc.extend(f.diagnostics(db, sink)),
623622
ModuleDef::Module(m) => {
624623
// Only add diagnostics from inline modules
625624
if def_map[m.id.local_id].origin.is_inline() {
626-
acc.extend(m.diagnostics(db, sink, internal_diagnostics))
625+
acc.extend(m.diagnostics(db, sink))
627626
}
628627
}
629628
_ => acc.extend(decl.diagnostics(db)),
@@ -633,7 +632,7 @@ impl Module {
633632
for impl_def in self.impl_defs(db) {
634633
for item in impl_def.items(db) {
635634
if let AssocItem::Function(f) = item {
636-
acc.extend(f.diagnostics(db, sink, internal_diagnostics));
635+
acc.extend(f.diagnostics(db, sink));
637636
}
638637
}
639638
}
@@ -1040,7 +1039,6 @@ impl Function {
10401039
self,
10411040
db: &dyn HirDatabase,
10421041
sink: &mut DiagnosticSink,
1043-
internal_diagnostics: bool,
10441042
) -> Vec<AnyDiagnostic> {
10451043
let mut acc: Vec<AnyDiagnostic> = Vec::new();
10461044
let krate = self.module(db).id.krate();
@@ -1100,9 +1098,7 @@ impl Function {
11001098
}
11011099
}
11021100

1103-
for diagnostic in
1104-
BodyValidationDiagnostic::collect(db, self.id.into(), internal_diagnostics)
1105-
{
1101+
for diagnostic in BodyValidationDiagnostic::collect(db, self.id.into()) {
11061102
match diagnostic {
11071103
BodyValidationDiagnostic::RecordMissingFields {
11081104
record,
@@ -1223,18 +1219,6 @@ impl Function {
12231219
Err(SyntheticSyntax) => (),
12241220
}
12251221
}
1226-
BodyValidationDiagnostic::InternalBailedOut { pat } => {
1227-
match source_map.pat_syntax(pat) {
1228-
Ok(source_ptr) => {
1229-
let pat_syntax_ptr = source_ptr.value.either(Into::into, Into::into);
1230-
sink.push(InternalBailedOut {
1231-
file: source_ptr.file_id,
1232-
pat_syntax_ptr,
1233-
});
1234-
}
1235-
Err(SyntheticSyntax) => (),
1236-
}
1237-
}
12381222
}
12391223
}
12401224

crates/hir_ty/src/diagnostics/expr.rs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,13 @@ pub enum BodyValidationDiagnostic {
5050
MissingMatchArms {
5151
match_expr: ExprId,
5252
},
53-
InternalBailedOut {
54-
pat: PatId,
55-
},
5653
}
5754

5855
impl BodyValidationDiagnostic {
59-
pub fn collect(
60-
db: &dyn HirDatabase,
61-
owner: DefWithBodyId,
62-
internal_diagnostics: bool,
63-
) -> Vec<BodyValidationDiagnostic> {
56+
pub fn collect(db: &dyn HirDatabase, owner: DefWithBodyId) -> Vec<BodyValidationDiagnostic> {
6457
let _p = profile::span("BodyValidationDiagnostic::collect");
6558
let infer = db.infer(owner);
6659
let mut validator = ExprValidator::new(owner, infer.clone());
67-
validator.internal_diagnostics = internal_diagnostics;
6860
validator.validate_body(db);
6961
validator.diagnostics
7062
}
@@ -74,12 +66,11 @@ struct ExprValidator {
7466
owner: DefWithBodyId,
7567
infer: Arc<InferenceResult>,
7668
pub(super) diagnostics: Vec<BodyValidationDiagnostic>,
77-
internal_diagnostics: bool,
7869
}
7970

8071
impl ExprValidator {
8172
fn new(owner: DefWithBodyId, infer: Arc<InferenceResult>) -> ExprValidator {
82-
ExprValidator { owner, infer, diagnostics: Vec::new(), internal_diagnostics: false }
73+
ExprValidator { owner, infer, diagnostics: Vec::new() }
8374
}
8475

8576
fn validate_body(&mut self, db: &dyn HirDatabase) {
@@ -308,9 +299,7 @@ impl ExprValidator {
308299
// fit the match expression, we skip this diagnostic. Skipping the entire
309300
// diagnostic rather than just not including this match arm is preferred
310301
// to avoid the chance of false positives.
311-
if self.internal_diagnostics {
312-
self.diagnostics.push(BodyValidationDiagnostic::InternalBailedOut { pat: arm.pat })
313-
}
302+
cov_mark::hit!(validate_match_bailed_out);
314303
return;
315304
}
316305

crates/ide/src/diagnostics.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,9 @@ pub(crate) fn diagnostics(
181181
});
182182

183183
let mut diags = Vec::new();
184-
let internal_diagnostics = cfg!(test);
185184
let module = sema.to_module_def(file_id);
186185
if let Some(m) = module {
187-
diags = m.diagnostics(db, &mut sink, internal_diagnostics)
186+
diags = m.diagnostics(db, &mut sink)
188187
}
189188

190189
drop(sink);

0 commit comments

Comments
 (0)