Skip to content

Commit 7c33ba2

Browse files
committed
delay most error handing until later
1 parent 9e675b0 commit 7c33ba2

File tree

3 files changed

+8
-57
lines changed

3 files changed

+8
-57
lines changed

compiler/rustc_passes/messages.ftl

-9
Original file line numberDiff line numberDiff line change
@@ -469,15 +469,6 @@ passes_loop_match_attr =
469469
`#[loop_match]` should be applied to a loop
470470
.label = not a loop
471471
472-
passes_loop_match_bad_rhs =
473-
this expression must be a single `match` wrapped in a labeled block
474-
475-
passes_loop_match_bad_statements =
476-
statements are not allowed in this position within a `#[loop_match]`
477-
478-
passes_loop_match_missing_assignment =
479-
expected a single assignment expression
480-
481472
passes_macro_export =
482473
`#[macro_export]` only has an effect on macro definitions
483474

compiler/rustc_passes/src/errors.rs

-21
Original file line numberDiff line numberDiff line change
@@ -1222,27 +1222,6 @@ pub(crate) struct UnlabeledCfInWhileCondition<'a> {
12221222
pub cf_type: &'a str,
12231223
}
12241224

1225-
#[derive(Diagnostic)]
1226-
#[diag(passes_loop_match_bad_statements)]
1227-
pub(crate) struct LoopMatchBadStatements {
1228-
#[primary_span]
1229-
pub span: Span,
1230-
}
1231-
1232-
#[derive(Diagnostic)]
1233-
#[diag(passes_loop_match_bad_rhs)]
1234-
pub(crate) struct LoopMatchBadRhs {
1235-
#[primary_span]
1236-
pub span: Span,
1237-
}
1238-
1239-
#[derive(Diagnostic)]
1240-
#[diag(passes_loop_match_missing_assignment)]
1241-
pub(crate) struct LoopMatchMissingAssignment {
1242-
#[primary_span]
1243-
pub span: Span,
1244-
}
1245-
12461225
#[derive(LintDiagnostic)]
12471226
#[diag(passes_undefined_naked_function_abi)]
12481227
pub(crate) struct UndefinedNakedFunctionAbi;

compiler/rustc_passes/src/loops.rs

+8-27
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ use rustc_span::{BytePos, Span, sym};
1616

1717
use crate::errors::{
1818
BreakInsideClosure, BreakInsideCoroutine, BreakNonLoop, ConstContinueBadLabel,
19-
ContinueLabeledBlock, LoopMatchBadRhs, LoopMatchBadStatements, LoopMatchMissingAssignment,
20-
OutsideLoop, OutsideLoopSuggestion, UnlabeledCfInWhileCondition, UnlabeledInLabeledBlock,
19+
ContinueLabeledBlock, OutsideLoop, OutsideLoopSuggestion, UnlabeledCfInWhileCondition,
20+
UnlabeledInLabeledBlock,
2121
};
2222

2323
/// The context in which a block is encountered.
@@ -438,43 +438,24 @@ impl<'hir> CheckLoopVisitor<'hir> {
438438
return None;
439439
}
440440

441-
let dcx = self.tcx.dcx();
441+
// NOTE: diagnostics are emitted during MIR construction.
442442

443443
// accept either `state = expr` or `state = expr;`
444444
let loop_body_expr = match body.stmts {
445445
[] => match body.expr {
446446
Some(expr) => expr,
447-
None => {
448-
dcx.emit_err(LoopMatchMissingAssignment { span: body.span });
449-
return None;
450-
}
447+
None => return None,
451448
},
452449
[single] if body.expr.is_none() => match single.kind {
453450
hir::StmtKind::Expr(expr) | hir::StmtKind::Semi(expr) => expr,
454-
_ => {
455-
dcx.emit_err(LoopMatchMissingAssignment { span: body.span });
456-
return None;
457-
}
451+
_ => return None,
458452
},
459-
[first @ last] | [first, .., last] => {
460-
dcx.emit_err(LoopMatchBadStatements { span: first.span.to(last.span) });
461-
return None;
462-
}
453+
[..] => return None,
463454
};
464455

465-
let hir::ExprKind::Assign(_, rhs_expr, _) = loop_body_expr.kind else {
466-
dcx.emit_err(LoopMatchMissingAssignment { span: loop_body_expr.span });
467-
return None;
468-
};
456+
let hir::ExprKind::Assign(_, rhs_expr, _) = loop_body_expr.kind else { return None };
469457

470-
let hir::ExprKind::Block(_, label) = rhs_expr.kind else {
471-
dcx.emit_err(LoopMatchBadRhs { span: rhs_expr.span });
472-
return None;
473-
};
474-
475-
if label.is_none() {
476-
todo!()
477-
}
458+
let hir::ExprKind::Block(_, label) = rhs_expr.kind else { return None };
478459

479460
label
480461
}

0 commit comments

Comments
 (0)