Skip to content

Commit f8ca417

Browse files
committed
reword error for invalid range patterns
For half-open ranges, specifies that the upper bound cannot be the minimum. Also specify that this only applies to range patterns and not also expressions.
1 parent 1d60f9e commit f8ca417

File tree

15 files changed

+58
-46
lines changed

15 files changed

+58
-46
lines changed

compiler/rustc_mir_build/messages.ftl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,11 @@ mir_build_loop_match_unsupported_type =
250250
.note = only integers, floats, bool, char, and enums without fields are supported
251251
252252
mir_build_lower_range_bound_must_be_less_than_or_equal_to_upper =
253-
lower range bound must be less than or equal to upper
253+
lower bound for range pattern must be less than or equal to upper bound
254254
.label = lower bound larger than upper bound
255255
.teach_note = When matching against a range, the compiler verifies that the range is non-empty. Range patterns include both end-points, so this is equivalent to requiring the start of the range to be less than or equal to the end of the range.
256256
257-
mir_build_lower_range_bound_must_be_less_than_upper = lower range bound must be less than upper
257+
mir_build_lower_range_bound_must_be_less_than_upper = lower bound for range pattern must be less than upper bound
258258
259259
mir_build_more_information = for more information, visit https://doc.rust-lang.org/book/ch19-02-refutability.html
260260
@@ -506,6 +506,8 @@ mir_build_unused_unsafe = unnecessary `unsafe` block
506506
507507
mir_build_unused_unsafe_enclosing_block_label = because it's nested under this `unsafe` block
508508
509+
mir_build_upper_range_bound_cannot_be_min = exclusive upper bound for a range bound cannot be the minimum
510+
509511
mir_build_variant_defined_here = not covered
510512
511513
mir_build_wrap_suggestion = consider wrapping the function body in an unsafe block

compiler/rustc_mir_build/src/errors.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,13 @@ pub(crate) struct LowerRangeBoundMustBeLessThanUpper {
776776
pub(crate) span: Span,
777777
}
778778

779+
#[derive(Diagnostic)]
780+
#[diag(mir_build_upper_range_bound_cannot_be_min, code = E0579)]
781+
pub(crate) struct UpperRangeBoundCannotBeMin {
782+
#[primary_span]
783+
pub(crate) span: Span,
784+
}
785+
779786
#[derive(LintDiagnostic)]
780787
#[diag(mir_build_leading_irrefutable_let_patterns)]
781788
#[note]

compiler/rustc_mir_build/src/thir/pattern/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,9 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
273273
teach: self.tcx.sess.teach(E0030),
274274
})
275275
}
276+
RangeEnd::Excluded if lo_expr.is_none() => {
277+
self.tcx.dcx().emit_err(UpperRangeBoundCannotBeMin { span })
278+
}
276279
RangeEnd::Excluded => {
277280
self.tcx.dcx().emit_err(LowerRangeBoundMustBeLessThanUpper { span })
278281
}

tests/ui/error-codes/E0030-teach.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
fn main() {
44
match 5u32 {
55
1000 ..= 5 => {}
6-
//~^ ERROR lower range bound must be less than or equal to upper
6+
//~^ ERROR lower bound for range pattern must be less than or equal to upper bound
77
}
88
}

tests/ui/error-codes/E0030-teach.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0030]: lower range bound must be less than or equal to upper
1+
error[E0030]: lower bound for range pattern must be less than or equal to upper bound
22
--> $DIR/E0030-teach.rs:5:9
33
|
44
LL | 1000 ..= 5 => {}

tests/ui/error-codes/E0030.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
fn main() {
22
match 5u32 {
33
1000 ..= 5 => {}
4-
//~^ ERROR lower range bound must be less than or equal to upper
4+
//~^ ERROR lower bound for range pattern must be less than or equal to upper bound
55
}
66
}

tests/ui/error-codes/E0030.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0030]: lower range bound must be less than or equal to upper
1+
error[E0030]: lower bound for range pattern must be less than or equal to upper bound
22
--> $DIR/E0030.rs:3:9
33
|
44
LL | 1000 ..= 5 => {}

tests/ui/half-open-range-patterns/half-open-range-pats-thir-lower-empty.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,36 @@ macro_rules! m {
99

1010
fn main() {
1111
m!(0, ..u8::MIN);
12-
//~^ ERROR lower range bound must be less than upper
12+
//~^ ERROR exclusive upper bound for a range bound cannot be the minimum
1313
m!(0, ..u16::MIN);
14-
//~^ ERROR lower range bound must be less than upper
14+
//~^ ERROR exclusive upper bound for a range bound cannot be the minimum
1515
m!(0, ..u32::MIN);
16-
//~^ ERROR lower range bound must be less than upper
16+
//~^ ERROR exclusive upper bound for a range bound cannot be the minimum
1717
m!(0, ..u64::MIN);
18-
//~^ ERROR lower range bound must be less than upper
18+
//~^ ERROR exclusive upper bound for a range bound cannot be the minimum
1919
m!(0, ..u128::MIN);
20-
//~^ ERROR lower range bound must be less than upper
20+
//~^ ERROR exclusive upper bound for a range bound cannot be the minimum
2121

2222
m!(0, ..i8::MIN);
23-
//~^ ERROR lower range bound must be less than upper
23+
//~^ ERROR exclusive upper bound for a range bound cannot be the minimum
2424
m!(0, ..i16::MIN);
25-
//~^ ERROR lower range bound must be less than upper
25+
//~^ ERROR exclusive upper bound for a range bound cannot be the minimum
2626
m!(0, ..i32::MIN);
27-
//~^ ERROR lower range bound must be less than upper
27+
//~^ ERROR exclusive upper bound for a range bound cannot be the minimum
2828
m!(0, ..i64::MIN);
29-
//~^ ERROR lower range bound must be less than upper
29+
//~^ ERROR exclusive upper bound for a range bound cannot be the minimum
3030
m!(0, ..i128::MIN);
31-
//~^ ERROR lower range bound must be less than upper
31+
//~^ ERROR exclusive upper bound for a range bound cannot be the minimum
3232

3333
m!(0f16, ..f16::NEG_INFINITY);
34-
//~^ ERROR lower range bound must be less than upper
34+
//~^ ERROR exclusive upper bound for a range bound cannot be the minimum
3535
m!(0f32, ..f32::NEG_INFINITY);
36-
//~^ ERROR lower range bound must be less than upper
36+
//~^ ERROR exclusive upper bound for a range bound cannot be the minimum
3737
m!(0f64, ..f64::NEG_INFINITY);
38-
//~^ ERROR lower range bound must be less than upper
38+
//~^ ERROR exclusive upper bound for a range bound cannot be the minimum
3939
m!(0f128, ..f128::NEG_INFINITY);
40-
//~^ ERROR lower range bound must be less than upper
40+
//~^ ERROR exclusive upper bound for a range bound cannot be the minimum
4141

4242
m!('a', ..'\u{0}');
43-
//~^ ERROR lower range bound must be less than upper
43+
//~^ ERROR exclusive upper bound for a range bound cannot be the minimum
4444
}

tests/ui/half-open-range-patterns/half-open-range-pats-thir-lower-empty.stderr

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,88 @@
1-
error[E0579]: lower range bound must be less than upper
1+
error[E0579]: exclusive upper bound for a range bound cannot be the minimum
22
--> $DIR/half-open-range-pats-thir-lower-empty.rs:11:11
33
|
44
LL | m!(0, ..u8::MIN);
55
| ^^^^^^^^^
66

7-
error[E0579]: lower range bound must be less than upper
7+
error[E0579]: exclusive upper bound for a range bound cannot be the minimum
88
--> $DIR/half-open-range-pats-thir-lower-empty.rs:13:11
99
|
1010
LL | m!(0, ..u16::MIN);
1111
| ^^^^^^^^^^
1212

13-
error[E0579]: lower range bound must be less than upper
13+
error[E0579]: exclusive upper bound for a range bound cannot be the minimum
1414
--> $DIR/half-open-range-pats-thir-lower-empty.rs:15:11
1515
|
1616
LL | m!(0, ..u32::MIN);
1717
| ^^^^^^^^^^
1818

19-
error[E0579]: lower range bound must be less than upper
19+
error[E0579]: exclusive upper bound for a range bound cannot be the minimum
2020
--> $DIR/half-open-range-pats-thir-lower-empty.rs:17:11
2121
|
2222
LL | m!(0, ..u64::MIN);
2323
| ^^^^^^^^^^
2424

25-
error[E0579]: lower range bound must be less than upper
25+
error[E0579]: exclusive upper bound for a range bound cannot be the minimum
2626
--> $DIR/half-open-range-pats-thir-lower-empty.rs:19:11
2727
|
2828
LL | m!(0, ..u128::MIN);
2929
| ^^^^^^^^^^^
3030

31-
error[E0579]: lower range bound must be less than upper
31+
error[E0579]: exclusive upper bound for a range bound cannot be the minimum
3232
--> $DIR/half-open-range-pats-thir-lower-empty.rs:22:11
3333
|
3434
LL | m!(0, ..i8::MIN);
3535
| ^^^^^^^^^
3636

37-
error[E0579]: lower range bound must be less than upper
37+
error[E0579]: exclusive upper bound for a range bound cannot be the minimum
3838
--> $DIR/half-open-range-pats-thir-lower-empty.rs:24:11
3939
|
4040
LL | m!(0, ..i16::MIN);
4141
| ^^^^^^^^^^
4242

43-
error[E0579]: lower range bound must be less than upper
43+
error[E0579]: exclusive upper bound for a range bound cannot be the minimum
4444
--> $DIR/half-open-range-pats-thir-lower-empty.rs:26:11
4545
|
4646
LL | m!(0, ..i32::MIN);
4747
| ^^^^^^^^^^
4848

49-
error[E0579]: lower range bound must be less than upper
49+
error[E0579]: exclusive upper bound for a range bound cannot be the minimum
5050
--> $DIR/half-open-range-pats-thir-lower-empty.rs:28:11
5151
|
5252
LL | m!(0, ..i64::MIN);
5353
| ^^^^^^^^^^
5454

55-
error[E0579]: lower range bound must be less than upper
55+
error[E0579]: exclusive upper bound for a range bound cannot be the minimum
5656
--> $DIR/half-open-range-pats-thir-lower-empty.rs:30:11
5757
|
5858
LL | m!(0, ..i128::MIN);
5959
| ^^^^^^^^^^^
6060

61-
error[E0579]: lower range bound must be less than upper
61+
error[E0579]: exclusive upper bound for a range bound cannot be the minimum
6262
--> $DIR/half-open-range-pats-thir-lower-empty.rs:33:14
6363
|
6464
LL | m!(0f16, ..f16::NEG_INFINITY);
6565
| ^^^^^^^^^^^^^^^^^^^
6666

67-
error[E0579]: lower range bound must be less than upper
67+
error[E0579]: exclusive upper bound for a range bound cannot be the minimum
6868
--> $DIR/half-open-range-pats-thir-lower-empty.rs:35:14
6969
|
7070
LL | m!(0f32, ..f32::NEG_INFINITY);
7171
| ^^^^^^^^^^^^^^^^^^^
7272

73-
error[E0579]: lower range bound must be less than upper
73+
error[E0579]: exclusive upper bound for a range bound cannot be the minimum
7474
--> $DIR/half-open-range-pats-thir-lower-empty.rs:37:14
7575
|
7676
LL | m!(0f64, ..f64::NEG_INFINITY);
7777
| ^^^^^^^^^^^^^^^^^^^
7878

79-
error[E0579]: lower range bound must be less than upper
79+
error[E0579]: exclusive upper bound for a range bound cannot be the minimum
8080
--> $DIR/half-open-range-pats-thir-lower-empty.rs:39:15
8181
|
8282
LL | m!(0f128, ..f128::NEG_INFINITY);
8383
| ^^^^^^^^^^^^^^^^^^^^
8484

85-
error[E0579]: lower range bound must be less than upper
85+
error[E0579]: exclusive upper bound for a range bound cannot be the minimum
8686
--> $DIR/half-open-range-pats-thir-lower-empty.rs:42:13
8787
|
8888
LL | m!('a', ..'\u{0}');

tests/ui/loop-match/invalid.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ fn invalid_range_pattern(state: f32) {
202202
break 'blk 2.5;
203203
}
204204
4.0..3.0 => {
205-
//~^ ERROR lower range bound must be less than upper
205+
//~^ ERROR lower bound for range pattern must be less than upper bound
206206
todo!()
207207
}
208208
}

0 commit comments

Comments
 (0)