-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Awkward wording of char slicing error message #38052
Comments
Lol, I initially read this as saying "do not lie [about] character boundary" to the person who wrote I'd suggest:
Assuming the actual problem is that you can't form a new string slice with invalid/cut off characters:
|
Well, the problem is "and/or": "0 and 3 are" / "0 or 3 is". Can we just check in the function that prints this message, and make the error message less vague? It's on the panic path anyway.
|
I made a PR with your strategy @durka. It feels good to be more friendly yet technically specific here (?) |
Use more specific panic message for &str slicing errors Separate out of bounds errors from character boundary errors, and print more details for character boundary errors. It reports the first error it finds in: 1. begin out of bounds 2. end out of bounds 3. begin <= end violated 3. begin not char boundary 5. end not char boundary. Example: &"abcαβγ"[..4] thread 'str::test_slice_fail_boundary_1' panicked at 'byte index 4 is not a char boundary; it is inside 'α' (bytes 3..5) of `abcαβγ`' Fixes #38052
Use more specific panic message for &str slicing errors Separate out of bounds errors from character boundary errors, and print more details for character boundary errors. It reports the first error it finds in: 1. begin out of bounds 2. end out of bounds 3. begin <= end violated 3. begin not char boundary 5. end not char boundary. Example: &"abcαβγ"[..4] thread 'str::test_slice_fail_boundary_1' panicked at 'byte index 4 is not a char boundary; it is inside 'α' (bytes 3..5) of `abcαβγ`' Fixes #38052
gives
To me, "index do not lie" feels weird, should be "does not lie".
The text was updated successfully, but these errors were encountered: