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:
parent
262cd76333
commit
94ff542ff5
2 changed files with 3 additions and 3 deletions
|
|
@ -612,14 +612,14 @@ mod slice_index {
|
|||
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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue