-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #56074 - matthewjasper:forbid-recursive-impl-trait, r=n…
…ikomatsakis Forbid recursive impl trait There is no type T, such that `T = [T; 2]`, but impl Trait could sometimes be to circumvented this. This patch makes it a hard error for an opaque type to resolve to such a "type". Before this can be merged it needs - [x] A better error message - it's good enough for now. - [x] A crater run (?) to see if this any real-world code closes #47659
- Loading branch information
Showing
8 changed files
with
342 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
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.