RS.CLIPPY.STR_SPLIT_AT_NEWLINE
Splitting a trimmed string at hard-coded newlines
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: str_split_at_newline. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for usages of str.trim().split("\
") and str.trim().split("\\r\
").
Why is this bad?
Hard-coding the line endings makes the code less compatible. str.lines should be used instead.
Example
"some\
text\
with\
newlines\
".trim().split(\'\
\');
Use instead:
"some\
text\
with\
newlines\
".lines();
Known Problems
This lint cannot detect if the split is intentionally restricted to a single type of newline ("\
" or
"\\r\
"), for example during the parsing of a specific file format in which precisely one newline type is
valid.