mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Make panic message less confusing
The panic message when slicing a string with a negative length range (eg `"abcdef"[4..3]`) is confusing: it gives the condition that failed to hold, whilst all the other panic messages give the condition that did hold. Before: begin <= end (4 <= 3) when slicing `abcdef` After: begin > end (4 > 3) when slicing `abcdef`
This commit is contained in:
@@ -612,14 +612,14 @@ fn test_slice_fail() {
|
||||
data: "abcdef";
|
||||
good: data[4..4] == "";
|
||||
bad: data[4..3];
|
||||
message: "begin <= end (4 <= 3)";
|
||||
message: "begin > end (4 > 3)";
|
||||
}
|
||||
|
||||
in mod rangeinclusive_neg_width {
|
||||
data: "abcdef";
|
||||
good: data[4..=3] == "";
|
||||
bad: data[4..=2];
|
||||
message: "begin <= end (4 <= 3)";
|
||||
message: "begin > end (4 > 3)";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ fn slice_error_fail_rt(s: &str, begin: usize, end: usize) -> ! {
|
||||
|
||||
// 3. range is backwards.
|
||||
if begin > end {
|
||||
panic!("begin <= end ({begin} <= {end}) when slicing `{s_trunc}`{ellipsis}")
|
||||
panic!("begin > end ({begin} > {end}) when slicing `{s_trunc}`{ellipsis}")
|
||||
}
|
||||
|
||||
// 4. begin is inside a character.
|
||||
|
||||
Reference in New Issue
Block a user