Skip to content

Commit b292e1b

Browse files
committed
internal: refactor missing match arms diagnostics
1 parent 3478897 commit b292e1b

File tree

4 files changed

+935
-930
lines changed

4 files changed

+935
-930
lines changed

crates/hir/src/diagnostics.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ diagnostics![
3838
MacroError,
3939
MismatchedArgCount,
4040
MissingFields,
41+
MissingMatchArms,
4142
MissingOkOrSomeInTailExpr,
4243
MissingUnsafe,
4344
NoSuchField,
@@ -149,31 +150,13 @@ pub struct MissingOkOrSomeInTailExpr {
149150
pub required: String,
150151
}
151152

152-
// Diagnostic: missing-match-arm
153-
//
154-
// This diagnostic is triggered if `match` block is missing one or more match arms.
155153
#[derive(Debug)]
156154
pub struct MissingMatchArms {
157155
pub file: HirFileId,
158156
pub match_expr: AstPtr<ast::Expr>,
159157
pub arms: AstPtr<ast::MatchArmList>,
160158
}
161159

162-
impl Diagnostic for MissingMatchArms {
163-
fn code(&self) -> DiagnosticCode {
164-
DiagnosticCode("missing-match-arm")
165-
}
166-
fn message(&self) -> String {
167-
String::from("Missing match arm")
168-
}
169-
fn display_source(&self) -> InFile<SyntaxNodePtr> {
170-
InFile { file_id: self.file, value: self.match_expr.clone().into() }
171-
}
172-
fn as_any(&self) -> &(dyn Any + Send + 'static) {
173-
self
174-
}
175-
}
176-
177160
#[derive(Debug)]
178161
pub struct InternalBailedOut {
179162
pub file: HirFileId,

crates/hir/src/lib.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,11 +1209,14 @@ impl Function {
12091209
if let (Some(match_expr), Some(arms)) =
12101210
(match_expr.expr(), match_expr.match_arm_list())
12111211
{
1212-
sink.push(MissingMatchArms {
1213-
file: source_ptr.file_id,
1214-
match_expr: AstPtr::new(&match_expr),
1215-
arms: AstPtr::new(&arms),
1216-
})
1212+
acc.push(
1213+
MissingMatchArms {
1214+
file: source_ptr.file_id,
1215+
match_expr: AstPtr::new(&match_expr),
1216+
arms: AstPtr::new(&arms),
1217+
}
1218+
.into(),
1219+
)
12171220
}
12181221
}
12191222
}

0 commit comments

Comments
 (0)