]>
git.proxmox.com Git - rustc.git/blob - src/tools/clippy/tests/ui/trim_split_whitespace.rs
2 #![warn(clippy::trim_split_whitespace)]
3 #![allow(clippy::let_unit_value)]
7 fn trim(self) -> Self {
10 fn split_whitespace(self) {}
13 struct DerefStr(&'
static str);
14 impl std
::ops
::Deref
for DerefStr
{
16 fn deref(&self) -> &Self::Target
{
21 struct DerefStrAndCustom(&'
static str);
22 impl std
::ops
::Deref
for DerefStrAndCustom
{
24 fn deref(&self) -> &Self::Target
{
28 impl DerefStrAndCustom
{
29 fn trim(self) -> Self {
32 fn split_whitespace(self) {}
35 struct DerefStrAndCustomSplit(&'
static str);
36 impl std
::ops
::Deref
for DerefStrAndCustomSplit
{
38 fn deref(&self) -> &Self::Target
{
42 impl DerefStrAndCustomSplit
{
44 fn split_whitespace(self) {}
47 struct DerefStrAndCustomTrim(&'
static str);
48 impl std
::ops
::Deref
for DerefStrAndCustomTrim
{
50 fn deref(&self) -> &Self::Target
{
54 impl DerefStrAndCustomTrim
{
55 fn trim(self) -> Self {
62 let _
= " A B C ".trim().split_whitespace(); // should trigger lint
63 let _
= " A B C ".trim_start().split_whitespace(); // should trigger lint
64 let _
= " A B C ".trim_end().split_whitespace(); // should trigger lint
67 let _
= (" A B C ").to_string().trim().split_whitespace(); // should trigger lint
68 let _
= (" A B C ").to_string().trim_start().split_whitespace(); // should trigger lint
69 let _
= (" A B C ").to_string().trim_end().split_whitespace(); // should trigger lint
72 let _
= Custom
.trim().split_whitespace(); // should not trigger lint
75 let s
= DerefStr(" A B C ");
76 let _
= s
.trim().split_whitespace(); // should trigger lint
78 // Deref<Target=str> + custom impl
79 let s
= DerefStrAndCustom(" A B C ");
80 let _
= s
.trim().split_whitespace(); // should not trigger lint
82 // Deref<Target=str> + only custom split_ws() impl
83 let s
= DerefStrAndCustomSplit(" A B C ");
84 let _
= s
.trim().split_whitespace(); // should trigger lint
85 // Expl: trim() is called on str (deref) and returns &str.
86 // Thus split_ws() is called on str as well and the custom impl on S is unused
88 // Deref<Target=str> + only custom trim() impl
89 let s
= DerefStrAndCustomTrim(" A B C ");
90 let _
= s
.trim().split_whitespace(); // should not trigger lint