RS.CLIPPY.STRING_SLICE

Slicing a string

This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: string_slice. Copyright ©2025 The Rust Team. All rights reserved.

What it does

Checks for slice operations on strings

Why restrict this?

UTF-8 characters span multiple bytes, and it is easy to inadvertently confuse character counts and string indices. This may lead to panics, and should warrant some test cases containing wide UTF-8 characters. This lint is most useful in code that should avoid panics at all costs.

Known problems

Probably lots of false positives. If an index comes from a known valid position (e.g. obtained via char_indices over the same string), it is totally OK.

Example

&"Ölkanne"[1..];