Skip to content

Commit d341b17

Browse files
committed
Add test for deref recursion limit printing twice
1 parent 20dc0c5 commit d341b17

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

src/test/ui/issues/issue-38940.rs

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// issue-38940: error printed twice for deref recursion limit exceeded
2+
// Test that the recursion limit can be changed. In this case, we have
3+
// deeply nested types that will fail the `Send` check by overflow
4+
// when the recursion limit is set very low.
5+
#![allow(dead_code)]
6+
#![recursion_limit="10"]
7+
macro_rules! link {
8+
($outer:ident, $inner:ident) => {
9+
struct $outer($inner);
10+
impl $outer {
11+
fn new() -> $outer {
12+
$outer($inner::new())
13+
}
14+
}
15+
impl std::ops::Deref for $outer {
16+
type Target = $inner;
17+
fn deref(&self) -> &$inner {
18+
&self.0
19+
}
20+
}
21+
}
22+
}
23+
struct Bottom;
24+
impl Bottom {
25+
fn new() -> Bottom {
26+
Bottom
27+
}
28+
}
29+
link!(Top, A);
30+
link!(A, B);
31+
link!(B, C);
32+
link!(C, D);
33+
link!(D, E);
34+
link!(E, F);
35+
link!(F, G);
36+
link!(G, H);
37+
link!(H, I);
38+
link!(I, J);
39+
link!(J, K);
40+
link!(K, Bottom);
41+
fn main() {
42+
let t = Top::new();
43+
let x: &Bottom = &t;
44+
//~^ ERROR mismatched types
45+
//~| NOTE expected type `&Bottom`
46+
//~| NOTE found type `&Top`
47+
//~| NOTE expected struct `Bottom`, found struct `Top`
48+
//~| ERROR reached the recursion limit while auto-dereferencing I
49+
//~| NOTE deref recursion limit reached
50+
//~| NOTE consider adding a `#![recursion_limit="20"]` attribute to your crate
51+
}

src/test/ui/issues/issue-38940.stderr

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error[E0055]: reached the recursion limit while auto-dereferencing I
2+
--> $DIR/issue-38940.rs:43:22
3+
|
4+
LL | let x: &Bottom = &t;
5+
| ^^ deref recursion limit reached
6+
|
7+
= help: consider adding a `#![recursion_limit="20"]` attribute to your crate
8+
9+
error[E0308]: mismatched types
10+
--> $DIR/issue-38940.rs:43:22
11+
|
12+
LL | let x: &Bottom = &t;
13+
| ^^ expected struct `Bottom`, found struct `Top`
14+
|
15+
= note: expected type `&Bottom`
16+
found type `&Top`
17+
18+
error: aborting due to 2 previous errors
19+
20+
Some errors occurred: E0055, E0308.
21+
For more information about an error, try `rustc --explain E0055`.

0 commit comments

Comments
 (0)