Skip to content

Commit a0ef520

Browse files
committed
8733: Make docs more precise and add description of known problems
1 parent 37a0c79 commit a0ef520

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

clippy_lints/src/methods/mod.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -3837,7 +3837,7 @@ declare_clippy_lint! {
38373837
///
38383838
/// ### Why is this bad?
38393839
///
3840-
/// Hard-coding the line endings makes the code less portable. `str.lines` should be used instead.
3840+
/// Hard-coding the line endings makes the code less compatible. `str.lines` should be used instead.
38413841
///
38423842
/// ### Example
38433843
/// ```no_run
@@ -3847,6 +3847,13 @@ declare_clippy_lint! {
38473847
/// ```no_run
38483848
/// "some\ntext\nwith\nnewlines\n".lines();
38493849
/// ```
3850+
///
3851+
/// ### Known Problems
3852+
///
3853+
/// This lint cannot detect if the split is intentionally restricted to a single type of newline (`"\n"` or
3854+
/// `"\r\n"`), for example during the parsing of a specific file format in which precisely one newline type is
3855+
/// valid.
3856+
/// ```
38503857
#[clippy::version = "1.76.0"]
38513858
pub STR_SPLIT_AT_NEWLINE,
38523859
pedantic,

clippy_lints/src/methods/str_split.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@ use rustc_lint::LateContext;
99
use super::STR_SPLIT_AT_NEWLINE;
1010

1111
pub(super) fn check<'a>(cx: &LateContext<'a>, expr: &'_ Expr<'_>, split_recv: &'a Expr<'_>, split_arg: &'_ Expr<'_>) {
12-
// We're looking for `A.trim().split(B)`, where the adjusted type of `A` is `&str` (e.g. a `str`
13-
// literal or an expression returning `String`), and `B` is a `Pattern` that hard-codes a
14-
// newline (either `"\n"` or `"\r\n"`). There are a lot of ways to specify a pattern, and
15-
// this lint only checks the most basic ones: a `'\n'`, `"\n"`, and `"\r\n"`.
16-
12+
// We're looking for `A.trim().split(B)`, where the adjusted type of `A` is `&str` (e.g. an
13+
// expression returning `String`), and `B` is a `Pattern` that hard-codes a newline (either `"\n"`
14+
// or `"\r\n"`). There are a lot of ways to specify a pattern, and this lint only checks the most
15+
// basic ones: a `'\n'`, `"\n"`, and `"\r\n"`.
1716
if let ExprKind::MethodCall(trim_method_name, trim_recv, [], _) = split_recv.kind
1817
&& trim_method_name.ident.as_str() == "trim"
1918
&& cx.typeck_results().expr_ty_adjusted(trim_recv).peel_refs().is_str()

0 commit comments

Comments
 (0)