Skip to content

Commit

Permalink
Rollup merge of #87383 - Alexendoo:impl_trait_in_bindings-tests, r=ol…
Browse files Browse the repository at this point in the history
…i-obk

Add regression tests for the impl_trait_in_bindings ICEs

Closes #54600, closes #54840, closes #58504, closes #58956, closes #70971, closes #79099, closes #84919, closes #86201, closes #86642, closes #87295

r? `@oli-obk`
  • Loading branch information
JohnTitor authored Jul 23, 2021
2 parents b1fa06b + 470d378 commit 15b2d95
Show file tree
Hide file tree
Showing 20 changed files with 221 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/test/ui/impl-trait/issues/issue-54600.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use std::fmt::Debug;

fn main() {
let x: Option<impl Debug> = Some(44_u32);
//~^ `impl Trait` not allowed outside of function and method return types
println!("{:?}", x);
}
9 changes: 9 additions & 0 deletions src/test/ui/impl-trait/issues/issue-54600.stderr
Original file line number Diff line number Diff line change
@@ -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<impl Debug> = Some(44_u32);
| ^^^^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0562`.
7 changes: 7 additions & 0 deletions src/test/ui/impl-trait/issues/issue-54840.rs
Original file line number Diff line number Diff line change
@@ -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
}
9 changes: 9 additions & 0 deletions src/test/ui/impl-trait/issues/issue-54840.stderr
Original file line number Diff line number Diff line change
@@ -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`.
12 changes: 12 additions & 0 deletions src/test/ui/impl-trait/issues/issue-58504.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#![feature(generators, generator_trait, never_type)]

use std::ops::Generator;

fn mk_gen() -> impl Generator<Return=!, Yield=()> {
|| { loop { yield; } }
}

fn main() {
let gens: [impl Generator<Return=!, Yield=()>;2] = [ mk_gen(), mk_gen() ];
//~^ `impl Trait` not allowed outside of function and method return types
}
9 changes: 9 additions & 0 deletions src/test/ui/impl-trait/issues/issue-58504.stderr
Original file line number Diff line number Diff line change
@@ -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<Return=!, Yield=()>;2] = [ mk_gen(), mk_gen() ];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0562`.
14 changes: 14 additions & 0 deletions src/test/ui/impl-trait/issues/issue-58956.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
trait Lam {}

pub struct B;
impl Lam for B {}
pub struct Wrap<T>(T);

const _A: impl Lam = {
//~^ `impl Trait` not allowed outside of function and method return types
let x: Wrap<impl Lam> = Wrap(B);
//~^ `impl Trait` not allowed outside of function and method return types
x.0
};

fn main() {}
15 changes: 15 additions & 0 deletions src/test/ui/impl-trait/issues/issue-58956.stderr
Original file line number Diff line number Diff line change
@@ -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<impl Lam> = Wrap(B);
| ^^^^^^^^

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0562`.
4 changes: 4 additions & 0 deletions src/test/ui/impl-trait/issues/issue-70971.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fn main() {
let x : (impl Copy,) = (true,);
//~^ `impl Trait` not allowed outside of function and method return types
}
9 changes: 9 additions & 0 deletions src/test/ui/impl-trait/issues/issue-70971.stderr
Original file line number Diff line number Diff line change
@@ -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`.
10 changes: 10 additions & 0 deletions src/test/ui/impl-trait/issues/issue-79099.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
struct Bug {
V1: [(); {
let f: impl core::future::Future<Output = u8> = async { 1 };
//~^ `impl Trait` not allowed outside of function and method return types
//~| expected identifier
1
}],
}

fn main() {}
20 changes: 20 additions & 0 deletions src/test/ui/impl-trait/issues/issue-79099.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
error: expected identifier, found `1`
--> $DIR/issue-79099.rs:3:65
|
LL | let f: impl core::future::Future<Output = u8> = 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<Output = u8> = async { 1 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0562`.
9 changes: 9 additions & 0 deletions src/test/ui/impl-trait/issues/issue-84919.rs
Original file line number Diff line number Diff line change
@@ -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() {}
9 changes: 9 additions & 0 deletions src/test/ui/impl-trait/issues/issue-84919.stderr
Original file line number Diff line number Diff line change
@@ -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`.
13 changes: 13 additions & 0 deletions src/test/ui/impl-trait/issues/issue-86201.rs
Original file line number Diff line number Diff line change
@@ -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 _: <FunType as FnOnce<()>>::Output = STATIC_FN();
}
21 changes: 21 additions & 0 deletions src/test/ui/impl-trait/issues/issue-86201.stderr
Original file line number Diff line number Diff line change
@@ -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`.
8 changes: 8 additions & 0 deletions src/test/ui/impl-trait/issues/issue-86642.rs
Original file line number Diff line number Diff line change
@@ -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() {}
9 changes: 9 additions & 0 deletions src/test/ui/impl-trait/issues/issue-86642.stderr
Original file line number Diff line number Diff line change
@@ -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`.
18 changes: 18 additions & 0 deletions src/test/ui/impl-trait/issues/issue-87295.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
trait Trait {
type Output;
}
impl Trait for () {
type Output = i32;
}

struct Struct<F>(F);
impl<F> Struct<F> {
pub fn new(_: F) -> Self {
todo!()
}
}

fn main() {
let _do_not_waste: Struct<impl Trait<Output = i32>> = Struct::new(());
//~^ `impl Trait` not allowed outside of function and method return types
}
9 changes: 9 additions & 0 deletions src/test/ui/impl-trait/issues/issue-87295.stderr
Original file line number Diff line number Diff line change
@@ -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<impl Trait<Output = i32>> = Struct::new(());
| ^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0562`.

0 comments on commit 15b2d95

Please sign in to comment.