From 470d378646d096009bb21102f3948041c0c8f29a Mon Sep 17 00:00:00 2001 From: Alex Macleod Date: Thu, 22 Jul 2021 19:16:33 +0100 Subject: [PATCH] Add regression tests for the impl_trait_in_bindings ICEs --- src/test/ui/impl-trait/issues/issue-54600.rs | 7 +++++++ .../ui/impl-trait/issues/issue-54600.stderr | 9 ++++++++ src/test/ui/impl-trait/issues/issue-54840.rs | 7 +++++++ .../ui/impl-trait/issues/issue-54840.stderr | 9 ++++++++ src/test/ui/impl-trait/issues/issue-58504.rs | 12 +++++++++++ .../ui/impl-trait/issues/issue-58504.stderr | 9 ++++++++ src/test/ui/impl-trait/issues/issue-58956.rs | 14 +++++++++++++ .../ui/impl-trait/issues/issue-58956.stderr | 15 +++++++++++++ src/test/ui/impl-trait/issues/issue-70971.rs | 4 ++++ .../ui/impl-trait/issues/issue-70971.stderr | 9 ++++++++ src/test/ui/impl-trait/issues/issue-79099.rs | 10 +++++++++ .../ui/impl-trait/issues/issue-79099.stderr | 20 ++++++++++++++++++ src/test/ui/impl-trait/issues/issue-84919.rs | 9 ++++++++ .../ui/impl-trait/issues/issue-84919.stderr | 9 ++++++++ src/test/ui/impl-trait/issues/issue-86201.rs | 13 ++++++++++++ .../ui/impl-trait/issues/issue-86201.stderr | 21 +++++++++++++++++++ src/test/ui/impl-trait/issues/issue-86642.rs | 8 +++++++ .../ui/impl-trait/issues/issue-86642.stderr | 9 ++++++++ src/test/ui/impl-trait/issues/issue-87295.rs | 18 ++++++++++++++++ .../ui/impl-trait/issues/issue-87295.stderr | 9 ++++++++ 20 files changed, 221 insertions(+) create mode 100644 src/test/ui/impl-trait/issues/issue-54600.rs create mode 100644 src/test/ui/impl-trait/issues/issue-54600.stderr create mode 100644 src/test/ui/impl-trait/issues/issue-54840.rs create mode 100644 src/test/ui/impl-trait/issues/issue-54840.stderr create mode 100644 src/test/ui/impl-trait/issues/issue-58504.rs create mode 100644 src/test/ui/impl-trait/issues/issue-58504.stderr create mode 100644 src/test/ui/impl-trait/issues/issue-58956.rs create mode 100644 src/test/ui/impl-trait/issues/issue-58956.stderr create mode 100644 src/test/ui/impl-trait/issues/issue-70971.rs create mode 100644 src/test/ui/impl-trait/issues/issue-70971.stderr create mode 100644 src/test/ui/impl-trait/issues/issue-79099.rs create mode 100644 src/test/ui/impl-trait/issues/issue-79099.stderr create mode 100644 src/test/ui/impl-trait/issues/issue-84919.rs create mode 100644 src/test/ui/impl-trait/issues/issue-84919.stderr create mode 100644 src/test/ui/impl-trait/issues/issue-86201.rs create mode 100644 src/test/ui/impl-trait/issues/issue-86201.stderr create mode 100644 src/test/ui/impl-trait/issues/issue-86642.rs create mode 100644 src/test/ui/impl-trait/issues/issue-86642.stderr create mode 100644 src/test/ui/impl-trait/issues/issue-87295.rs create mode 100644 src/test/ui/impl-trait/issues/issue-87295.stderr diff --git a/src/test/ui/impl-trait/issues/issue-54600.rs b/src/test/ui/impl-trait/issues/issue-54600.rs new file mode 100644 index 0000000000000..7a64799302332 --- /dev/null +++ b/src/test/ui/impl-trait/issues/issue-54600.rs @@ -0,0 +1,7 @@ +use std::fmt::Debug; + +fn main() { + let x: Option = Some(44_u32); + //~^ `impl Trait` not allowed outside of function and method return types + println!("{:?}", x); +} diff --git a/src/test/ui/impl-trait/issues/issue-54600.stderr b/src/test/ui/impl-trait/issues/issue-54600.stderr new file mode 100644 index 0000000000000..4d0c32c6bb708 --- /dev/null +++ b/src/test/ui/impl-trait/issues/issue-54600.stderr @@ -0,0 +1,9 @@ +error[E0562]: `impl Trait` not allowed outside of function and method return types + --> $DIR/issue-54600.rs:4:19 + | +LL | let x: Option = Some(44_u32); + | ^^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0562`. diff --git a/src/test/ui/impl-trait/issues/issue-54840.rs b/src/test/ui/impl-trait/issues/issue-54840.rs new file mode 100644 index 0000000000000..030d5715d5739 --- /dev/null +++ b/src/test/ui/impl-trait/issues/issue-54840.rs @@ -0,0 +1,7 @@ +use std::ops::Add; + +fn main() { + let i: i32 = 0; + let j: &impl Add = &i; + //~^ `impl Trait` not allowed outside of function and method return types +} diff --git a/src/test/ui/impl-trait/issues/issue-54840.stderr b/src/test/ui/impl-trait/issues/issue-54840.stderr new file mode 100644 index 0000000000000..b8046b7482f72 --- /dev/null +++ b/src/test/ui/impl-trait/issues/issue-54840.stderr @@ -0,0 +1,9 @@ +error[E0562]: `impl Trait` not allowed outside of function and method return types + --> $DIR/issue-54840.rs:5:13 + | +LL | let j: &impl Add = &i; + | ^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0562`. diff --git a/src/test/ui/impl-trait/issues/issue-58504.rs b/src/test/ui/impl-trait/issues/issue-58504.rs new file mode 100644 index 0000000000000..aac33b3b3e5c5 --- /dev/null +++ b/src/test/ui/impl-trait/issues/issue-58504.rs @@ -0,0 +1,12 @@ +#![feature(generators, generator_trait, never_type)] + +use std::ops::Generator; + +fn mk_gen() -> impl Generator { + || { loop { yield; } } +} + +fn main() { + let gens: [impl Generator;2] = [ mk_gen(), mk_gen() ]; + //~^ `impl Trait` not allowed outside of function and method return types +} diff --git a/src/test/ui/impl-trait/issues/issue-58504.stderr b/src/test/ui/impl-trait/issues/issue-58504.stderr new file mode 100644 index 0000000000000..ff1010f066182 --- /dev/null +++ b/src/test/ui/impl-trait/issues/issue-58504.stderr @@ -0,0 +1,9 @@ +error[E0562]: `impl Trait` not allowed outside of function and method return types + --> $DIR/issue-58504.rs:10:16 + | +LL | let gens: [impl Generator;2] = [ mk_gen(), mk_gen() ]; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0562`. diff --git a/src/test/ui/impl-trait/issues/issue-58956.rs b/src/test/ui/impl-trait/issues/issue-58956.rs new file mode 100644 index 0000000000000..5fe18b6e9b54a --- /dev/null +++ b/src/test/ui/impl-trait/issues/issue-58956.rs @@ -0,0 +1,14 @@ +trait Lam {} + +pub struct B; +impl Lam for B {} +pub struct Wrap(T); + +const _A: impl Lam = { + //~^ `impl Trait` not allowed outside of function and method return types + let x: Wrap = Wrap(B); + //~^ `impl Trait` not allowed outside of function and method return types + x.0 +}; + +fn main() {} diff --git a/src/test/ui/impl-trait/issues/issue-58956.stderr b/src/test/ui/impl-trait/issues/issue-58956.stderr new file mode 100644 index 0000000000000..00ebf170ab2fe --- /dev/null +++ b/src/test/ui/impl-trait/issues/issue-58956.stderr @@ -0,0 +1,15 @@ +error[E0562]: `impl Trait` not allowed outside of function and method return types + --> $DIR/issue-58956.rs:7:11 + | +LL | const _A: impl Lam = { + | ^^^^^^^^ + +error[E0562]: `impl Trait` not allowed outside of function and method return types + --> $DIR/issue-58956.rs:9:17 + | +LL | let x: Wrap = Wrap(B); + | ^^^^^^^^ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0562`. diff --git a/src/test/ui/impl-trait/issues/issue-70971.rs b/src/test/ui/impl-trait/issues/issue-70971.rs new file mode 100644 index 0000000000000..d4dc2fd877b67 --- /dev/null +++ b/src/test/ui/impl-trait/issues/issue-70971.rs @@ -0,0 +1,4 @@ +fn main() { + let x : (impl Copy,) = (true,); + //~^ `impl Trait` not allowed outside of function and method return types +} diff --git a/src/test/ui/impl-trait/issues/issue-70971.stderr b/src/test/ui/impl-trait/issues/issue-70971.stderr new file mode 100644 index 0000000000000..31993da3e32f3 --- /dev/null +++ b/src/test/ui/impl-trait/issues/issue-70971.stderr @@ -0,0 +1,9 @@ +error[E0562]: `impl Trait` not allowed outside of function and method return types + --> $DIR/issue-70971.rs:2:14 + | +LL | let x : (impl Copy,) = (true,); + | ^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0562`. diff --git a/src/test/ui/impl-trait/issues/issue-79099.rs b/src/test/ui/impl-trait/issues/issue-79099.rs new file mode 100644 index 0000000000000..f72533d42e1fa --- /dev/null +++ b/src/test/ui/impl-trait/issues/issue-79099.rs @@ -0,0 +1,10 @@ +struct Bug { + V1: [(); { + let f: impl core::future::Future = async { 1 }; + //~^ `impl Trait` not allowed outside of function and method return types + //~| expected identifier + 1 + }], +} + +fn main() {} diff --git a/src/test/ui/impl-trait/issues/issue-79099.stderr b/src/test/ui/impl-trait/issues/issue-79099.stderr new file mode 100644 index 0000000000000..121536d3f6857 --- /dev/null +++ b/src/test/ui/impl-trait/issues/issue-79099.stderr @@ -0,0 +1,20 @@ +error: expected identifier, found `1` + --> $DIR/issue-79099.rs:3:65 + | +LL | let f: impl core::future::Future = async { 1 }; + | ----- ^ expected identifier + | | + | `async` blocks are only allowed in Rust 2018 or later + | + = help: set `edition = "2018"` in `Cargo.toml` + = note: for more on editions, read https://doc.rust-lang.org/edition-guide + +error[E0562]: `impl Trait` not allowed outside of function and method return types + --> $DIR/issue-79099.rs:3:16 + | +LL | let f: impl core::future::Future = async { 1 }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0562`. diff --git a/src/test/ui/impl-trait/issues/issue-84919.rs b/src/test/ui/impl-trait/issues/issue-84919.rs new file mode 100644 index 0000000000000..479bad97cdf32 --- /dev/null +++ b/src/test/ui/impl-trait/issues/issue-84919.rs @@ -0,0 +1,9 @@ +trait Trait {} +impl Trait for () {} + +fn foo<'a: 'a>() { + let _x: impl Trait = (); + //~^ `impl Trait` not allowed outside of function and method return types +} + +fn main() {} diff --git a/src/test/ui/impl-trait/issues/issue-84919.stderr b/src/test/ui/impl-trait/issues/issue-84919.stderr new file mode 100644 index 0000000000000..bb1bcfefe64ee --- /dev/null +++ b/src/test/ui/impl-trait/issues/issue-84919.stderr @@ -0,0 +1,9 @@ +error[E0562]: `impl Trait` not allowed outside of function and method return types + --> $DIR/issue-84919.rs:5:13 + | +LL | let _x: impl Trait = (); + | ^^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0562`. diff --git a/src/test/ui/impl-trait/issues/issue-86201.rs b/src/test/ui/impl-trait/issues/issue-86201.rs new file mode 100644 index 0000000000000..8dc76f4f752a1 --- /dev/null +++ b/src/test/ui/impl-trait/issues/issue-86201.rs @@ -0,0 +1,13 @@ +#![feature(unboxed_closures)] +#![feature(min_type_alias_impl_trait)] + +type FunType = impl Fn<()>; +//~^ could not find defining uses +static STATIC_FN: FunType = some_fn; +//~^ mismatched types + +fn some_fn() {} + +fn main() { + let _: >::Output = STATIC_FN(); +} diff --git a/src/test/ui/impl-trait/issues/issue-86201.stderr b/src/test/ui/impl-trait/issues/issue-86201.stderr new file mode 100644 index 0000000000000..b1460096ded66 --- /dev/null +++ b/src/test/ui/impl-trait/issues/issue-86201.stderr @@ -0,0 +1,21 @@ +error[E0308]: mismatched types + --> $DIR/issue-86201.rs:6:29 + | +LL | type FunType = impl Fn<()>; + | ----------- the expected opaque type +LL | +LL | static STATIC_FN: FunType = some_fn; + | ^^^^^^^ expected opaque type, found fn item + | + = note: expected opaque type `impl Fn<()>` + found fn item `fn() {some_fn}` + +error: could not find defining uses + --> $DIR/issue-86201.rs:4:16 + | +LL | type FunType = impl Fn<()>; + | ^^^^^^^^^^^ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/impl-trait/issues/issue-86642.rs b/src/test/ui/impl-trait/issues/issue-86642.rs new file mode 100644 index 0000000000000..8953ff8158148 --- /dev/null +++ b/src/test/ui/impl-trait/issues/issue-86642.rs @@ -0,0 +1,8 @@ +static x: impl Fn(&str) -> Result<&str, ()> = move |source| { + //~^ `impl Trait` not allowed outside of function and method return types + let res = (move |source| Ok(source))(source); + let res = res.or((move |source| Ok(source))(source)); + res +}; + +fn main() {} diff --git a/src/test/ui/impl-trait/issues/issue-86642.stderr b/src/test/ui/impl-trait/issues/issue-86642.stderr new file mode 100644 index 0000000000000..2fc0a6fe1f50e --- /dev/null +++ b/src/test/ui/impl-trait/issues/issue-86642.stderr @@ -0,0 +1,9 @@ +error[E0562]: `impl Trait` not allowed outside of function and method return types + --> $DIR/issue-86642.rs:1:11 + | +LL | static x: impl Fn(&str) -> Result<&str, ()> = move |source| { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0562`. diff --git a/src/test/ui/impl-trait/issues/issue-87295.rs b/src/test/ui/impl-trait/issues/issue-87295.rs new file mode 100644 index 0000000000000..2f2bfe147bd66 --- /dev/null +++ b/src/test/ui/impl-trait/issues/issue-87295.rs @@ -0,0 +1,18 @@ +trait Trait { + type Output; +} +impl Trait for () { + type Output = i32; +} + +struct Struct(F); +impl Struct { + pub fn new(_: F) -> Self { + todo!() + } +} + +fn main() { + let _do_not_waste: Struct> = Struct::new(()); + //~^ `impl Trait` not allowed outside of function and method return types +} diff --git a/src/test/ui/impl-trait/issues/issue-87295.stderr b/src/test/ui/impl-trait/issues/issue-87295.stderr new file mode 100644 index 0000000000000..f5c7603ce4918 --- /dev/null +++ b/src/test/ui/impl-trait/issues/issue-87295.stderr @@ -0,0 +1,9 @@ +error[E0562]: `impl Trait` not allowed outside of function and method return types + --> $DIR/issue-87295.rs:16:31 + | +LL | let _do_not_waste: Struct> = Struct::new(()); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0562`.