Skip to content

Commit 17b9d35

Browse files
committed
Refactor: Distinguish scrutinee expression from match expression
1 parent 5e8c586 commit 17b9d35

File tree

1 file changed

+10
-10
lines changed
  • crates/hir-ty/src/diagnostics

1 file changed

+10
-10
lines changed

crates/hir-ty/src/diagnostics/expr.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,15 @@ impl ExprValidator {
147147

148148
fn validate_match(
149149
&mut self,
150-
id: ExprId,
151150
match_expr: ExprId,
151+
scrutinee_expr: ExprId,
152152
arms: &[MatchArm],
153153
db: &dyn HirDatabase,
154154
) {
155155
let body = db.body(self.owner);
156156

157-
let match_expr_ty = &self.infer[match_expr];
158-
if match_expr_ty.is_unknown() {
157+
let scrut_ty = &self.infer[scrutinee_expr];
158+
if scrut_ty.is_unknown() {
159159
return;
160160
}
161161

@@ -167,17 +167,17 @@ impl ExprValidator {
167167
for arm in arms {
168168
if let Some(pat_ty) = self.infer.type_of_pat.get(arm.pat) {
169169
// We only include patterns whose type matches the type
170-
// of the match expression. If we had an InvalidMatchArmPattern
170+
// of the scrutinee expression. If we had an InvalidMatchArmPattern
171171
// diagnostic or similar we could raise that in an else
172172
// block here.
173173
//
174174
// When comparing the types, we also have to consider that rustc
175-
// will automatically de-reference the match expression type if
175+
// will automatically de-reference the scrutinee expression type if
176176
// necessary.
177177
//
178178
// FIXME we should use the type checker for this.
179-
if (pat_ty == match_expr_ty
180-
|| match_expr_ty
179+
if (pat_ty == scrut_ty
180+
|| scrut_ty
181181
.as_reference()
182182
.map(|(match_expr_ty, ..)| match_expr_ty == pat_ty)
183183
.unwrap_or(false))
@@ -205,16 +205,16 @@ impl ExprValidator {
205205
return;
206206
}
207207

208-
let report = compute_match_usefulness(&cx, &m_arms, match_expr_ty);
208+
let report = compute_match_usefulness(&cx, &m_arms, scrut_ty);
209209

210210
// FIXME Report unreacheble arms
211211
// https://github.com/rust-lang/rust/blob/f31622a50/compiler/rustc_mir_build/src/thir/pattern/check_match.rs#L200
212212

213213
let witnesses = report.non_exhaustiveness_witnesses;
214214
if !witnesses.is_empty() {
215215
self.diagnostics.push(BodyValidationDiagnostic::MissingMatchArms {
216-
match_expr: id,
217-
uncovered_patterns: missing_match_arms(&cx, match_expr_ty, witnesses, arms),
216+
match_expr,
217+
uncovered_patterns: missing_match_arms(&cx, scrut_ty, witnesses, arms),
218218
});
219219
}
220220
}

0 commit comments

Comments
 (0)