Skip to content

Commit 05e6499

Browse files
committed
add error for unknown jump target
1 parent 96be62b commit 05e6499

File tree

5 files changed

+16
-5
lines changed

5 files changed

+16
-5
lines changed

compiler/rustc_mir_build/messages.ftl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ mir_build_call_to_unsafe_fn_requires_unsafe_unsafe_op_in_unsafe_fn_allowed =
8484
8585
mir_build_confused = missing patterns are not covered because `{$variable}` is interpreted as a constant pattern, not a new variable
8686
87-
mir_build_const_continue_missing_value = a `const_continue` must break to a label with a value
87+
mir_build_const_continue_missing_value = a `#[const_continue]` must break to a label with a value
88+
89+
mir_build_const_continue_unknown_jump_target = the target of this `#[const_continue]` is not statically known
90+
.note = this value must be an integer or enum literal
8891
8992
mir_build_const_defined_here = constant defined here
9093

compiler/rustc_mir_build/src/builder/scope.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ use tracing::{debug, instrument};
9999

100100
use super::matches::BuiltMatchTree;
101101
use crate::builder::{BlockAnd, BlockAndExtension, BlockFrame, Builder, CFG};
102+
use crate::errors::ConstContinueUnknownJumpTarget;
102103

103104
#[derive(Debug)]
104105
pub(crate) struct Scopes<'tcx> {
@@ -813,8 +814,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
813814
let Some(real_target) =
814815
self.static_pattern_match(&cx, value, &*scope.arms, &scope.built_match_tree)
815816
else {
816-
// self.tcx.dcx().emit_fatal()
817-
todo!()
817+
self.tcx.dcx().emit_fatal(ConstContinueUnknownJumpTarget { span })
818818
};
819819

820820
self.block_context.push(BlockFrame::SubExpr);

compiler/rustc_mir_build/src/errors.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,3 +1194,11 @@ pub(crate) struct ConstContinueMissingValue {
11941194
#[primary_span]
11951195
pub span: Span,
11961196
}
1197+
1198+
#[derive(Diagnostic)]
1199+
#[diag(mir_build_const_continue_unknown_jump_target)]
1200+
#[note]
1201+
pub(crate) struct ConstContinueUnknownJumpTarget {
1202+
#[primary_span]
1203+
pub span: Span,
1204+
}

tests/ui/loop-match/invalid.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ fn break_without_value_unit() {
136136
() => {
137137
#[const_continue]
138138
break 'blk;
139-
//~^ ERROR a `const_continue` must break to a label with a value
139+
//~^ ERROR a `#[const_continue]` must break to a label with a value
140140
}
141141
}
142142
}

tests/ui/loop-match/invalid.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ LL | |
7474
LL | | }
7575
| |_____^
7676

77-
error: a `const_continue` must break to a label with a value
77+
error: a `#[const_continue]` must break to a label with a value
7878
--> $DIR/invalid.rs:138:21
7979
|
8080
LL | break 'blk;

0 commit comments

Comments
 (0)