Skip to content

Commit eeef079

Browse files
authored
Rollup merge of rust-lang#136567 - adetaylor:test-for-recursion, r=oli-obk
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. As suggested by ```@oli-obk``` Relates to rust-lang#44874 r? ```@wesleywiser```
2 parents fd4623b + 0772400 commit eeef079

2 files changed

+71
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#![feature(arbitrary_self_types)]
2+
3+
struct MySmartPtr<T>(T);
4+
5+
impl<T> core::ops::Receiver for MySmartPtr<T> {
6+
type Target = MySmartPtr<T>;
7+
}
8+
9+
struct Content;
10+
11+
impl Content {
12+
fn method(self: MySmartPtr<Self>) { // note self type
13+
//~^ reached the recursion limit
14+
//~| reached the recursion limit
15+
//~| invalid `self` parameter type
16+
}
17+
}
18+
19+
fn main() {
20+
let p = MySmartPtr(Content);
21+
p.method();
22+
//~^ reached the recursion limit
23+
//~| no method named `method`
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
error[E0055]: reached the recursion limit while auto-dereferencing `MySmartPtr<Content>`
2+
--> $DIR/arbitrary_self_type_infinite_recursion.rs:12:19
3+
|
4+
LL | fn method(self: MySmartPtr<Self>) { // note self type
5+
| ^^^^^^^^^^^^^^^^ deref recursion limit reached
6+
|
7+
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`arbitrary_self_type_infinite_recursion`)
8+
9+
error[E0055]: reached the recursion limit while auto-dereferencing `MySmartPtr<Content>`
10+
--> $DIR/arbitrary_self_type_infinite_recursion.rs:12:19
11+
|
12+
LL | fn method(self: MySmartPtr<Self>) { // note self type
13+
| ^^^^^^^^^^^^^^^^ deref recursion limit reached
14+
|
15+
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`arbitrary_self_type_infinite_recursion`)
16+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
17+
18+
error[E0307]: invalid `self` parameter type: `MySmartPtr<Content>`
19+
--> $DIR/arbitrary_self_type_infinite_recursion.rs:12:19
20+
|
21+
LL | fn method(self: MySmartPtr<Self>) { // note self type
22+
| ^^^^^^^^^^^^^^^^
23+
|
24+
= note: type of `self` must be `Self` or some type implementing `Receiver`
25+
= 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>`
26+
27+
error[E0055]: reached the recursion limit while auto-dereferencing `MySmartPtr<Content>`
28+
--> $DIR/arbitrary_self_type_infinite_recursion.rs:21:5
29+
|
30+
LL | p.method();
31+
| ^^^^^^ deref recursion limit reached
32+
|
33+
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`arbitrary_self_type_infinite_recursion`)
34+
35+
error[E0599]: no method named `method` found for struct `MySmartPtr` in the current scope
36+
--> $DIR/arbitrary_self_type_infinite_recursion.rs:21:5
37+
|
38+
LL | struct MySmartPtr<T>(T);
39+
| -------------------- method `method` not found for this struct
40+
...
41+
LL | p.method();
42+
| ^^^^^^ method not found in `MySmartPtr<Content>`
43+
44+
error: aborting due to 5 previous errors
45+
46+
Some errors have detailed explanations: E0055, E0307, E0599.
47+
For more information about an error, try `rustc --explain E0055`.

0 commit comments

Comments
 (0)