forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#64038 - matthewjasper:deny-mutual-impl-trai…
…t-recursion, r=varkor Check impl trait substs when checking for recursive types closes rust-lang#64004
- Loading branch information
Showing
7 changed files
with
100 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/test/ui/async-await/mutually-recursive-async-impl-trait-type.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// edition:2018 | ||
// Test that impl trait does not allow creating recursive types that are | ||
// otherwise forbidden when using `async` and `await`. | ||
|
||
async fn rec_1() { //~ ERROR recursion in an `async fn` | ||
rec_2().await; | ||
} | ||
|
||
async fn rec_2() { //~ ERROR recursion in an `async fn` | ||
rec_1().await; | ||
} | ||
|
||
fn main() {} |
19 changes: 19 additions & 0 deletions
19
src/test/ui/async-await/mutually-recursive-async-impl-trait-type.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
error[E0733]: recursion in an `async fn` requires boxing | ||
--> $DIR/mutually-recursive-async-impl-trait-type.rs:5:18 | ||
| | ||
LL | async fn rec_1() { | ||
| ^ recursive `async fn` | ||
| | ||
= note: a recursive `async fn` must be rewritten to return a boxed `dyn Future`. | ||
|
||
error[E0733]: recursion in an `async fn` requires boxing | ||
--> $DIR/mutually-recursive-async-impl-trait-type.rs:9:18 | ||
| | ||
LL | async fn rec_2() { | ||
| ^ recursive `async fn` | ||
| | ||
= note: a recursive `async fn` must be rewritten to return a boxed `dyn Future`. | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0733`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/test/ui/impl-trait/recursive-impl-trait-type--through-non-recursize.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Test that impl trait does not allow creating recursive types that are | ||
// otherwise forbidden. Even when there's an opaque type in another crate | ||
// hiding this. | ||
|
||
fn id<T>(t: T) -> impl Sized { t } | ||
|
||
fn recursive_id() -> impl Sized { //~ ERROR opaque type expands to a recursive type | ||
id(recursive_id2()) | ||
} | ||
|
||
fn recursive_id2() -> impl Sized { //~ ERROR opaque type expands to a recursive type | ||
id(recursive_id()) | ||
} | ||
|
||
fn wrap<T>(t: T) -> impl Sized { (t,) } | ||
|
||
fn recursive_wrap() -> impl Sized { //~ ERROR opaque type expands to a recursive type | ||
wrap(recursive_wrap2()) | ||
} | ||
|
||
fn recursive_wrap2() -> impl Sized { //~ ERROR opaque type expands to a recursive type | ||
wrap(recursive_wrap()) | ||
} | ||
|
||
fn main() {} |
35 changes: 35 additions & 0 deletions
35
src/test/ui/impl-trait/recursive-impl-trait-type--through-non-recursize.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
error[E0720]: opaque type expands to a recursive type | ||
--> $DIR/recursive-impl-trait-type--through-non-recursize.rs:7:22 | ||
| | ||
LL | fn recursive_id() -> impl Sized { | ||
| ^^^^^^^^^^ expands to a recursive type | ||
| | ||
= note: type resolves to itself | ||
|
||
error[E0720]: opaque type expands to a recursive type | ||
--> $DIR/recursive-impl-trait-type--through-non-recursize.rs:11:23 | ||
| | ||
LL | fn recursive_id2() -> impl Sized { | ||
| ^^^^^^^^^^ expands to a recursive type | ||
| | ||
= note: type resolves to itself | ||
|
||
error[E0720]: opaque type expands to a recursive type | ||
--> $DIR/recursive-impl-trait-type--through-non-recursize.rs:17:24 | ||
| | ||
LL | fn recursive_wrap() -> impl Sized { | ||
| ^^^^^^^^^^ expands to a recursive type | ||
| | ||
= note: expanded type is `((impl Sized,),)` | ||
|
||
error[E0720]: opaque type expands to a recursive type | ||
--> $DIR/recursive-impl-trait-type--through-non-recursize.rs:21:25 | ||
| | ||
LL | fn recursive_wrap2() -> impl Sized { | ||
| ^^^^^^^^^^ expands to a recursive type | ||
| | ||
= note: expanded type is `((impl Sized,),)` | ||
|
||
error: aborting due to 4 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0720`. |