Improve error message

This commit is contained in:
Nadrieril 2020-10-22 19:32:46 +01:00
parent c89d439bb5
commit 94ad5e1672
2 changed files with 35 additions and 20 deletions

View file

@ -309,18 +309,18 @@ impl IntRange {
pcx.span, pcx.span,
|lint| { |lint| {
let mut err = lint.build("multiple patterns overlap on their endpoints"); let mut err = lint.build("multiple patterns overlap on their endpoints");
err.span_label(pcx.span, "overlapping range endpoints"); err.span_label(pcx.span, "... with this range");
for (int_range, span) in overlaps { for (int_range, span) in overlaps {
// Use the real type for user display of the ranges: // Use the real type for user display of the ranges:
err.span_label( err.span_label(
span, span,
&format!( &format!(
"this range overlaps on `{}`", "this range overlaps on `{}`...",
int_range.to_pat(pcx.cx.tcx, pcx.ty) int_range.to_pat(pcx.cx.tcx, pcx.ty)
), ),
); );
} }
// FIXME: add note err.note("this is likely to be a mistake");
err.emit(); err.emit();
}, },
); );

View file

@ -2,73 +2,88 @@ error: multiple patterns overlap on their endpoints
--> $DIR/overlapping_range_endpoints.rs:15:22 --> $DIR/overlapping_range_endpoints.rs:15:22
| |
LL | m!(0u8, 20..=30, 30..=40); LL | m!(0u8, 20..=30, 30..=40);
| ------- ^^^^^^^ overlapping range endpoints | ------- ^^^^^^^ ... with this range
| | | |
| this range overlaps on `30_u8` | this range overlaps on `30_u8`...
| |
note: the lint level is defined here note: the lint level is defined here
--> $DIR/overlapping_range_endpoints.rs:2:9 --> $DIR/overlapping_range_endpoints.rs:2:9
| |
LL | #![deny(overlapping_range_endpoints)] LL | #![deny(overlapping_range_endpoints)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: this is likely to be a mistake
error: multiple patterns overlap on their endpoints error: multiple patterns overlap on their endpoints
--> $DIR/overlapping_range_endpoints.rs:16:22 --> $DIR/overlapping_range_endpoints.rs:16:22
| |
LL | m!(0u8, 30..=40, 20..=30); LL | m!(0u8, 30..=40, 20..=30);
| ------- ^^^^^^^ overlapping range endpoints | ------- ^^^^^^^ ... with this range
| | | |
| this range overlaps on `30_u8` | this range overlaps on `30_u8`...
|
= note: this is likely to be a mistake
error: multiple patterns overlap on their endpoints error: multiple patterns overlap on their endpoints
--> $DIR/overlapping_range_endpoints.rs:19:22 --> $DIR/overlapping_range_endpoints.rs:19:22
| |
LL | m!(0u8, 20.. 30, 29..=40); LL | m!(0u8, 20.. 30, 29..=40);
| ------- ^^^^^^^ overlapping range endpoints | ------- ^^^^^^^ ... with this range
| | | |
| this range overlaps on `29_u8` | this range overlaps on `29_u8`...
|
= note: this is likely to be a mistake
error: multiple patterns overlap on their endpoints error: multiple patterns overlap on their endpoints
--> $DIR/overlapping_range_endpoints.rs:23:22 --> $DIR/overlapping_range_endpoints.rs:23:22
| |
LL | m!(0u8, 20..=30, 30..=31); LL | m!(0u8, 20..=30, 30..=31);
| ------- ^^^^^^^ overlapping range endpoints | ------- ^^^^^^^ ... with this range
| | | |
| this range overlaps on `30_u8` | this range overlaps on `30_u8`...
|
= note: this is likely to be a mistake
error: multiple patterns overlap on their endpoints error: multiple patterns overlap on their endpoints
--> $DIR/overlapping_range_endpoints.rs:27:22 --> $DIR/overlapping_range_endpoints.rs:27:22
| |
LL | m!(0u8, 20..=30, 19..=20); LL | m!(0u8, 20..=30, 19..=20);
| ------- ^^^^^^^ overlapping range endpoints | ------- ^^^^^^^ ... with this range
| | | |
| this range overlaps on `20_u8` | this range overlaps on `20_u8`...
|
= note: this is likely to be a mistake
error: multiple patterns overlap on their endpoints error: multiple patterns overlap on their endpoints
--> $DIR/overlapping_range_endpoints.rs:39:9 --> $DIR/overlapping_range_endpoints.rs:39:9
| |
LL | 0..=10 => {} LL | 0..=10 => {}
| ------ this range overlaps on `10_u8` | ------ this range overlaps on `10_u8`...
LL | 20..=30 => {} LL | 20..=30 => {}
| ------- this range overlaps on `20_u8` | ------- this range overlaps on `20_u8`...
LL | 10..=20 => {} LL | 10..=20 => {}
| ^^^^^^^ overlapping range endpoints | ^^^^^^^ ... with this range
|
= note: this is likely to be a mistake
error: multiple patterns overlap on their endpoints error: multiple patterns overlap on their endpoints
--> $DIR/overlapping_range_endpoints.rs:50:16 --> $DIR/overlapping_range_endpoints.rs:50:16
| |
LL | (true, 0..=10) => {} LL | (true, 0..=10) => {}
| ------ this range overlaps on `10_u8` | ------ this range overlaps on `10_u8`...
LL | (true, 10..20) => {} LL | (true, 10..20) => {}
| ^^^^^^ overlapping range endpoints | ^^^^^^ ... with this range
|
= note: this is likely to be a mistake
error: multiple patterns overlap on their endpoints error: multiple patterns overlap on their endpoints
--> $DIR/overlapping_range_endpoints.rs:56:14 --> $DIR/overlapping_range_endpoints.rs:56:14
| |
LL | Some(0..=10) => {} LL | Some(0..=10) => {}
| ------ this range overlaps on `10_u8` | ------ this range overlaps on `10_u8`...
LL | Some(10..20) => {} LL | Some(10..20) => {}
| ^^^^^^ overlapping range endpoints | ^^^^^^ ... with this range
|
= note: this is likely to be a mistake
error: aborting due to 8 previous errors error: aborting due to 8 previous errors