From 707315857a506f99d123a98670341b2d619bca9c Mon Sep 17 00:00:00 2001 From: Matthew Jasper Date: Sun, 20 Oct 2019 22:08:26 +0100 Subject: Don't ICE for completely unexpandable `impl Trait` types --- ...rsive-impl-trait-type--through-non-recursize.rs | 25 ----- ...e-impl-trait-type--through-non-recursize.stderr | 35 ------- .../impl-trait/recursive-impl-trait-type-direct.rs | 7 ++ .../recursive-impl-trait-type-direct.stderr | 11 ++ .../recursive-impl-trait-type-indirect.rs | 77 ++++++++++++++ .../recursive-impl-trait-type-indirect.stderr | 115 +++++++++++++++++++++ ...ursive-impl-trait-type-through-non-recursive.rs | 25 +++++ ...ve-impl-trait-type-through-non-recursive.stderr | 35 +++++++ .../ui/impl-trait/recursive-impl-trait-type.rs | 77 -------------- .../ui/impl-trait/recursive-impl-trait-type.stderr | 115 --------------------- 10 files changed, 270 insertions(+), 252 deletions(-) delete mode 100644 src/test/ui/impl-trait/recursive-impl-trait-type--through-non-recursize.rs delete mode 100644 src/test/ui/impl-trait/recursive-impl-trait-type--through-non-recursize.stderr create mode 100644 src/test/ui/impl-trait/recursive-impl-trait-type-direct.rs create mode 100644 src/test/ui/impl-trait/recursive-impl-trait-type-direct.stderr create mode 100644 src/test/ui/impl-trait/recursive-impl-trait-type-indirect.rs create mode 100644 src/test/ui/impl-trait/recursive-impl-trait-type-indirect.stderr create mode 100644 src/test/ui/impl-trait/recursive-impl-trait-type-through-non-recursive.rs create mode 100644 src/test/ui/impl-trait/recursive-impl-trait-type-through-non-recursive.stderr delete mode 100644 src/test/ui/impl-trait/recursive-impl-trait-type.rs delete mode 100644 src/test/ui/impl-trait/recursive-impl-trait-type.stderr (limited to 'src/test/ui/impl-trait') diff --git a/src/test/ui/impl-trait/recursive-impl-trait-type--through-non-recursize.rs b/src/test/ui/impl-trait/recursive-impl-trait-type--through-non-recursize.rs deleted file mode 100644 index cfd9c0ec5b4..00000000000 --- a/src/test/ui/impl-trait/recursive-impl-trait-type--through-non-recursize.rs +++ /dev/null @@ -1,25 +0,0 @@ -// 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) -> 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) -> 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() {} diff --git a/src/test/ui/impl-trait/recursive-impl-trait-type--through-non-recursize.stderr b/src/test/ui/impl-trait/recursive-impl-trait-type--through-non-recursize.stderr deleted file mode 100644 index 7572c6c1bf0..00000000000 --- a/src/test/ui/impl-trait/recursive-impl-trait-type--through-non-recursize.stderr +++ /dev/null @@ -1,35 +0,0 @@ -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`. diff --git a/src/test/ui/impl-trait/recursive-impl-trait-type-direct.rs b/src/test/ui/impl-trait/recursive-impl-trait-type-direct.rs new file mode 100644 index 00000000000..b22d2165533 --- /dev/null +++ b/src/test/ui/impl-trait/recursive-impl-trait-type-direct.rs @@ -0,0 +1,7 @@ +// Test that an impl trait type that expands to itself is an error. + +fn test() -> impl Sized { //~ ERROR E0720 + test() +} + +fn main() {} diff --git a/src/test/ui/impl-trait/recursive-impl-trait-type-direct.stderr b/src/test/ui/impl-trait/recursive-impl-trait-type-direct.stderr new file mode 100644 index 00000000000..1b5dbd814a4 --- /dev/null +++ b/src/test/ui/impl-trait/recursive-impl-trait-type-direct.stderr @@ -0,0 +1,11 @@ +error[E0720]: opaque type expands to a recursive type + --> $DIR/recursive-impl-trait-type-direct.rs:3:14 + | +LL | fn test() -> impl Sized { + | ^^^^^^^^^^ expands to a recursive type + | + = note: type resolves to itself + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0720`. diff --git a/src/test/ui/impl-trait/recursive-impl-trait-type-indirect.rs b/src/test/ui/impl-trait/recursive-impl-trait-type-indirect.rs new file mode 100644 index 00000000000..2428b560b70 --- /dev/null +++ b/src/test/ui/impl-trait/recursive-impl-trait-type-indirect.rs @@ -0,0 +1,77 @@ +// Test that impl trait does not allow creating recursive types that are +// otherwise forbidden. + +#![feature(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() -> impl Sized { //~ ERROR + (substs_change::<&T>(),) +} + +fn generator_hold() -> impl Sized { //~ ERROR + move || { + let x = generator_hold(); + yield; + x; + } +} + +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() {} diff --git a/src/test/ui/impl-trait/recursive-impl-trait-type-indirect.stderr b/src/test/ui/impl-trait/recursive-impl-trait-type-indirect.stderr new file mode 100644 index 00000000000..b7ba0d6ab17 --- /dev/null +++ b/src/test/ui/impl-trait/recursive-impl-trait-type-indirect.stderr @@ -0,0 +1,115 @@ +error[E0720]: opaque type expands to a recursive type + --> $DIR/recursive-impl-trait-type-indirect.rs:6:22 + | +LL | fn option(i: i32) -> impl Sized { + | ^^^^^^^^^^ expands to a recursive type + | + = note: expanded type is `std::option::Option<(impl Sized, i32)>` + +error[E0720]: opaque type expands to a recursive type + --> $DIR/recursive-impl-trait-type-indirect.rs:14:15 + | +LL | fn tuple() -> 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-indirect.rs:18:15 + | +LL | fn array() -> impl Sized { + | ^^^^^^^^^^ expands to a recursive type + | + = note: expanded type is `[impl Sized; 1]` + +error[E0720]: opaque type expands to a recursive type + --> $DIR/recursive-impl-trait-type-indirect.rs:22:13 + | +LL | fn ptr() -> impl Sized { + | ^^^^^^^^^^ expands to a recursive type + | + = note: expanded type is `*const impl Sized` + +error[E0720]: opaque type expands to a recursive type + --> $DIR/recursive-impl-trait-type-indirect.rs:26:16 + | +LL | fn fn_ptr() -> impl Sized { + | ^^^^^^^^^^ expands to a recursive type + | + = note: expanded type is `fn() -> impl Sized` + +error[E0720]: opaque type expands to a recursive type + --> $DIR/recursive-impl-trait-type-indirect.rs:30:25 + | +LL | fn closure_capture() -> impl Sized { + | ^^^^^^^^^^ expands to a recursive type + | + = note: expanded type is `[closure@$DIR/recursive-impl-trait-type-indirect.rs:32:5: 32:19 x:impl Sized]` + +error[E0720]: opaque type expands to a recursive type + --> $DIR/recursive-impl-trait-type-indirect.rs:35:29 + | +LL | fn closure_ref_capture() -> impl Sized { + | ^^^^^^^^^^ expands to a recursive type + | + = note: expanded type is `[closure@$DIR/recursive-impl-trait-type-indirect.rs:37:5: 37:20 x:impl Sized]` + +error[E0720]: opaque type expands to a recursive type + --> $DIR/recursive-impl-trait-type-indirect.rs:40:21 + | +LL | fn closure_sig() -> impl Sized { + | ^^^^^^^^^^ expands to a recursive type + | + = note: expanded type is `[closure@$DIR/recursive-impl-trait-type-indirect.rs:41:5: 41:21]` + +error[E0720]: opaque type expands to a recursive type + --> $DIR/recursive-impl-trait-type-indirect.rs:44:23 + | +LL | fn generator_sig() -> impl Sized { + | ^^^^^^^^^^ expands to a recursive type + | + = note: expanded type is `[closure@$DIR/recursive-impl-trait-type-indirect.rs:45:5: 45:23]` + +error[E0720]: opaque type expands to a recursive type + --> $DIR/recursive-impl-trait-type-indirect.rs:48:27 + | +LL | fn generator_capture() -> impl Sized { + | ^^^^^^^^^^ expands to a recursive type + | + = note: expanded type is `[generator@$DIR/recursive-impl-trait-type-indirect.rs:50:5: 50:26 x:impl Sized {()}]` + +error[E0720]: opaque type expands to a recursive type + --> $DIR/recursive-impl-trait-type-indirect.rs:53:26 + | +LL | fn substs_change() -> 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-indirect.rs:57:24 + | +LL | fn generator_hold() -> impl Sized { + | ^^^^^^^^^^ expands to a recursive type + | + = note: expanded type is `[generator@$DIR/recursive-impl-trait-type-indirect.rs:58:5: 62:6 {impl Sized, ()}]` + +error[E0720]: opaque type expands to a recursive type + --> $DIR/recursive-impl-trait-type-indirect.rs:69:26 + | +LL | fn mutual_recursion() -> impl Sync { + | ^^^^^^^^^ expands to a recursive type + | + = note: type resolves to itself + +error[E0720]: opaque type expands to a recursive type + --> $DIR/recursive-impl-trait-type-indirect.rs:73:28 + | +LL | fn mutual_recursion_b() -> impl Sized { + | ^^^^^^^^^^ expands to a recursive type + | + = note: type resolves to itself + +error: aborting due to 14 previous errors + +For more information about this error, try `rustc --explain E0720`. diff --git a/src/test/ui/impl-trait/recursive-impl-trait-type-through-non-recursive.rs b/src/test/ui/impl-trait/recursive-impl-trait-type-through-non-recursive.rs new file mode 100644 index 00000000000..cfd9c0ec5b4 --- /dev/null +++ b/src/test/ui/impl-trait/recursive-impl-trait-type-through-non-recursive.rs @@ -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) -> 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) -> 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() {} diff --git a/src/test/ui/impl-trait/recursive-impl-trait-type-through-non-recursive.stderr b/src/test/ui/impl-trait/recursive-impl-trait-type-through-non-recursive.stderr new file mode 100644 index 00000000000..73c12f6137d --- /dev/null +++ b/src/test/ui/impl-trait/recursive-impl-trait-type-through-non-recursive.stderr @@ -0,0 +1,35 @@ +error[E0720]: opaque type expands to a recursive type + --> $DIR/recursive-impl-trait-type-through-non-recursive.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-recursive.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-recursive.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-recursive.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`. diff --git a/src/test/ui/impl-trait/recursive-impl-trait-type.rs b/src/test/ui/impl-trait/recursive-impl-trait-type.rs deleted file mode 100644 index 2428b560b70..00000000000 --- a/src/test/ui/impl-trait/recursive-impl-trait-type.rs +++ /dev/null @@ -1,77 +0,0 @@ -// Test that impl trait does not allow creating recursive types that are -// otherwise forbidden. - -#![feature(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() -> impl Sized { //~ ERROR - (substs_change::<&T>(),) -} - -fn generator_hold() -> impl Sized { //~ ERROR - move || { - let x = generator_hold(); - yield; - x; - } -} - -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() {} diff --git a/src/test/ui/impl-trait/recursive-impl-trait-type.stderr b/src/test/ui/impl-trait/recursive-impl-trait-type.stderr deleted file mode 100644 index 324607117dc..00000000000 --- a/src/test/ui/impl-trait/recursive-impl-trait-type.stderr +++ /dev/null @@ -1,115 +0,0 @@ -error[E0720]: opaque type expands to a recursive type - --> $DIR/recursive-impl-trait-type.rs:6:22 - | -LL | fn option(i: i32) -> impl Sized { - | ^^^^^^^^^^ expands to a recursive type - | - = note: expanded type is `std::option::Option<(impl Sized, i32)>` - -error[E0720]: opaque type expands to a recursive type - --> $DIR/recursive-impl-trait-type.rs:14:15 - | -LL | fn tuple() -> 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.rs:18:15 - | -LL | fn array() -> impl Sized { - | ^^^^^^^^^^ expands to a recursive type - | - = note: expanded type is `[impl Sized; 1]` - -error[E0720]: opaque type expands to a recursive type - --> $DIR/recursive-impl-trait-type.rs:22:13 - | -LL | fn ptr() -> impl Sized { - | ^^^^^^^^^^ expands to a recursive type - | - = note: expanded type is `*const impl Sized` - -error[E0720]: opaque type expands to a recursive type - --> $DIR/recursive-impl-trait-type.rs:26:16 - | -LL | fn fn_ptr() -> impl Sized { - | ^^^^^^^^^^ expands to a recursive type - | - = note: expanded type is `fn() -> impl Sized` - -error[E0720]: opaque type expands to a recursive type - --> $DIR/recursive-impl-trait-type.rs:30:25 - | -LL | fn closure_capture() -> impl Sized { - | ^^^^^^^^^^ expands to a recursive type - | - = note: expanded type is `[closure@$DIR/recursive-impl-trait-type.rs:32:5: 32:19 x:impl Sized]` - -error[E0720]: opaque type expands to a recursive type - --> $DIR/recursive-impl-trait-type.rs:35:29 - | -LL | fn closure_ref_capture() -> impl Sized { - | ^^^^^^^^^^ expands to a recursive type - | - = note: expanded type is `[closure@$DIR/recursive-impl-trait-type.rs:37:5: 37:20 x:impl Sized]` - -error[E0720]: opaque type expands to a recursive type - --> $DIR/recursive-impl-trait-type.rs:40:21 - | -LL | fn closure_sig() -> impl Sized { - | ^^^^^^^^^^ expands to a recursive type - | - = note: expanded type is `[closure@$DIR/recursive-impl-trait-type.rs:41:5: 41:21]` - -error[E0720]: opaque type expands to a recursive type - --> $DIR/recursive-impl-trait-type.rs:44:23 - | -LL | fn generator_sig() -> impl Sized { - | ^^^^^^^^^^ expands to a recursive type - | - = note: expanded type is `[closure@$DIR/recursive-impl-trait-type.rs:45:5: 45:23]` - -error[E0720]: opaque type expands to a recursive type - --> $DIR/recursive-impl-trait-type.rs:48:27 - | -LL | fn generator_capture() -> impl Sized { - | ^^^^^^^^^^ expands to a recursive type - | - = note: expanded type is `[generator@$DIR/recursive-impl-trait-type.rs:50:5: 50:26 x:impl Sized {()}]` - -error[E0720]: opaque type expands to a recursive type - --> $DIR/recursive-impl-trait-type.rs:53:26 - | -LL | fn substs_change() -> 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.rs:57:24 - | -LL | fn generator_hold() -> impl Sized { - | ^^^^^^^^^^ expands to a recursive type - | - = note: expanded type is `[generator@$DIR/recursive-impl-trait-type.rs:58:5: 62:6 {impl Sized, ()}]` - -error[E0720]: opaque type expands to a recursive type - --> $DIR/recursive-impl-trait-type.rs:69:26 - | -LL | fn mutual_recursion() -> impl Sync { - | ^^^^^^^^^ expands to a recursive type - | - = note: type resolves to itself - -error[E0720]: opaque type expands to a recursive type - --> $DIR/recursive-impl-trait-type.rs:73:28 - | -LL | fn mutual_recursion_b() -> impl Sized { - | ^^^^^^^^^^ expands to a recursive type - | - = note: type resolves to itself - -error: aborting due to 14 previous errors - -For more information about this error, try `rustc --explain E0720`. -- cgit 1.4.1-3-g733a5 From 0c05ed29fd26eb1a7cc5fa77c0fa41d940a78346 Mon Sep 17 00:00:00 2001 From: matthewjasper Date: Fri, 25 Oct 2019 18:50:40 +0100 Subject: Apply suggestions from code review Co-Authored-By: Mazdak Farrokhzad --- src/test/ui/impl-trait/recursive-impl-trait-type-direct.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/test/ui/impl-trait') diff --git a/src/test/ui/impl-trait/recursive-impl-trait-type-direct.rs b/src/test/ui/impl-trait/recursive-impl-trait-type-direct.rs index b22d2165533..2b4f5e0975a 100644 --- a/src/test/ui/impl-trait/recursive-impl-trait-type-direct.rs +++ b/src/test/ui/impl-trait/recursive-impl-trait-type-direct.rs @@ -1,6 +1,6 @@ -// Test that an impl trait type that expands to itself is an error. +// Test that an `impl Trait` type that expands to itself is an error. -fn test() -> impl Sized { //~ ERROR E0720 +fn test() -> impl Sized { //~ ERROR E0720 test() } -- cgit 1.4.1-3-g733a5