about summary refs log tree commit diff
path: root/tests/ui/methods
diff options
context:
space:
mode:
authormejrs <59372212+mejrs@users.noreply.github.com>2025-04-29 12:46:26 +0200
committermejrs <59372212+mejrs@users.noreply.github.com>2025-04-29 12:46:26 +0200
commita4ce307c0137dca593e2eaa982ee413c7ba03525 (patch)
tree4a8817dc04f91b334cd10e76509db8b2f29c01b2 /tests/ui/methods
parentfc2cd77e114a651755f39f2d9dc5cec6911f4bd9 (diff)
downloadrust-a4ce307c0137dca593e2eaa982ee413c7ba03525.tar.gz
rust-a4ce307c0137dca593e2eaa982ee413c7ba03525.zip
Coalesce duplicate missing clone tests
Diffstat (limited to 'tests/ui/methods')
-rw-r--r--tests/ui/methods/clone-missing.rs33
-rw-r--r--tests/ui/methods/clone-missing.stderr25
2 files changed, 43 insertions, 15 deletions
diff --git a/tests/ui/methods/clone-missing.rs b/tests/ui/methods/clone-missing.rs
index f2e4ad268c6..c5ecd3f175e 100644
--- a/tests/ui/methods/clone-missing.rs
+++ b/tests/ui/methods/clone-missing.rs
@@ -1,19 +1,34 @@
-// This test checks that calling `.clone()` on a type that does not implement the `Clone` trait
-// results in a compilation error. The `Foo` struct does not derive or implement `Clone`,
-// so attempting to clone it should fail.
+//! This test checks that calling `.clone()` on a type that does
+//! not implement the `Clone` trait results in a compilation error.
+//! The `NotClone` and AlsoNotClone structs do not derive or
+//! implement `Clone`, so attempting to clone them should fail.
 
-struct Foo {
-  i: isize,
+struct NotClone {
+    i: isize,
 }
 
-fn foo(i:isize) -> Foo {
-    Foo {
-        i: i
+fn not_clone(i: isize) -> NotClone {
+    NotClone { i }
+}
+
+struct AlsoNotClone {
+    i: isize,
+    j: NotClone,
+}
+
+fn also_not_clone(i: isize) -> AlsoNotClone {
+    AlsoNotClone {
+        i,
+        j: NotClone { i: i },
     }
 }
 
 fn main() {
-    let x = foo(10);
+    let x = not_clone(10);
+    let _y = x.clone();
+    //~^ ERROR no method named `clone` found
+
+    let x = also_not_clone(10);
     let _y = x.clone();
     //~^ ERROR no method named `clone` found
 }
diff --git a/tests/ui/methods/clone-missing.stderr b/tests/ui/methods/clone-missing.stderr
index 4ab1aae4934..8676e73c8ca 100644
--- a/tests/ui/methods/clone-missing.stderr
+++ b/tests/ui/methods/clone-missing.stderr
@@ -1,16 +1,29 @@
-error[E0599]: no method named `clone` found for struct `Foo` in the current scope
-  --> $DIR/clone-missing.rs:17:16
+error[E0599]: no method named `clone` found for struct `NotClone` in the current scope
+  --> $DIR/clone-missing.rs:28:16
    |
-LL | struct Foo {
-   | ---------- method `clone` not found for this struct
+LL | struct NotClone {
+   | --------------- method `clone` not found for this struct
 ...
 LL |     let _y = x.clone();
-   |                ^^^^^ method not found in `Foo`
+   |                ^^^^^ method not found in `NotClone`
    |
    = help: items from traits can only be used if the trait is implemented and in scope
    = note: the following trait defines an item `clone`, perhaps you need to implement it:
            candidate #1: `Clone`
 
-error: aborting due to 1 previous error
+error[E0599]: no method named `clone` found for struct `AlsoNotClone` in the current scope
+  --> $DIR/clone-missing.rs:32:16
+   |
+LL | struct AlsoNotClone {
+   | ------------------- method `clone` not found for this struct
+...
+LL |     let _y = x.clone();
+   |                ^^^^^ method not found in `AlsoNotClone`
+   |
+   = help: items from traits can only be used if the trait is implemented and in scope
+   = note: the following trait defines an item `clone`, perhaps you need to implement it:
+           candidate #1: `Clone`
+
+error: aborting due to 2 previous errors
 
 For more information about this error, try `rustc --explain E0599`.