Skip to content

Commit 0788b2c

Browse files
committed
add error for unknown jump target
1 parent 1015976 commit 0788b2c

File tree

5 files changed

+16
-5
lines changed

5 files changed

+16
-5
lines changed

compiler/rustc_mir_build/messages.ftl

+4-1
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

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ use tracing::{debug, instrument};
9898

9999
use super::matches::BuiltMatchTree;
100100
use crate::builder::{BlockAnd, BlockAndExtension, BlockFrame, Builder, CFG};
101+
use crate::errors::ConstContinueUnknownJumpTarget;
101102

102103
#[derive(Debug)]
103104
pub(crate) struct Scopes<'tcx> {
@@ -810,8 +811,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
810811
let Some(real_target) =
811812
self.static_pattern_match(&cx, value, &*scope.arms, &scope.built_match_tree)
812813
else {
813-
// self.tcx.dcx().emit_fatal()
814-
todo!()
814+
self.tcx.dcx().emit_fatal(ConstContinueUnknownJumpTarget { span })
815815
};
816816

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

compiler/rustc_mir_build/src/errors.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1206,3 +1206,11 @@ pub(crate) struct ConstContinueMissingValue {
12061206
#[primary_span]
12071207
pub span: Span,
12081208
}
1209+
1210+
#[derive(Diagnostic)]
1211+
#[diag(mir_build_const_continue_unknown_jump_target)]
1212+
#[note]
1213+
pub(crate) struct ConstContinueUnknownJumpTarget {
1214+
#[primary_span]
1215+
pub span: Span,
1216+
}

tests/ui/loop-match/invalid.rs

+1-1
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

+1-1
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)