Rollup merge of #149528 - fee1-dead-contrib:rangeboundreword, r=jieyouxu

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.

Fixes rust-lang/rust#149165
This commit is contained in:
Matthias Krüger 2025-12-04 08:46:21 +01:00 committed by GitHub
commit 420ef95cd7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 58 additions and 46 deletions

View file

@ -3,6 +3,6 @@
fn main() {
match 5u32 {
1000 ..= 5 => {}
//~^ ERROR lower range bound must be less than or equal to upper
//~^ ERROR lower bound for range pattern must be less than or equal to upper bound
}
}

View file

@ -1,4 +1,4 @@
error[E0030]: lower range bound must be less than or equal to upper
error[E0030]: lower bound for range pattern must be less than or equal to upper bound
--> $DIR/E0030-teach.rs:5:9
|
LL | 1000 ..= 5 => {}

View file

@ -1,6 +1,6 @@
fn main() {
match 5u32 {
1000 ..= 5 => {}
//~^ ERROR lower range bound must be less than or equal to upper
//~^ ERROR lower bound for range pattern must be less than or equal to upper bound
}
}

View file

@ -1,4 +1,4 @@
error[E0030]: lower range bound must be less than or equal to upper
error[E0030]: lower bound for range pattern must be less than or equal to upper bound
--> $DIR/E0030.rs:3:9
|
LL | 1000 ..= 5 => {}

View file

@ -9,36 +9,36 @@ macro_rules! m {
fn main() {
m!(0, ..u8::MIN);
//~^ ERROR lower range bound must be less than upper
//~^ ERROR exclusive upper bound for a range bound cannot be the minimum
m!(0, ..u16::MIN);
//~^ ERROR lower range bound must be less than upper
//~^ ERROR exclusive upper bound for a range bound cannot be the minimum
m!(0, ..u32::MIN);
//~^ ERROR lower range bound must be less than upper
//~^ ERROR exclusive upper bound for a range bound cannot be the minimum
m!(0, ..u64::MIN);
//~^ ERROR lower range bound must be less than upper
//~^ ERROR exclusive upper bound for a range bound cannot be the minimum
m!(0, ..u128::MIN);
//~^ ERROR lower range bound must be less than upper
//~^ ERROR exclusive upper bound for a range bound cannot be the minimum
m!(0, ..i8::MIN);
//~^ ERROR lower range bound must be less than upper
//~^ ERROR exclusive upper bound for a range bound cannot be the minimum
m!(0, ..i16::MIN);
//~^ ERROR lower range bound must be less than upper
//~^ ERROR exclusive upper bound for a range bound cannot be the minimum
m!(0, ..i32::MIN);
//~^ ERROR lower range bound must be less than upper
//~^ ERROR exclusive upper bound for a range bound cannot be the minimum
m!(0, ..i64::MIN);
//~^ ERROR lower range bound must be less than upper
//~^ ERROR exclusive upper bound for a range bound cannot be the minimum
m!(0, ..i128::MIN);
//~^ ERROR lower range bound must be less than upper
//~^ ERROR exclusive upper bound for a range bound cannot be the minimum
m!(0f16, ..f16::NEG_INFINITY);
//~^ ERROR lower range bound must be less than upper
//~^ ERROR exclusive upper bound for a range bound cannot be the minimum
m!(0f32, ..f32::NEG_INFINITY);
//~^ ERROR lower range bound must be less than upper
//~^ ERROR exclusive upper bound for a range bound cannot be the minimum
m!(0f64, ..f64::NEG_INFINITY);
//~^ ERROR lower range bound must be less than upper
//~^ ERROR exclusive upper bound for a range bound cannot be the minimum
m!(0f128, ..f128::NEG_INFINITY);
//~^ ERROR lower range bound must be less than upper
//~^ ERROR exclusive upper bound for a range bound cannot be the minimum
m!('a', ..'\u{0}');
//~^ ERROR lower range bound must be less than upper
//~^ ERROR exclusive upper bound for a range bound cannot be the minimum
}

View file

@ -1,88 +1,88 @@
error[E0579]: lower range bound must be less than upper
error[E0579]: exclusive upper bound for a range bound cannot be the minimum
--> $DIR/half-open-range-pats-thir-lower-empty.rs:11:11
|
LL | m!(0, ..u8::MIN);
| ^^^^^^^^^
error[E0579]: lower range bound must be less than upper
error[E0579]: exclusive upper bound for a range bound cannot be the minimum
--> $DIR/half-open-range-pats-thir-lower-empty.rs:13:11
|
LL | m!(0, ..u16::MIN);
| ^^^^^^^^^^
error[E0579]: lower range bound must be less than upper
error[E0579]: exclusive upper bound for a range bound cannot be the minimum
--> $DIR/half-open-range-pats-thir-lower-empty.rs:15:11
|
LL | m!(0, ..u32::MIN);
| ^^^^^^^^^^
error[E0579]: lower range bound must be less than upper
error[E0579]: exclusive upper bound for a range bound cannot be the minimum
--> $DIR/half-open-range-pats-thir-lower-empty.rs:17:11
|
LL | m!(0, ..u64::MIN);
| ^^^^^^^^^^
error[E0579]: lower range bound must be less than upper
error[E0579]: exclusive upper bound for a range bound cannot be the minimum
--> $DIR/half-open-range-pats-thir-lower-empty.rs:19:11
|
LL | m!(0, ..u128::MIN);
| ^^^^^^^^^^^
error[E0579]: lower range bound must be less than upper
error[E0579]: exclusive upper bound for a range bound cannot be the minimum
--> $DIR/half-open-range-pats-thir-lower-empty.rs:22:11
|
LL | m!(0, ..i8::MIN);
| ^^^^^^^^^
error[E0579]: lower range bound must be less than upper
error[E0579]: exclusive upper bound for a range bound cannot be the minimum
--> $DIR/half-open-range-pats-thir-lower-empty.rs:24:11
|
LL | m!(0, ..i16::MIN);
| ^^^^^^^^^^
error[E0579]: lower range bound must be less than upper
error[E0579]: exclusive upper bound for a range bound cannot be the minimum
--> $DIR/half-open-range-pats-thir-lower-empty.rs:26:11
|
LL | m!(0, ..i32::MIN);
| ^^^^^^^^^^
error[E0579]: lower range bound must be less than upper
error[E0579]: exclusive upper bound for a range bound cannot be the minimum
--> $DIR/half-open-range-pats-thir-lower-empty.rs:28:11
|
LL | m!(0, ..i64::MIN);
| ^^^^^^^^^^
error[E0579]: lower range bound must be less than upper
error[E0579]: exclusive upper bound for a range bound cannot be the minimum
--> $DIR/half-open-range-pats-thir-lower-empty.rs:30:11
|
LL | m!(0, ..i128::MIN);
| ^^^^^^^^^^^
error[E0579]: lower range bound must be less than upper
error[E0579]: exclusive upper bound for a range bound cannot be the minimum
--> $DIR/half-open-range-pats-thir-lower-empty.rs:33:14
|
LL | m!(0f16, ..f16::NEG_INFINITY);
| ^^^^^^^^^^^^^^^^^^^
error[E0579]: lower range bound must be less than upper
error[E0579]: exclusive upper bound for a range bound cannot be the minimum
--> $DIR/half-open-range-pats-thir-lower-empty.rs:35:14
|
LL | m!(0f32, ..f32::NEG_INFINITY);
| ^^^^^^^^^^^^^^^^^^^
error[E0579]: lower range bound must be less than upper
error[E0579]: exclusive upper bound for a range bound cannot be the minimum
--> $DIR/half-open-range-pats-thir-lower-empty.rs:37:14
|
LL | m!(0f64, ..f64::NEG_INFINITY);
| ^^^^^^^^^^^^^^^^^^^
error[E0579]: lower range bound must be less than upper
error[E0579]: exclusive upper bound for a range bound cannot be the minimum
--> $DIR/half-open-range-pats-thir-lower-empty.rs:39:15
|
LL | m!(0f128, ..f128::NEG_INFINITY);
| ^^^^^^^^^^^^^^^^^^^^
error[E0579]: lower range bound must be less than upper
error[E0579]: exclusive upper bound for a range bound cannot be the minimum
--> $DIR/half-open-range-pats-thir-lower-empty.rs:42:13
|
LL | m!('a', ..'\u{0}');

View file

@ -202,7 +202,7 @@ fn invalid_range_pattern(state: f32) {
break 'blk 2.5;
}
4.0..3.0 => {
//~^ ERROR lower range bound must be less than upper
//~^ ERROR lower bound for range pattern must be less than upper bound
todo!()
}
}

View file

@ -121,7 +121,7 @@ LL ~ State::A => State::B,
LL ~ State::B | State::C => todo!(),
|
error[E0579]: lower range bound must be less than upper
error[E0579]: lower bound for range pattern must be less than upper bound
--> $DIR/invalid.rs:204:17
|
LL | 4.0..3.0 => {

View file

@ -1,19 +1,19 @@
fn main() {
match 5 {
6 ..= 1 => { }
//~^ ERROR lower range bound must be less than or equal to upper
//~^ ERROR lower bound for range pattern must be less than or equal to upper bound
_ => { }
};
match 5 {
0 .. 0 => { }
//~^ ERROR lower range bound must be less than upper
//~^ ERROR lower bound for range pattern must be less than upper bound
_ => { }
};
match 5u64 {
0xFFFF_FFFF_FFFF_FFFF ..= 1 => { }
//~^ ERROR lower range bound must be less than or equal to upper
//~^ ERROR lower bound for range pattern must be less than or equal to upper bound
_ => { }
};
}

View file

@ -1,16 +1,16 @@
error[E0030]: lower range bound must be less than or equal to upper
error[E0030]: lower bound for range pattern must be less than or equal to upper bound
--> $DIR/match-range-fail-2.rs:3:9
|
LL | 6 ..= 1 => { }
| ^^^^^^^ lower bound larger than upper bound
error[E0579]: lower range bound must be less than upper
error[E0579]: lower bound for range pattern must be less than upper bound
--> $DIR/match-range-fail-2.rs:9:9
|
LL | 0 .. 0 => { }
| ^^^^^^
error[E0030]: lower range bound must be less than or equal to upper
error[E0030]: lower bound for range pattern must be less than or equal to upper bound
--> $DIR/match-range-fail-2.rs:15:9
|
LL | 0xFFFF_FFFF_FFFF_FFFF ..= 1 => { }

View file

@ -15,7 +15,7 @@ fn main() {
// There isn't really a way to detect these
1..=TOO_BIG => {}
//~^ ERROR lower range bound must be less than or equal to upper
//~^ ERROR lower bound for range pattern must be less than or equal to upper bound
_ => {}
}

View file

@ -10,7 +10,7 @@ error: literal out of range for `u8`
LL | 1..=256 => {}
| ^^^ this value does not fit into the type `u8` whose range is `0..=255`
error[E0030]: lower range bound must be less than or equal to upper
error[E0030]: lower bound for range pattern must be less than or equal to upper bound
--> $DIR/validate-range-endpoints.rs:17:9
|
LL | 1..=TOO_BIG => {}