-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Forbid impl Trait from referring to unnamable recursive types
There is no type T, such that `T = [T; 2]`, we should not allow this to be circumvented by impl Trait.
- Loading branch information
1 parent
7ba17aa
commit 65c1f54
Showing
7 changed files
with
340 additions
and
11 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
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
20 changes: 16 additions & 4 deletions
20
src/test/ui/impl-trait/infinite-impl-trait-issue-38064.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 |
---|---|---|
@@ -1,7 +1,19 @@ | ||
error[E0275]: overflow evaluating the requirement `impl Quux` | ||
error[E0720]: opaque type expands to a recursive type | ||
--> $DIR/infinite-impl-trait-issue-38064.rs:8:13 | ||
| | ||
= help: consider adding a `#![recursion_limit="128"]` attribute to your crate | ||
LL | fn foo() -> impl Quux { //~ opaque type expands to a recursive type | ||
| ^^^^^^^^^ expands to self-referential type | ||
| | ||
= note: expanded type is `foo::Foo<bar::Bar<impl Quux>>` | ||
|
||
error[E0720]: opaque type expands to a recursive type | ||
--> $DIR/infinite-impl-trait-issue-38064.rs:14:13 | ||
| | ||
LL | fn bar() -> impl Quux { //~ opaque type expands to a recursive type | ||
| ^^^^^^^^^ expands to self-referential type | ||
| | ||
= note: expanded type is `bar::Bar<foo::Foo<impl Quux>>` | ||
|
||
error: aborting due to previous error | ||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0275`. | ||
For more information about this error, try `rustc --explain E0720`. |
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,81 @@ | ||
// Test that impl trait does not allow creating recursive types that are | ||
// otherwise forbidden. | ||
|
||
#![feature(await_macro, async_await, futures_api, generators)] | ||
|
||
fn option(i: i32) -> impl Sized { //~ ERROR | ||
if i < 0 { | ||
None | ||
} else { | ||
Some((option(i - 1), i)) | ||
} | ||
} | ||
|
||
fn tuple() -> impl Sized { //~ ERROR | ||
(tuple(),) | ||
} | ||
|
||
fn array() -> impl Sized { //~ ERROR | ||
[array()] | ||
} | ||
|
||
fn ptr() -> impl Sized { //~ ERROR | ||
&ptr() as *const _ | ||
} | ||
|
||
fn fn_ptr() -> impl Sized { //~ ERROR | ||
fn_ptr as fn() -> _ | ||
} | ||
|
||
fn closure_capture() -> impl Sized { //~ ERROR | ||
let x = closure_capture(); | ||
move || { x; } | ||
} | ||
|
||
fn closure_ref_capture() -> impl Sized { //~ ERROR | ||
let x = closure_ref_capture(); | ||
move || { &x; } | ||
} | ||
|
||
fn closure_sig() -> impl Sized { //~ ERROR | ||
|| closure_sig() | ||
} | ||
|
||
fn generator_sig() -> impl Sized { //~ ERROR | ||
|| generator_sig() | ||
} | ||
|
||
fn generator_capture() -> impl Sized { //~ ERROR | ||
let x = generator_capture(); | ||
move || { yield; x; } | ||
} | ||
|
||
fn substs_change<T>() -> impl Sized { //~ ERROR | ||
(substs_change::<&T>(),) | ||
} | ||
|
||
fn generator_hold() -> impl Sized { //~ ERROR | ||
move || { | ||
let x = generator_hold(); | ||
yield; | ||
x; | ||
} | ||
} | ||
|
||
async fn recursive_async_function() -> () { //~ ERROR | ||
await!(recursive_async_function()); | ||
} | ||
|
||
fn use_fn_ptr() -> impl Sized { // OK, error already reported | ||
fn_ptr() | ||
} | ||
|
||
fn mutual_recursion() -> impl Sync { //~ ERROR | ||
mutual_recursion_b() | ||
} | ||
|
||
fn mutual_recursion_b() -> impl Sized { //~ ERROR | ||
mutual_recursion() | ||
} | ||
|
||
fn main() {} |
Oops, something went wrong.