summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/len_without_is_empty.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:50 +0000
commit2e00214b3efbdfeefaa0fe9e8b8fd519de7adc35 (patch)
treed325add32978dbdc1db975a438b3a77d571b1ab8 /src/tools/clippy/tests/ui/len_without_is_empty.rs
parentReleasing progress-linux version 1.68.2+dfsg1-1~progress7.99u1. (diff)
downloadrustc-2e00214b3efbdfeefaa0fe9e8b8fd519de7adc35.tar.xz
rustc-2e00214b3efbdfeefaa0fe9e8b8fd519de7adc35.zip
Merging upstream version 1.69.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tools/clippy/tests/ui/len_without_is_empty.rs')
-rw-r--r--src/tools/clippy/tests/ui/len_without_is_empty.rs46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui/len_without_is_empty.rs b/src/tools/clippy/tests/ui/len_without_is_empty.rs
index 78397c2af..b5dec6c46 100644
--- a/src/tools/clippy/tests/ui/len_without_is_empty.rs
+++ b/src/tools/clippy/tests/ui/len_without_is_empty.rs
@@ -282,4 +282,50 @@ impl AsyncLen {
}
}
+// issue #9520
+pub struct NonStandardLenAndIsEmptySignature;
+impl NonStandardLenAndIsEmptySignature {
+ // don't lint
+ pub fn len(&self, something: usize) -> usize {
+ something
+ }
+
+ pub fn is_empty(&self, something: usize) -> bool {
+ something == 0
+ }
+}
+
+// test case for #9520 with generics in the function signature
+pub trait TestResource {
+ type NonStandardSignatureWithGenerics: Copy;
+ fn lookup_content(&self, item: Self::NonStandardSignatureWithGenerics) -> Result<Option<&[u8]>, String>;
+}
+pub struct NonStandardSignatureWithGenerics(u32);
+impl NonStandardSignatureWithGenerics {
+ pub fn is_empty<T, U>(self, resource: &T) -> bool
+ where
+ T: TestResource<NonStandardSignatureWithGenerics = U>,
+ U: Copy + From<NonStandardSignatureWithGenerics>,
+ {
+ if let Ok(Some(content)) = resource.lookup_content(self.into()) {
+ content.is_empty()
+ } else {
+ true
+ }
+ }
+
+ // test case for #9520 with generics in the function signature
+ pub fn len<T, U>(self, resource: &T) -> usize
+ where
+ T: TestResource<NonStandardSignatureWithGenerics = U>,
+ U: Copy + From<NonStandardSignatureWithGenerics>,
+ {
+ if let Ok(Some(content)) = resource.lookup_content(self.into()) {
+ content.len()
+ } else {
+ 0_usize
+ }
+ }
+}
+
fn main() {}