Skip to content

Commit d8ea4b1

Browse files
Apply suggestions from code review
Co-authored-by: Travis Cross <[email protected]>
1 parent 9ef047b commit d8ea4b1

26 files changed

+84
-66
lines changed

compiler/rustc_feature/src/builtin_attrs.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,10 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
619619
EncodeCrossCrate::Yes, min_generic_const_args, experimental!(type_const),
620620
),
621621

622-
// #[loop_match] and #[const_continue]
622+
// The `#[loop_match]` and `#[const_continue]` attributes are part of the
623+
// lang experiment for RFC 3720 tracked in:
624+
//
625+
// - https://github.com/rust-lang/rust/issues/132306
623626
gated!(
624627
const_continue, Normal, template!(Word), ErrorFollowing,
625628
EncodeCrossCrate::No, loop_match, experimental!(const_continue)

compiler/rustc_feature/src/unstable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ declare_features! (
556556
/// to pass custom arguments to the linker.
557557
(unstable, link_arg_attribute, "1.76.0", Some(99427)),
558558
/// Allows fused `loop`/`match` for direct intraprocedural jumps.
559-
(incomplete, loop_match, "CURRENT_RUSTC_VERSION", Some(138777)),
559+
(incomplete, loop_match, "CURRENT_RUSTC_VERSION", Some(132306)),
560560
/// Give access to additional metadata about declarative macro meta-variables.
561561
(unstable, macro_metavar_expr, "1.61.0", Some(83527)),
562562
/// Provides a way to concatenate identifiers using metavariable expressions.

compiler/rustc_hir_typeck/src/loops.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ enum Context {
3939
AnonConst,
4040
/// E.g. `const { ... }`.
4141
ConstBlock,
42-
/// `#[loop_match] loop { state = 'label: { /* ... */ } }`
42+
/// E.g. `#[loop_match] loop { state = 'label: { /* ... */ } }`.
4343
LoopMatch {
44-
/// The label of the labeled block (so not the loop!)
44+
/// The label of the labeled block (not of the loop itself).
4545
labeled_block: Label,
4646
},
4747
}
@@ -209,7 +209,7 @@ impl<'hir> Visitor<'hir> for CheckLoopVisitor<'hir> {
209209
Err(hir::LoopIdError::UnresolvedLabel) => None,
210210
};
211211

212-
// a #[const_continue] must be to a block that participates in #[loop_match]
212+
// A `#[const_continue]` must break to a block in a `#[loop_match]`.
213213
let attrs = self.tcx.hir_attrs(e.hir_id);
214214
if attrs.iter().any(|attr| attr.has_name(sym::const_continue)) {
215215
if let Some(break_label) = break_label.label {
@@ -419,9 +419,9 @@ impl<'hir> CheckLoopVisitor<'hir> {
419419
return None;
420420
}
421421

422-
// NOTE: diagnostics are emitted during MIR construction.
422+
// NOTE: Diagnostics are emitted during MIR construction.
423423

424-
// accept either `state = expr` or `state = expr;`
424+
// Accept either `state = expr` or `state = expr;`.
425425
let loop_body_expr = match body.stmts {
426426
[] => match body.expr {
427427
Some(expr) => expr,

compiler/rustc_middle/src/thir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ pub enum ExprKind<'tcx> {
380380
},
381381
/// A `#[loop_match] loop { state = 'blk: { match state { ... } } }` expression.
382382
LoopMatch {
383-
/// The state variable that is updated, and also the scrutinee of the match
383+
/// The state variable that is updated, and also the scrutinee of the match.
384384
state: ExprId,
385385
region_scope: region::Scope,
386386
arms: Box<[ArmId]>,

compiler/rustc_mir_build/messages.ftl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,11 @@ mir_build_loop_match_bad_statements =
227227
statements are not allowed in this position within a `#[loop_match]`
228228
229229
mir_build_loop_match_invalid_match =
230-
invalid match on `loop_match` state
231-
.note = only matches on local variables are valid
230+
invalid match on `#[loop_match]` state
231+
.note = a local variable must be the scrutinee within a `#[loop_match]`
232232
233233
mir_build_loop_match_invalid_update =
234-
invalid update of the `loop_match` state
234+
invalid update of the `#[loop_match]` state
235235
.label = the assignment must update this variable
236236
237237
mir_build_loop_match_missing_assignment =

compiler/rustc_mir_build/src/builder/expr/into.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
310310

311311
// The `built_tree` maps match arms to their basic block (where control flow
312312
// jumps to when a value matches the arm). This structure is stored so that a
313-
// #[const_continue] can figure out what basic block to jump to.
313+
// `#[const_continue]` can figure out what basic block to jump to.
314314
let built_tree = this.lower_match_tree(
315315
body_block,
316316
scrutinee_span,
@@ -327,7 +327,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
327327
// hence the `in_breakable_scope`.
328328
//
329329
// Then `in_const_continuable_scope` stores information for the lowering of
330-
// #[const_continue], and finally the match is lowered in the standard way.
330+
// `#[const_continue]`, and finally the match is lowered in the standard way.
331331
unpack!(
332332
body_block = this.in_scope(
333333
(region_scope, source_info),

compiler/rustc_mir_build/src/builder/matches/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2868,7 +2868,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
28682868
true
28692869
}
28702870

2871-
/// Attempt to statically pick the BasicBlock that a value would resolve to at runtime.
2871+
/// Attempt to statically pick the `BasicBlock` that a value would resolve to at runtime.
28722872
pub(crate) fn static_pattern_match(
28732873
&self,
28742874
cx: &RustcPatCtxt<'_, 'tcx>,
@@ -2927,7 +2927,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
29272927
// a lot of care around intrinsics. For an issue to happen here, it would require a
29282928
// macro expanding to a `simd_shuffle` call without wrapping the constant argument in a
29292929
// `const {}` block, but the user pass through arbitrary expressions.
2930-
// FIXME(oli-obk): replace the magic const generic argument of `simd_shuffle` with a
2930+
2931+
// FIXME(oli-obk): Replace the magic const generic argument of `simd_shuffle` with a
29312932
// real const generic, and get rid of this entire function.
29322933
other => span_bug!(constant.span, "{other:#?}"),
29332934
};
@@ -2978,7 +2979,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
29782979
},
29792980
Constructor::Wildcard => true,
29802981

2981-
// these we may eventually support
2982+
// These we may eventually support:
29822983
Constructor::Struct
29832984
| Constructor::Ref
29842985
| Constructor::Slice(_)
@@ -2990,7 +2991,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
29902991
| Constructor::F128Range(..)
29912992
| Constructor::Str(_) => bug!("unsupported pattern constructor {:?}", pat.ctor()),
29922993

2993-
// these should never occur here
2994+
// These should never occur here:
29942995
Constructor::Opaque(_)
29952996
| Constructor::Never
29962997
| Constructor::NonExhaustive

compiler/rustc_mir_build/src/builder/scope.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -874,8 +874,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
874874
_ => span_bug!(state_decl.source_info.span, "unsupported #[loop_match] state"),
875875
};
876876

877-
// The PatCtxt is normally used in pattern exhaustiveness checking, but reused here
878-
// because it performs normalization and const evaluation.
877+
// The `PatCtxt` is normally used in pattern exhaustiveness checking, but reused
878+
// here because it performs normalization and const evaluation.
879879
let dropless_arena = rustc_arena::DroplessArena::default();
880880
let typeck_results = self.tcx.typeck(self.def_id);
881881
let cx = RustcPatCtxt {

compiler/rustc_mir_build/src/thir/cx/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ impl<'tcx> ThirBuildCx<'tcx> {
876876
if is_loop_match {
877877
let dcx = self.tcx.dcx();
878878

879-
// accept either `state = expr` or `state = expr;`
879+
// Accept either `state = expr` or `state = expr;`.
880880
let loop_body_expr = match body.stmts {
881881
[] => match body.expr {
882882
Some(expr) => expr,

tests/ui/feature-gates/feature-gate-loop-match.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// A #[const_continue] to a labeled loop should error.
1+
// Test that `#[loop_match]` and `#[const_continue]` cannot be used without
2+
// `#![feature(loop_match)]`.
23

34
enum State {
45
A,

tests/ui/feature-gates/feature-gate-loop-match.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
error[E0658]: the `#[loop_match]` attribute is an experimental feature
2-
--> $DIR/feature-gate-loop-match.rs:11:5
2+
--> $DIR/feature-gate-loop-match.rs:12:5
33
|
44
LL | #[loop_match]
55
| ^^^^^^^^^^^^^
66
|
7-
= note: see issue #138777 <https://github.com/rust-lang/rust/issues/138777> for more information
7+
= note: see issue #132306 <https://github.com/rust-lang/rust/issues/132306> for more information
88
= help: add `#![feature(loop_match)]` to the crate attributes to enable
99
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
1010

1111
error[E0658]: the `#[const_continue]` attribute is an experimental feature
12-
--> $DIR/feature-gate-loop-match.rs:16:21
12+
--> $DIR/feature-gate-loop-match.rs:17:21
1313
|
1414
LL | #[const_continue]
1515
| ^^^^^^^^^^^^^^^^^
1616
|
17-
= note: see issue #138777 <https://github.com/rust-lang/rust/issues/138777> for more information
17+
= note: see issue #132306 <https://github.com/rust-lang/rust/issues/132306> for more information
1818
= help: add `#![feature(loop_match)]` to the crate attributes to enable
1919
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
2020

2121
error[E0658]: the `#[const_continue]` attribute is an experimental feature
22-
--> $DIR/feature-gate-loop-match.rs:21:21
22+
--> $DIR/feature-gate-loop-match.rs:22:21
2323
|
2424
LL | #[const_continue]
2525
| ^^^^^^^^^^^^^^^^^
2626
|
27-
= note: see issue #138777 <https://github.com/rust-lang/rust/issues/138777> for more information
27+
= note: see issue #132306 <https://github.com/rust-lang/rust/issues/132306> for more information
2828
= help: add `#![feature(loop_match)]` to the crate attributes to enable
2929
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
3030

tests/ui/loop-match/break-to-block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Test that a break without #[const_continue] still works as expected.
1+
// Test that a `break` without `#[const_continue]` still works as expected.
22

33
//@ run-pass
44

tests/ui/loop-match/const-continue-to-block.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// A #[const_continue] to a normal labeled block (that does is not part of a #[loop_match]) should
2-
// error.
1+
// Test that a `#[const_continue]` that breaks to a normal labeled block (that
2+
// is not part of a `#[loop_match]`) produces an error.
33

44
#![allow(incomplete_features)]
55
#![feature(loop_match)]
@@ -18,7 +18,7 @@ fn const_continue_to_block() -> u8 {
1818
_ => 'b: {
1919
#[const_continue]
2020
break 'b 2;
21-
//~^ ERROR `#[const_continue]` must break to a labeled block that participates in a `#[loop_match]`
21+
//~^ ERROR `#[const_continue]` must break to a labeled block in a `#[loop_match]`
2222
}
2323
}
2424
}

tests/ui/loop-match/const-continue-to-block.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: `#[const_continue]` must break to a labeled block that participates in a `#[loop_match]`
1+
error: `#[const_continue]` must break to a labeled block in a `#[loop_match]`
22
--> $DIR/const-continue-to-block.rs:20:27
33
|
44
LL | break 'b 2;

tests/ui/loop-match/const-continue-to-loop.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Test that a `#[const_continue]` that breaks to the label of the loop itself
2+
// rather than to the label of the block within the `#[loop_match]` produces an
3+
// error.
4+
15
#![allow(incomplete_features)]
26
#![feature(loop_match)]
37
#![crate_type = "lib"]
@@ -15,7 +19,7 @@ fn const_continue_to_loop() -> u8 {
1519
_ => {
1620
#[const_continue]
1721
break 'a 2;
18-
//~^ ERROR `#[const_continue]` must break to a labeled block that participates in a `#[loop_match]`
22+
//~^ ERROR `#[const_continue]` must break to a labeled block in a `#[loop_match]`
1923
}
2024
}
2125
}

tests/ui/loop-match/const-continue-to-loop.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
error: `#[const_continue]` must break to a labeled block that participates in a `#[loop_match]`
2-
--> $DIR/const-continue-to-loop.rs:17:27
1+
error: `#[const_continue]` must break to a labeled block in a `#[loop_match]`
2+
--> $DIR/const-continue-to-loop.rs:21:27
33
|
44
LL | break 'a 2;
55
| ^^

tests/ui/loop-match/integer-patterns.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Test that signed and unsigned integer patterns work with #[loop_match].
1+
// Test that signed and unsigned integer patterns work with `#[loop_match]`.
22

33
//@ run-pass
44

tests/ui/loop-match/invalid-attribute.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// Checks that #[loop_match] and #[const_continue] attributes can be
2-
// placed on expressions only.
1+
// Test that the `#[loop_match]` and `#[const_continue]` attributes can only be
2+
// placed on expressions.
33

44
#![allow(incomplete_features)]
55
#![feature(loop_match)]

tests/ui/loop-match/invalid.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// Test that a good error is emitted when #[loop_match] is applied to syntax it does not support.
1+
// Test that the correct error is emitted when `#[loop_match]` is applied to
2+
// syntax it does not support.
23
#![allow(incomplete_features)]
34
#![feature(loop_match)]
45
#![crate_type = "lib"]
@@ -15,7 +16,7 @@ fn invalid_update() {
1516
#[loop_match]
1617
loop {
1718
fake = 'blk: {
18-
//~^ ERROR invalid update of the `loop_match` state
19+
//~^ ERROR invalid update of the `#[loop_match]` state
1920
match state {
2021
_ => State::B,
2122
}
@@ -29,7 +30,7 @@ fn invalid_scrutinee() {
2930
loop {
3031
state = 'blk: {
3132
match State::A {
32-
//~^ ERROR invalid match on `loop_match` state
33+
//~^ ERROR invalid match on `#[loop_match]` state
3334
_ => State::B,
3435
}
3536
}

tests/ui/loop-match/invalid.stderr

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0308]: mismatched types
2-
--> $DIR/invalid.rs:121:21
2+
--> $DIR/invalid.rs:122:21
33
|
44
LL | break 'blk;
55
| ^^^^^^^^^^ expected `State`, found `()`
@@ -9,49 +9,49 @@ help: give the `break` a value of the expected type
99
LL | break 'blk /* value */;
1010
| +++++++++++
1111

12-
error: invalid update of the `loop_match` state
13-
--> $DIR/invalid.rs:17:9
12+
error: invalid update of the `#[loop_match]` state
13+
--> $DIR/invalid.rs:18:9
1414
|
1515
LL | fake = 'blk: {
1616
| ^^^^
1717
LL |
1818
LL | match state {
1919
| ----- the assignment must update this variable
2020

21-
error: invalid match on `loop_match` state
22-
--> $DIR/invalid.rs:31:19
21+
error: invalid match on `#[loop_match]` state
22+
--> $DIR/invalid.rs:32:19
2323
|
2424
LL | match State::A {
2525
| ^^^^^^^^
2626
|
27-
= note: only matches on local variables are valid
27+
= note: a local variable must be the scrutinee within a `#[loop_match]`
2828

2929
error: statements are not allowed in this position within a `#[loop_match]`
30-
--> $DIR/invalid.rs:43:9
30+
--> $DIR/invalid.rs:44:9
3131
|
3232
LL | 1;
3333
| ^^
3434

3535
error: statements are not allowed in this position within a `#[loop_match]`
36-
--> $DIR/invalid.rs:58:13
36+
--> $DIR/invalid.rs:59:13
3737
|
3838
LL | 1;
3939
| ^^
4040

4141
error: this expression must be a single `match` wrapped in a labeled block
42-
--> $DIR/invalid.rs:71:17
42+
--> $DIR/invalid.rs:72:17
4343
|
4444
LL | state = State::B
4545
| ^^^^^^^^
4646

4747
error: this expression must be a single `match` wrapped in a labeled block
48-
--> $DIR/invalid.rs:81:13
48+
--> $DIR/invalid.rs:82:13
4949
|
5050
LL | State::B
5151
| ^^^^^^^^
5252

5353
error: this expression must be a single `match` wrapped in a labeled block
54-
--> $DIR/invalid.rs:91:17
54+
--> $DIR/invalid.rs:92:17
5555
|
5656
LL | state = 'blk: {
5757
| _________________^
@@ -60,13 +60,13 @@ LL | | }
6060
| |_________^
6161

6262
error: expected a single assignment expression
63-
--> $DIR/invalid.rs:101:9
63+
--> $DIR/invalid.rs:102:9
6464
|
6565
LL | ()
6666
| ^^
6767

6868
error: expected a single assignment expression
69-
--> $DIR/invalid.rs:108:10
69+
--> $DIR/invalid.rs:109:10
7070
|
7171
LL | loop {
7272
| __________^
@@ -75,13 +75,13 @@ LL | | }
7575
| |_____^
7676

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

8383
error: match arms that are part of a `#[loop_match]` cannot have guards
84-
--> $DIR/invalid.rs:156:29
84+
--> $DIR/invalid.rs:157:29
8585
|
8686
LL | State::B if cond => break 'a,
8787
| ^^^^

0 commit comments

Comments
 (0)