loop match: error on #[const_continue] outside #[loop_match]

This commit is contained in:
Folkert de Vries
2025-07-25 15:18:51 +02:00
parent adcb3d3b4c
commit 040f71e812
9 changed files with 107 additions and 34 deletions

View File

@@ -87,7 +87,7 @@ mir_build_confused = missing patterns are not covered because `{$variable}` is i
mir_build_const_continue_bad_const = could not determine the target branch for this `#[const_continue]`
.label = this value is too generic
mir_build_const_continue_missing_value = a `#[const_continue]` must break to a label with a value
mir_build_const_continue_missing_label_or_value = a `#[const_continue]` must break to a label with a value
mir_build_const_continue_not_const = could not determine the target branch for this `#[const_continue]`
.help = try extracting the expression into a `const` item

View File

@@ -1254,8 +1254,8 @@ pub(crate) struct ConstContinueBadConst {
}
#[derive(Diagnostic)]
#[diag(mir_build_const_continue_missing_value)]
pub(crate) struct ConstContinueMissingValue {
#[diag(mir_build_const_continue_missing_label_or_value)]
pub(crate) struct ConstContinueMissingLabelOrValue {
#[primary_span]
pub span: Span,
}

View File

@@ -852,9 +852,9 @@ impl<'tcx> ThirBuildCx<'tcx> {
if find_attr!(self.tcx.hir_attrs(expr.hir_id), AttributeKind::ConstContinue(_)) {
match dest.target_id {
Ok(target_id) => {
let Some(value) = value else {
let (Some(value), Some(_)) = (value, dest.label) else {
let span = expr.span;
self.tcx.dcx().emit_fatal(ConstContinueMissingValue { span })
self.tcx.dcx().emit_fatal(ConstContinueMissingLabelOrValue { span })
};
ExprKind::ConstContinue {