about summary refs log tree commit diff
path: root/tests/ui/self
diff options
context:
space:
mode:
authorAdrian Taylor <adetaylor@chromium.org>2025-02-05 08:04:37 +0000
committerAdrian Taylor <adetaylor@chromium.org>2025-02-05 08:18:38 +0000
commit0772400dbff0293307c6a3d19e60c391699a146f (patch)
tree6a6b05d18470071e418cbc0fc540555dd0e8ee71 /tests/ui/self
parentaa6f5ab18e67cb815f73e0d53d217bc54b0da924 (diff)
downloadrust-0772400dbff0293307c6a3d19e60c391699a146f.tar.gz
rust-0772400dbff0293307c6a3d19e60c391699a146f.zip
Arbitrary self types v2: recursion test
Add a test for infinite recursion of an arbitrary self type.

These diagnostics aren't perfect (especially the repetition of the
statement that there's too much recursion) but for now at least
let's add a test to confirm that such diagnostics are emitted.
Diffstat (limited to 'tests/ui/self')
-rw-r--r--tests/ui/self/arbitrary_self_type_infinite_recursion.rs24
-rw-r--r--tests/ui/self/arbitrary_self_type_infinite_recursion.stderr47
2 files changed, 71 insertions, 0 deletions
diff --git a/tests/ui/self/arbitrary_self_type_infinite_recursion.rs b/tests/ui/self/arbitrary_self_type_infinite_recursion.rs
new file mode 100644
index 00000000000..6fbf35c0b86
--- /dev/null
+++ b/tests/ui/self/arbitrary_self_type_infinite_recursion.rs
@@ -0,0 +1,24 @@
+#![feature(arbitrary_self_types)]
+
+struct MySmartPtr<T>(T);
+
+impl<T> core::ops::Receiver for MySmartPtr<T> {
+  type Target = MySmartPtr<T>;
+}
+
+struct Content;
+
+impl Content {
+  fn method(self: MySmartPtr<Self>) { // note self type
+     //~^ reached the recursion limit
+     //~| reached the recursion limit
+     //~| invalid `self` parameter type
+  }
+}
+
+fn main() {
+  let p = MySmartPtr(Content);
+  p.method();
+  //~^ reached the recursion limit
+  //~| no method named `method`
+}
diff --git a/tests/ui/self/arbitrary_self_type_infinite_recursion.stderr b/tests/ui/self/arbitrary_self_type_infinite_recursion.stderr
new file mode 100644
index 00000000000..5e652efb364
--- /dev/null
+++ b/tests/ui/self/arbitrary_self_type_infinite_recursion.stderr
@@ -0,0 +1,47 @@
+error[E0055]: reached the recursion limit while auto-dereferencing `MySmartPtr<Content>`
+  --> $DIR/arbitrary_self_type_infinite_recursion.rs:12:19
+   |
+LL |   fn method(self: MySmartPtr<Self>) { // note self type
+   |                   ^^^^^^^^^^^^^^^^ deref recursion limit reached
+   |
+   = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`arbitrary_self_type_infinite_recursion`)
+
+error[E0055]: reached the recursion limit while auto-dereferencing `MySmartPtr<Content>`
+  --> $DIR/arbitrary_self_type_infinite_recursion.rs:12:19
+   |
+LL |   fn method(self: MySmartPtr<Self>) { // note self type
+   |                   ^^^^^^^^^^^^^^^^ deref recursion limit reached
+   |
+   = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`arbitrary_self_type_infinite_recursion`)
+   = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
+
+error[E0307]: invalid `self` parameter type: `MySmartPtr<Content>`
+  --> $DIR/arbitrary_self_type_infinite_recursion.rs:12:19
+   |
+LL |   fn method(self: MySmartPtr<Self>) { // note self type
+   |                   ^^^^^^^^^^^^^^^^
+   |
+   = note: type of `self` must be `Self` or some type implementing `Receiver`
+   = help: consider changing to `self`, `&self`, `&mut self`, or a type implementing `Receiver` such as `self: Box<Self>`, `self: Rc<Self>`, or `self: Arc<Self>`
+
+error[E0055]: reached the recursion limit while auto-dereferencing `MySmartPtr<Content>`
+  --> $DIR/arbitrary_self_type_infinite_recursion.rs:21:5
+   |
+LL |   p.method();
+   |     ^^^^^^ deref recursion limit reached
+   |
+   = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`arbitrary_self_type_infinite_recursion`)
+
+error[E0599]: no method named `method` found for struct `MySmartPtr` in the current scope
+  --> $DIR/arbitrary_self_type_infinite_recursion.rs:21:5
+   |
+LL | struct MySmartPtr<T>(T);
+   | -------------------- method `method` not found for this struct
+...
+LL |   p.method();
+   |     ^^^^^^ method not found in `MySmartPtr<Content>`
+
+error: aborting due to 5 previous errors
+
+Some errors have detailed explanations: E0055, E0307, E0599.
+For more information about an error, try `rustc --explain E0055`.