Skip to content

Commit 94ff542

Browse files
committed
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`
1 parent 262cd76 commit 94ff542

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

library/alloctests/tests/str.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,14 +612,14 @@ mod slice_index {
612612
data: "abcdef";
613613
good: data[4..4] == "";
614614
bad: data[4..3];
615-
message: "begin <= end (4 <= 3)";
615+
message: "begin > end (4 > 3)";
616616
}
617617

618618
in mod rangeinclusive_neg_width {
619619
data: "abcdef";
620620
good: data[4..=3] == "";
621621
bad: data[4..=2];
622-
message: "begin <= end (4 <= 3)";
622+
message: "begin > end (4 > 3)";
623623
}
624624
}
625625

library/core/src/str/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ fn slice_error_fail_rt(s: &str, begin: usize, end: usize) -> ! {
9999

100100
// 3. range is backwards.
101101
if begin > end {
102-
panic!("begin <= end ({begin} <= {end}) when slicing `{s_trunc}`{ellipsis}")
102+
panic!("begin > end ({begin} > {end}) when slicing `{s_trunc}`{ellipsis}")
103103
}
104104

105105
// 4. begin is inside a character.

0 commit comments

Comments
 (0)