-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Forbid recursive impl trait #56074
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
bors
merged 2 commits into
rust-lang:master
from
matthewjasper:forbid-recursive-impl-trait
Jan 4, 2019
Merged
Forbid recursive impl trait #56074
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.